• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_type.php
  • Класс: CCalendarType
  • Вызов: CCalendarType::GetList
static function GetList($params = [])
{
	global $DB;
	$access = new CAccess();
	$access->UpdateCodes();
	$arFilter = $params['arFilter'] ?? null;
	$result = false;
	$cacheId = false;
	$cachePath = '';
	$arOrder = $params['arOrder'] ?? Array('XML_ID' => 'asc');
	$checkPermissions = ($params['checkPermissions'] ?? true) !== false;

	$bCache = CCalendar::CacheTime() > 0;

	if ($bCache)
	{
		$cache = new CPHPCache;
		$cacheId = serialize(array('type_list', $arFilter, $arOrder));
		$cachePath = CCalendar::CachePath().'type_list';

		if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath))
		{
			$res = $cache->GetVars();
			$result = $res["arResult"];
			$arTypeXmlIds = $res["arTypeXmlIds"];
		}
	}

	if (!$bCache || !isset($arTypeXmlIds))
	{
		$arFields = [
			"XML_ID" => ["FIELD_NAME" => "CT.XML_ID", "FIELD_TYPE" => "string"],
			"NAME" => ["FIELD_NAME" => "CT.NAME", "FIELD_TYPE" => "string"],
			"ACTIVE" => ["FIELD_NAME" => "CT.ACTIVE", "FIELD_TYPE" => "string"],
			"DESCRIPTION" => ["FIELD_NAME" => "CT.DESCRIPTION", "FIELD_TYPE" => "string"],
			"EXTERNAL_ID" => ["FIELD_NAME" => "CT.EXTERNAL_ID", "FIELD_TYPE" => "string"]
		];

		$arSqlSearch = [];
		if(is_array($arFilter))
		{
			$filter_keys = array_keys($arFilter);
			foreach ($filter_keys as $i => $value)
			{
				$n = mb_strtoupper($value);
				$val = $arFilter[$value];

				if (is_string($val) && !$val)
				{
					continue;
				}

				if ($n === 'XML_ID')
				{
					if (is_array($val))
					{
						$strXml = "";
						foreach($val as $xmlId)
						{
							$strXml .= ",'" . $DB->ForSql($xmlId) . "'";
						}
						$arSqlSearch[] = "CT.XML_ID in (".trim($strXml, ", ").")";
					}
					else
					{
						$arSqlSearch[] = GetFilterQuery("CT.XML_ID", $val, 'N');
					}
				}
				if ($n === 'EXTERNAL_ID')
				{
					$arSqlSearch[] = GetFilterQuery("CT.EXTERNAL_ID", $val, 'N');
				}
				elseif (isset($arFields[$n]))
				{
					$arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val);
				}
			}
		}

		$strOrderBy = '';
		foreach($arOrder as $by=>$order)
		{
			if (isset($arFields[mb_strtoupper($by)]))
			{
				$strOrderBy .= $arFields[mb_strtoupper($by)]["FIELD_NAME"] . ' '
					. (mb_strtolower($order) === 'desc' ? 'desc' : 'asc') . ',';
			}
		}

		if ($strOrderBy)
		{
			$strOrderBy = "ORDER BY " . rtrim($strOrderBy, ",");
		}

		$strSqlSearch = GetFilterSqlSearch($arSqlSearch);

		$strSql = "
			SELECT
				CT.*
			FROM
				b_calendar_type CT
			WHERE
				$strSqlSearch
			$strOrderBy";

		$res = $DB->Query($strSql, false, "Function: CCalendarType::GetList
Line: ".__LINE__); $result = []; $arTypeXmlIds = []; while($arRes = $res->Fetch()) { $result[] = $arRes; $arTypeXmlIds[] = $arRes['XML_ID']; } if ($bCache && isset($cache)) { $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath); $cache->EndDataCache(array( "arResult" => $result, "arTypeXmlIds" => $arTypeXmlIds )); } } if ($checkPermissions && !empty($arTypeXmlIds)) { $arPerm = self::GetArrayPermissions($arTypeXmlIds); $res = []; $arAccessCodes = []; $accessController = new TypeAccessController(CCalendar::GetCurUserId()); if (is_array($result)) { foreach($result as $type) { $typeXmlId = $type['XML_ID']; $typeModel = TypeModel::createFromXmlId($typeXmlId); $request = [ ActionDictionary::ACTION_TYPE_VIEW => [], ActionDictionary::ACTION_TYPE_EDIT => [], ActionDictionary::ACTION_TYPE_ACCESS => [], ]; $result = $accessController->batchCheck($request, $typeModel); if ($result[ActionDictionary::ACTION_TYPE_VIEW]) { $type['PERM'] = [ 'view' => true, 'add' => $result[ActionDictionary::ACTION_TYPE_EDIT], 'edit' => $result[ActionDictionary::ACTION_TYPE_EDIT], 'edit_section' => $result[ActionDictionary::ACTION_TYPE_EDIT], 'access' => $result[ActionDictionary::ACTION_TYPE_ACCESS], ]; if ($result[ActionDictionary::ACTION_TYPE_ACCESS]) { $type['ACCESS'] = []; if (!empty($arPerm[$typeXmlId])) { // Add codes to get they full names for interface $currentAccessCodes = array_keys($arPerm[$typeXmlId]); foreach ($currentAccessCodes as $code) { if (!in_array($code, $arAccessCodes, true)) { $arAccessCodes[] = $code; } } $type['ACCESS'] = $arPerm[$typeXmlId]; } } $res[] = $type; } } } CCalendar::PushAccessNames($arAccessCodes); $result = $res; } return $result; }