Rights::getData

  1. Bitrix24 API (v. 23.675.0)
  2. landing
  3. Rights
  4. getData
  • Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/rights.php
  • Класс: BitrixLandingRights
  • Вызов: Rights::getData
static function getData($entityId, $entityType, array $preDefined = [])
{
	static $access = null;
	$items = [];
	$codes = [];

	if ($access === null)
	{
		$access = new CAccess;
	}

	// filter (with predefined_
	$filter = [
		'ENTITY_ID' => $entityId,
		'=ENTITY_TYPE' => $entityType
	];
	if ($preDefined)
	{
		$filter['=ACCESS_CODE'] = array_keys($preDefined);
	}

	// main query
	$res = RightsTable::getList([
		'select' => [
			'TASK_ID',
			'ACCESS_CODE'
		],
		'filter' => $filter
	]);
	while ($row = $res->fetch())
	{
		$codes[] = $row['ACCESS_CODE'];
		if (!isset($items[$row['ACCESS_CODE']]))
		{
			$row['TASK_ID'] = [$row['TASK_ID']];
			$items[$row['ACCESS_CODE']] = $row;
		}
		else
		{
			$items[$row['ACCESS_CODE']]['TASK_ID'][] = $row['TASK_ID'];
		}
		if (isset($preDefined[$row['ACCESS_CODE']]))
		{
			unset($preDefined[$row['ACCESS_CODE']]);
		}
	}

	$items = array_values($items);

	// fill with predefined
	foreach ($preDefined as $accessCode => $rightCode)
	{
		$items[] = [
			'TASK_ID' => $rightCode,
			'ACCESS_CODE' => $accessCode
		];
		$codes[] = $accessCode;
	}

	// get titles
	if ($items)
	{
		$codesNames  = $access->getNames($codes);
		foreach ($items as &$item)
		{
			if (isset($codesNames[$item['ACCESS_CODE']]))
			{
				$item['ACCESS_PROVIDER'] = (
							isset($codesNames[$item['ACCESS_CODE']]['provider']) &&
							$codesNames[$item['ACCESS_CODE']]['provider']
						)
					? $codesNames[$item['ACCESS_CODE']]['provider']
					: '';
				$item['ACCESS_NAME'] = isset($codesNames[$item['ACCESS_CODE']]['name'])
					? $codesNames[$item['ACCESS_CODE']]['name']
					: $item['ACCESS_CODE'];
			}
		}
		unset($item);
	}

	return $items;
}

Добавить комментарий