- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockdocument.php
- Класс: CIBlockDocument
- Вызов: CIBlockDocument::SetPermissions
static function SetPermissions($documentId, $workflowId, $arPermissions, $bRewrite = true)
{
$documentId = intval($documentId);
if ($documentId <= 0)
throw new CBPArgumentNullException("documentId");
$documentType = self::GetDocumentType($documentId);
$iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
if ($iblockId <= 0)
throw new CBPArgumentOutOfRangeException("documentType", $documentType);
if (CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") !== "E")
return;
$ob = new CIBlockElementRights($iblockId, $documentId);
$documentRights = $ob->GetRights();
$mode = 'Hold';
$scope = 'ScopeWorkflow';
if (is_array($bRewrite) && class_exists('CBPSetPermissionsMode'))
{
if (isset($bRewrite['setMode']))
$mode = CBPSetPermissionsMode::outMode($bRewrite['setMode']);
if (isset($bRewrite['setScope']))
$scope = CBPSetPermissionsMode::outScope($bRewrite['setScope']);
}
elseif ($bRewrite == true)
{
$mode = 'Clear';
}
$overrideCodes = array();
if ($mode == 'Clear' || $mode == 'Rewrite')
{
foreach ($documentRights as $i => $arRight)
{
if ($scope == 'ScopeDocument' || $scope == 'ScopeWorkflow' && $arRight["XML_ID"] == $workflowId)
{
if ($mode == 'Clear')
unset($documentRights[$i]);
if ($mode == 'Rewrite')
$overrideCodes[$arRight["GROUP_CODE"]] = $i;
}
}
}
$i = 0;
$l = mb_strlen("user_");
foreach ($arPermissions as $taskId => $arUsers)
{
foreach ($arUsers as $user)
{
if (!$user)
continue;
$gc = null;
if ($user == 'author')
{
$u = self::GetUsersFromUserGroup('author', $documentId);
foreach ($u as $u1)
$gc = "U".$u1;
}
elseif (mb_strpos($user, 'group_') === 0)
{
$gc = mb_strtoupper(mb_substr($user, mb_strlen('group_')));
}
else
{
$gc = ((mb_substr($user, 0, $l) == "user_") ? "U".mb_substr($user, $l) : "G".$user);
}
if ($gc != null)
{
$documentRights["n".$i] = array("GROUP_CODE" => $gc, "TASK_ID" => $taskId, "XML_ID" => $workflowId);
$i++;
if (isset($overrideCodes[$gc]))
unset($documentRights[$overrideCodes[$gc]]);
}
}
}
$ob->SetRights($documentRights);
}