public static function UpdateUFRights($files, $rights, $ufEntity = array()) { static $arTasks = null; if (!is_array($rights) || sizeof($rights) <= 0) { return false; } if ($files === null || $files === false) { return false; } if (!is_array($files)) { $files = array($files); } if (sizeof($files) <= 0) { return false; } if (!CModule::IncludeModule('iblock') || !CModule::IncludeModule('webdav')) { return false; } $arFiles = array(); foreach ($files as $id) { $id = intval($id); if (intval($id) > 0) { $arFiles[] = $id; } } if (sizeof($arFiles) <= 0) { return false; } if ($arTasks == null) { $arTasks = CWebDavIblock::GetTasks(); } $arCodes = array(); foreach ($rights as $value) { if (substr($value, 0, 2) === 'SG') { $arCodes[] = $value . '_K'; } $arCodes[] = $value; } $arCodes = array_unique($arCodes); $i = 0; $arViewRights = $arEditRights = array(); $curUserID = 'U' . $GLOBALS['USER']->GetID(); foreach ($arCodes as $right) { if ($curUserID == $right) { // do not override owner's rights continue; } $key = 'n' . $i++; $arViewRights[$key] = array('GROUP_CODE' => $right, 'TASK_ID' => $arTasks['R']); } $ibe = new CIBlockElement(); $dbWDFile = $ibe->GetList(array(), array('ID' => $arFiles, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'NAME', 'SECTION_ID', 'IBLOCK_ID', 'WF_NEW')); $iblockIds = array(); if ($dbWDFile) { while ($arWDFile = $dbWDFile->Fetch()) { $id = $arWDFile['ID']; if ($arWDFile['WF_NEW'] == 'Y') { $ibe->Update($id, array('BP_PUBLISHED' => 'Y')); } if (CIBlock::GetArrayByID($arWDFile['IBLOCK_ID'], "RIGHTS_MODE") === "E") { $ibRights = CWebDavIblock::_get_ib_rights_object('ELEMENT', $id, $arWDFile['IBLOCK_ID']); $ibRights->SetRights(CWebDavTools::appendRights($ibRights, $arViewRights, $arTasks)); if (empty($iblockIds[$arWDFile['IBLOCK_ID']])) { $iblockIds[$arWDFile['IBLOCK_ID']] = $arWDFile['IBLOCK_ID']; } } } global $CACHE_MANAGER; foreach ($iblockIds as $iblockId) { $CACHE_MANAGER->ClearByTag('iblock_id_' . $iblockId); } unset($iblockId); } }
function SetUFRights($files, $rights) { static $arTasks = null; if (!CModule::IncludeModule('iblock') || !CModule::IncludeModule('webdav')) { return; } if (!is_array($rights) || count($rights) <= 0) { return false; } if ($files === null || $files === false) { return false; } if (!is_array($files)) { $files = array($files); } $arFiles = array(); foreach ($files as $id) { $id = intval($id); if (intval($id) > 0) { $arFiles[] = $id; } } if (count($arFiles) <= 0) { return false; } if ($arTasks == null) { $arTasks = CWebDavIblock::GetTasks(); } $arCodes = array(); foreach ($rights as $value) { if (substr($value, 0, 2) === 'SG') { $arCodes[] = $value . '_K'; } $arCodes[] = $value; } $arCodes = array_unique($arCodes); $i = 0; $arViewRights = array(); $curUserID = 'U' . $GLOBALS['USER']->GetID(); foreach ($arCodes as $right) { if ($curUserID == $right) { // do not override owner's rights continue; } $key = "n" . $i++; $arViewRights[$key] = array("GROUP_CODE" => $right, "TASK_ID" => $arTasks["R"]); } $ibe = new CIBlockElement(); $dbWDFile = $ibe->GetList(array(), array("ID" => $arFiles, "SHOW_NEW" => "Y"), false, false, array("ID", "NAME", "SECTION_ID", "IBLOCK_ID", "WF_NEW")); $iblockIds = array(); if ($dbWDFile) { while ($arWDFile = $dbWDFile->Fetch()) { $id = $arWDFile["ID"]; if ($arWDFile["WF_NEW"] == "Y") { $ibe->Update($id, array("BP_PUBLISHED" => "Y")); } if (CIBlock::GetArrayByID($arWDFile['IBLOCK_ID'], "RIGHTS_MODE") === "E") { $ibRights = CWebDavIblock::_get_ib_rights_object("ELEMENT", $id, $arWDFile["IBLOCK_ID"]); $ibRights->SetRights(CWebDavTools::appendRights($ibRights, $arViewRights, $arTasks)); if (empty($iblockIds[$arWDFile["IBLOCK_ID"]])) { $iblockIds[$arWDFile["IBLOCK_ID"]] = $arWDFile["IBLOCK_ID"]; } } } global $CACHE_MANAGER; foreach ($iblockIds as $iblockId) { $CACHE_MANAGER->ClearByTag("iblock_id_" . $iblockId); } unset($iblockId); } }
protected static function appendRights(CIBlockElementRights $ibRights, array $appendRights, array $tasks) { return CWebDavTools::appendRights($ibRights, $appendRights, $tasks); }
public static final function appendRightsOnSections(array $sections, array $rights) { $tasks = CWebDavIblock::GetTasks(); $reformatRights = array(); $i = 0; foreach ($rights as $letter => $groupCodes) { if (!is_array($groupCodes)) { $groupCodes = array($groupCodes); } foreach ($groupCodes as $groupCode) { $reformatRights['n' . $i] = array('GROUP_CODE' => $groupCode, 'TASK_ID' => $tasks[$letter]); $i++; } unset($groupCode); } unset($right); foreach ($sections as $section) { $sectionId = (int) $section['ID']; if ($sectionId <= 0) { continue; } if (CIBlock::GetArrayByID($section['IBLOCK_ID'], "RIGHTS_MODE") === "E") { $rightObject = CWebDavIblock::_get_ib_rights_object('SECTION', $sectionId, $section['IBLOCK_ID']); $rightObject->SetRights(CWebDavTools::appendRights($rightObject, $reformatRights, $tasks)); } } unset($section); }