Ejemplo n.º 1
0
 /**
  * @param $documentType
  * @param bool $withExtended
  * @return array|bool
  */
 public function GetAllowableUserGroups($documentType, $withExtended = false)
 {
     $documentType = trim($documentType);
     if (strlen($documentType) <= 0) {
         return false;
     }
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     $result = array("Author" => GetMessage("IBD_DOCUMENT_AUTHOR"));
     $groupsId = array(1);
     $extendedGroupsCode = array();
     if (CIBlock::getArrayByID($iblockId, "RIGHTS_MODE") === "E") {
         $rights = new CIBlockRights($iblockId);
         foreach ($rights->getGroups() as $iblockGroupCode) {
             if (preg_match("/^G(\\d+)\$/", $iblockGroupCode, $match)) {
                 $groupsId[] = $match[1];
             } else {
                 $extendedGroupsCode[] = $iblockGroupCode;
             }
         }
     } else {
         foreach (CIBlock::getGroupPermissions($iblockId) as $groupId => $perm) {
             if ($perm > "R") {
                 $groupsId[] = $groupId;
             }
         }
     }
     $groupsIterator = CGroup::getListEx(array("NAME" => "ASC"), array("ID" => $groupsId));
     while ($group = $groupsIterator->fetch()) {
         $result[$group["ID"]] = $group["NAME"];
     }
     if ($withExtended && $extendedGroupsCode) {
         foreach ($extendedGroupsCode as $groupCode) {
             $result['group_' . $groupCode] = CBPHelper::getExtendedGroupName($groupCode);
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public static function getAllowableUserGroups($documentType)
 {
     $storageId = self::getStorageIdByType($documentType);
     if (!$storageId) {
         throw new CBPArgumentNullException('documentType');
     }
     /** @var Storage $storage */
     $storage = Storage::loadById($storageId, array('ROOT_OBJECT'));
     if (!$storage) {
         throw new CBPArgumentNullException('documentType');
     }
     if ($storage->getProxyType() instanceof ProxyType\Group) {
         if (Loader::includeModule("socialnetwork")) {
             $resultUserGroups = array();
             $resultUserGroups["author"] = Loc::getMessage("DISK_USER_GROUPS_AUTHOR");
             $resultUserGroups[SONET_ROLES_OWNER] = Loc::getMessage("DISK_USER_GROUPS_OWNER");
             $resultUserGroups[SONET_ROLES_MODERATOR] = Loc::getMessage("DISK_USER_GROUPS_MODS");
             $resultUserGroups[SONET_ROLES_USER] = Loc::getMessage("DISK_USER_GROUPS_MEMBERS");
             return $resultUserGroups;
         }
     } else {
         $resultUserGroups = array('Author' => Loc::getMessage("DISK_USER_GROUPS_AUTHOR"));
         $groupIds = array(1);
         foreach (Driver::getInstance()->getRightsManager()->getSpecificRights($storage->getRootObject()) as $right) {
             if (preg_match("/^G(\\d+)\$/", $right['ACCESS_CODE'], $match)) {
                 $groupIds[] = $match[1];
             }
         }
         unset($right);
         //Crutch for Bitrix24 context (user group management is not supported)
         if (ModuleManager::isModuleInstalled('bitrix24')) {
             $siteId = \CAllSite::getDefSite();
             $employeeGroup = \CGroup::getList($by = '', $order = '', array('STRING_ID' => 'EMPLOYEES_' . $siteId, 'STRING_ID_EXACT_MATCH' => 'Y'))->fetch();
             if ($employeeGroup) {
                 $employeeGroupId = (int) $employeeGroup['ID'];
                 if (!in_array($employeeGroupId, $groupIds, true)) {
                     $groupIds[] = $employeeGroupId;
                 }
             }
         }
         $dbGroupsList = \CGroup::getListEx(array('NAME' => 'ASC'), array('ID' => $groupIds));
         while ($group = $dbGroupsList->fetch()) {
             $resultUserGroups[$group['ID']] = $group['NAME'];
         }
         return $resultUserGroups;
     }
 }