示例#1
0
 /**
  * Returns list users who have sharing on this object.
  * @return array
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\LoaderException
  */
 public function getMembersOfSharing()
 {
     $sharings = $this->getRealObject()->getSharingsAsReal();
     $members = array();
     $membersToSharing = array();
     foreach ($sharings as $sharing) {
         if ($sharing->isToDepartmentChild()) {
             continue;
         }
         list($type, $id) = Sharing::parseEntityValue($sharing->getToEntity());
         $members[$type][] = $id;
         $membersToSharing[$type . '|' . $id] = $sharing;
     }
     unset($sharing);
     $enabledSocialnetwork = Loader::includeModule('socialnetwork');
     $entityList = array();
     foreach (SharingTable::getListOfTypeValues() as $type) {
         if (empty($members[$type])) {
             continue;
         }
         if ($type == SharingTable::TYPE_TO_USER) {
             $query = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'PERSONAL_PHOTO', 'NAME', 'LOGIN', 'LAST_NAME', 'SECOND_NAME'), 'filter' => array('ID' => array_values($members[$type]))));
             while ($userRow = $query->fetch()) {
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $userRow['ID']];
                 $entityList[] = array('entityId' => Sharing::CODE_USER . $userRow['ID'], 'name' => \CUser::formatName('#NAME# #LAST_NAME#', array("NAME" => $userRow['NAME'], "LAST_NAME" => $userRow['LAST_NAME'], "SECOND_NAME" => $userRow['SECOND_NAME'], "LOGIN" => $userRow['LOGIN']), false), 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getPerson($userRow['PERSONAL_PHOTO']), 'type' => 'users');
             }
         } elseif ($type == SharingTable::TYPE_TO_GROUP && $enabledSocialnetwork) {
             $query = \CSocNetGroup::getList(array(), array('ID' => array_values($members[$type])), false, false, array('ID', 'IMAGE_ID', 'NAME'));
             while ($query && ($groupRow = $query->fetch())) {
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $groupRow['ID']];
                 $entityList[] = array('entityId' => Sharing::CODE_SOCNET_GROUP . $groupRow['ID'], 'name' => $groupRow['NAME'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getGroup($groupRow['IMAGE_ID']), 'type' => 'groups');
             }
         } elseif ($type == SharingTable::TYPE_TO_DEPARTMENT && $enabledSocialnetwork) {
             // intranet structure
             $structure = \CSocNetLogDestination::getStucture();
             foreach (array_values($members[$type]) as $departmentId) {
                 if (empty($structure['department']['DR' . $departmentId])) {
                     continue;
                 }
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $departmentId];
                 $entityList[] = array('entityId' => Sharing::CODE_DEPARTMENT . $departmentId, 'name' => $structure['department']['DR' . $departmentId]['name'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getDefaultGroup(), 'type' => 'department');
             }
             unset($departmentId);
         }
     }
     unset($type);
     return $entityList;
 }