CCrmRole::normalizePermissions

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRole
  4. normalizePermissions
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_role.php
  • Класс: \CCrmRole
  • Вызов: CCrmRole::normalizePermissions
static function normalizePermissions(array $permissions): array
{
	foreach ($permissions as $entityTypeName => $entityPermissions)
	{
		if (!is_array($entityPermissions))
		{
			$entityPermissions = [];
			$permissions[$entityTypeName] = [];
		}

		foreach ($entityPermissions as $permissionType => $permissionsForType)
		{
			if (!is_array($permissionsForType))
			{
				$permissionsForType = [];
				$permissions[$entityTypeName][$permissionType] = [];
			}

			$defaultPermissionValue = '-';
			foreach ($permissionsForType as $fieldName => $permissionValue)
			{
				if ($fieldName === '-') // default permission
				{
					$defaultPermissionValue = trim($permissionValue);
				}
			}
			foreach ($permissionsForType as $fieldName => $permissionValues)
			{
				if ($fieldName !== '-')
				{
					if (!is_array($permissionValues))
					{
						$permissionValues = [];
						$permissions[$entityTypeName][$permissionType][$fieldName] = [];
					}
					foreach ($permissionValues as $fieldValue => $permissionValue)
					{
						if (trim($permissionValue) === $defaultPermissionValue)
						{
							// if permission for this field value equals to default permission, use inheritance:
							$permissions[$entityTypeName][$permissionType][$fieldName][$fieldValue] = '-';
						}
					}
				}
			}
		}
	}
	return $permissions;
}

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