• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_sect.php
  • Класс: CCalendarSect
  • Вызов: CCalendarSect::GetSuperposedList
static function GetSuperposedList($params = [])
{
	global $DB;
	$checkPermissions = ($params['checkPermissions'] ?? null) !== false;
	$userId = isset($params['userId']) ? (int)$params['userId'] : CCalendar::GetCurUserId();

	$arResult = [];
	$arSectionIds = [];
	$sqlSearch = "";

	$select = '';
	$from = '';
	if ($checkPermissions)
	{
		$select .= ", CAP.ACCESS_CODE, CAP.TASK_ID";
		$from .= "n LEFT JOIN b_calendar_access CAP ON (CS.ID=CAP.SECT_ID)";
	}

	// Common types
	$strTypes = "";
	if (isset($params['TYPES']) && is_array($params['TYPES']))
	{
		foreach($params['TYPES'] as $type)
		{
			$strTypes .= ",'" . $DB->ForSql($type) . "'";
		}

		$strTypes = trim($strTypes, ", ");
		if ($strTypes != "")
		{
			$sqlSearch .= "(CS.CAL_TYPE in (" . $strTypes . "))";
		}
	}

	// Group's calendars
	$strGroups = "0";
	if (!empty($params['GROUPS']) && is_array($params['GROUPS']))
	{
		foreach($params['GROUPS'] as $ownerId)
		{
			if ((int)$ownerId > 0)
			{
				$strGroups .= "," . (int)$ownerId;
			}
		}

		if ($strGroups != "0")
		{
			if ($sqlSearch != "")
			{
				$sqlSearch .= " OR ";
			}
			$sqlSearch .= "(CS.OWNER_ID in (".$strGroups.") AND CS.CAL_TYPE='group')";
		}
	}

	if ($sqlSearch != "")
	{
		$strSql = "
			SELECT
				CS.*,
				CT.NAME AS TYPE_NAME, CT.DESCRIPTION AS TYPE_DESC".$select."
			FROM
				b_calendar_section CS
				LEFT JOIN b_calendar_type CT ON (CS.CAL_TYPE=CT.XML_ID)".$from."
			WHERE
				(
					CT.ACTIVE='Y'
				AND
					CS.ACTIVE='Y'
				AND
				(
					$sqlSearch
				))";

		$res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__); while($arRes = $res->Fetch()) { if ($checkPermissions) { self::HandlePermission($arRes); unset($arRes['ACCESS_CODE'], $arRes['TASK_ID']); } if (!in_array($arRes['ID'], $arSectionIds)) { $arSectionIds[] = $arRes['ID']; $arResult[] = $arRes; } } } // User's calendars $strUsers = "0"; if (isset($params['USERS']) && is_array($params['USERS']) && count($params['USERS']) > 0) { foreach($params['USERS'] as $ownerId) { if ((int)$ownerId > 0) { $strUsers .= ",". (int)$ownerId; } } if ($strUsers != "0") { $strSql = " SELECT CS.*, U.LOGIN AS USER_LOGIN, U.NAME AS USER_NAME, U.LAST_NAME AS USER_LAST_NAME, U.SECOND_NAME AS USER_SECOND_NAME".$select." FROM b_calendar_section CS LEFT JOIN b_user U ON (CS.OWNER_ID=U.ID)".$from." WHERE ( CS.ACTIVE='Y' AND CS.OWNER_ID in (".$strUsers.") AND CS.CAL_TYPE='user' )"; $res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__); } while($arRes = $res->Fetch()) { if ($checkPermissions) { self::HandlePermission($arRes); unset($arRes['ACCESS_CODE'], $arRes['TASK_ID']); } if (!in_array($arRes['ID'], $arSectionIds)) { $arSectionIds[] = $arRes['ID']; $arResult[] = $arRes; } } } if ($checkPermissions && !empty($arSectionIds)) { $res = []; $sectIds = []; foreach($arResult as $sect) { $sectId = $sect['ID']; $ownerId = $sect['OWNER_ID']; $accessController = new SectionAccessController($userId); $sectionModel = SectionModel::createFromId((int)$sectId) ->setType($sect['CAL_TYPE']) ->setOwnerId((int)$ownerId) ; $request = [ ActionDictionary::ACTION_SECTION_EVENT_VIEW_TIME => [], ActionDictionary::ACTION_SECTION_EVENT_VIEW_TITLE => [], ActionDictionary::ACTION_SECTION_EVENT_VIEW_FULL => [], ActionDictionary::ACTION_SECTION_ADD => [], ActionDictionary::ACTION_SECTION_EDIT => [], ActionDictionary::ACTION_SECTION_ACCESS => [], ]; $result = $accessController->batchCheck($request, $sectionModel); if ($result[ActionDictionary::ACTION_SECTION_EVENT_VIEW_TIME] && !in_array($sectId, $sectIds)) { $sect['PERM'] = [ 'view_time' => $result[ActionDictionary::ACTION_SECTION_EVENT_VIEW_TIME], 'view_title' => $result[ActionDictionary::ACTION_SECTION_EVENT_VIEW_TITLE], 'view_full' => $result[ActionDictionary::ACTION_SECTION_EVENT_VIEW_FULL], 'add' => $result[ActionDictionary::ACTION_SECTION_ADD], 'edit' => $result[ActionDictionary::ACTION_SECTION_EDIT], 'edit_section' => $result[ActionDictionary::ACTION_SECTION_EDIT], 'access' => $result[ActionDictionary::ACTION_SECTION_ACCESS], ]; if ($sect['CAL_TYPE'] === 'user') { if (isset($sect['USER_NAME'], $sect['USER_LAST_NAME'])) { $sect['OWNER_NAME'] = CCalendar::GetUserName(array( "NAME" => $sect['USER_NAME'], "LAST_NAME" => $sect['USER_LAST_NAME'], "LOGIN" => $sect['USER_LOGIN'], "ID" => $ownerId, "SECOND_NAME" => $sect['USER_SECOND_NAME']) ); unset( $sect['USER_LOGIN'], $sect['USER_LAST_NAME'], $sect['USER_SECOND_NAME'], $sect['USER_NAME'] ); } else { $sect['OWNER_NAME'] = CCalendar::GetUserName($ownerId); } } elseif ($sect['CAL_TYPE'] === 'group' && isset($params['arGroups'])) { $sect['OWNER_NAME'] = $params['arGroups'][$ownerId]['NAME']; } $res[] = $sect; $sectIds[] = $sectId; } } $arResult = $res; } foreach ($arResult as &$section) { if (!empty($section['NAME'])) { $section['NAME'] = Emoji::decode($section['NAME']); } } return $arResult; }