• Модуль: report
  • Путь к файлу: ~/bitrix/modules/report/lib/sharing.php
  • Класс: BitrixReportSharing
  • Вызов: Sharing::changeSharing
public function changeSharing($listNewEntity)
{
	$listSharingRow = $this->getByReportId();
	if(!empty($listNewEntity) && is_array($listNewEntity))
	{
		$newEntityData = array();
		foreach($listNewEntity as $entityId => $entityData)
		{
			switch($entityData['right'])
			{
				case RightsManager::ACCESS_READ:
				case RightsManager::ACCESS_EDIT:
					$newEntityData[$entityId]['ENTITY'] = $entityId;
					$newEntityData[$entityId]['RIGHTS'] = $entityData['right'];
					$newEntityData[$entityId]['REPORT_ID'] = $this->reportId;
					break;
			}
		}

		$overwriteSharing = $deleteSharing = $addSharing = array();
		foreach($listSharingRow as $sharingRow)
		{
			if(array_key_exists($sharingRow['ENTITY'], $newEntityData))
			{
				if($newEntityData[$sharingRow['ENTITY']]['RIGHTS'] != $sharingRow['RIGHTS'])
				{
					$overwriteSharing[$sharingRow['ENTITY']] = $newEntityData[$sharingRow['ENTITY']];
					$overwriteSharing[$sharingRow['ENTITY']]['ID'] = $sharingRow['ID'];
				}
				elseif($newEntityData[$sharingRow['ENTITY']]['RIGHTS'] == $sharingRow['RIGHTS'])
				{
					unset($newEntityData[$sharingRow['ENTITY']]);
				}
			}
			else
			{
				$deleteSharing[$sharingRow['ENTITY']] = $sharingRow;
			}
		}
		$addSharing = array_diff_key($newEntityData, $overwriteSharing);
		if($addSharing)
			$this->addToManyEntity($addSharing);
		if($overwriteSharing)
			$this->updateManyEntity($overwriteSharing);
		if($deleteSharing)
			$this->deleteManyEntity($deleteSharing);
	}
	else
	{
		$this->deleteManyEntity($listSharingRow);
	}

	$cache = new CPHPCache;
	$cache->cleanDir('/report/sharing/'.$this->reportId);
}