Пример #1
0
 /**
  *
  * Moves the source task before/after the target task;
  * @param array $data
  * @return false|array
  */
 public function move($data)
 {
     global $USER;
     if (!$USER->isAuthorized()) {
         $this->errors->add("AUTH_REQUIRED", Loc::getMessage("TASKS_SORTING_AUTH_REQUIRED"));
         return false;
     }
     $sourceId = isset($data["sourceId"]) ? intval($data["sourceId"]) : 0;
     $targetId = isset($data["targetId"]) ? intval($data["targetId"]) : 0;
     $before = isset($data["before"]) && ($data["before"] === true || $data["before"] === "true") ? true : false;
     $newGroupId = isset($data["newGroupId"]) ? intval($data["newGroupId"]) : null;
     $newParentId = isset($data["newParentId"]) ? intval($data["newParentId"]) : null;
     $currentGroupId = isset($data["currentGroupId"]) ? intval($data["currentGroupId"]) : 0;
     $userId = $USER->getId();
     if ($sourceId === $targetId || $sourceId < 1) {
         return array();
     }
     $sourceTask = new \CTaskItem($sourceId, $userId);
     if (!$sourceTask->checkCanRead()) {
         $this->errors->add("SOURCE_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_SOURCE_TASK"));
         return false;
     }
     if ($currentGroupId) {
         $group = \CSocNetGroup::getByID($currentGroupId);
         $canEdit = \CSocNetFeaturesPerms::currentUserCanPerformOperation(SONET_ENTITY_GROUP, $currentGroupId, "tasks", "edit_tasks");
         if (!$group || !$canEdit) {
             $this->errors->add("GROUP_PERMS_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_GROUP_PERMISSIONS"));
             return false;
         }
     }
     /*
     GROUP_ID and PARENT_ID could be changed after drag&drop manipulations.
     Target task is not required. Example: We want to move Task 1 after Project. In this case a target task is undefined.
     	Task 1
     	Project (without tasks)
     */
     $newTaskData = array();
     if ($newGroupId !== null) {
         $newTaskData["GROUP_ID"] = $newGroupId;
     }
     if ($newParentId !== null) {
         $newTaskData["PARENT_ID"] = $newParentId;
     }
     if (count($newTaskData)) {
         $sourceTask->update($newTaskData);
     }
     //But it's required for sorting
     if ($targetId < 1) {
         return array();
     }
     $targetTask = new \CTaskItem($targetId, $userId);
     if (!$targetTask->checkCanRead()) {
         $this->errors->add("TARGET_TASK_NOT_FOUND", Loc::getMessage("TASKS_SORTING_WRONG_TARGET_TASK"));
         return false;
     }
     SortingTable::setSorting($userId, $currentGroupId, $sourceId, $targetId, $before);
     return array();
 }
Пример #2
0
 private function getGroup()
 {
     if ($this->group !== null) {
         return $this->group;
     }
     if (!Loader::includeModule('socialnetwork')) {
         return null;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $this->group = \CSocNetGroup::getByID($this->entityId);
     if (!is_array($this->group)) {
         $this->group = array();
     }
     return $this->group;
 }
Пример #3
0
 protected function getDestinations()
 {
     $isExtranetInstalled = Loader::includeModule("extranet");
     $members = array();
     if ($this->blogPostData["HAS_SOCNET_ALL"] != "Y") {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $perm = \CBlogPost::getSocnetPermsName($this->entityId);
         foreach ($perm as $type => $v) {
             foreach ($v as $vv) {
                 if ($type == "SG") {
                     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                     if ($socNetGroup = \CSocNetGroup::getByID($vv["ENTITY_ID"])) {
                         $name = $socNetGroup["~NAME"];
                         $link = \CComponentEngine::makePathFromTemplate($this->getPathToGroup(), array("group_id" => $vv["ENTITY_ID"]));
                         $groupSiteID = false;
                         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                         $queryGroupSite = \CSocNetGroup::getSite($vv["ENTITY_ID"]);
                         while ($groupSite = $queryGroupSite->fetch()) {
                             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                             if (!$isExtranetInstalled || $groupSite["LID"] != \CExtranet::getExtranetSiteID()) {
                                 $groupSiteID = $groupSite["LID"];
                                 break;
                             }
                         }
                         if ($groupSiteID) {
                             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                             $tmp = \CSocNetLogTools::processPath(array("GROUP_URL" => $link), $this->getUser()->getId(), $groupSiteID);
                             // user_id is not important parameter
                             $link = strlen($tmp["URLS"]["GROUP_URL"]) > 0 ? $tmp["URLS"]["GROUP_URL"] : $link;
                         }
                         $isExtranet = is_array($GLOBALS["arExtranetGroupID"]) && in_array($vv["ENTITY_ID"], $GLOBALS["arExtranetGroupID"]);
                         $members[] = array("NAME" => $name, "LINK" => $link, 'AVATAR_SRC' => Ui\Avatar::getGroup($socNetGroup['IMAGE_ID']), "IS_EXTRANET" => $isExtranet ? "Y" : "N");
                     }
                 } elseif ($type == "U") {
                     if (in_array("US" . $vv["ENTITY_ID"], $vv["ENTITY"])) {
                         array_unshift($members, array("NAME" => Loc::getMessage('DISK_UF_BLOG_POST_CONNECTOR_MEMBERS_ALL'), "LINK" => null, 'AVATAR_SRC' => Ui\Avatar::getDefaultGroup(), "IS_EXTRANET" => "N"));
                     } else {
                         $name = \CUser::formatName('#NAME# #LAST_NAME#', array("NAME" => $vv["~U_NAME"], "LAST_NAME" => $vv["~U_LAST_NAME"], "SECOND_NAME" => $vv["~U_SECOND_NAME"], "LOGIN" => $vv["~U_LOGIN"], "NAME_LIST_FORMATTED" => ""), false);
                         $isExtranet = is_array($GLOBALS["arExtranetUserID"]) && in_array($vv["ENTITY_ID"], $GLOBALS["arExtranetUserID"]);
                         $members[] = array("NAME" => $name, "LINK" => \CComponentEngine::makePathFromTemplate($this->getPathToUser(), array("user_id" => $vv["ENTITY_ID"])), 'AVATAR_SRC' => Ui\Avatar::getPerson($vv['U_PERSONAL_PHOTO']), "IS_EXTRANET" => $isExtranet ? "Y" : "N");
                     }
                 } elseif ($type == "DR") {
                     $members[] = array("NAME" => $vv["EL_NAME"], "LINK" => null, 'AVATAR_SRC' => Ui\Avatar::getDefaultGroup(), "IS_EXTRANET" => "N");
                 }
             }
         }
     } else {
         $members[] = array("NAME" => Loc::getMessage('DISK_UF_BLOG_POST_CONNECTOR_MEMBERS_ALL'), "LINK" => null, 'AVATAR_SRC' => Ui\Avatar::getDefaultGroup(), "IS_EXTRANET" => "N");
     }
     return $members;
 }
Пример #4
0
 public static function getUsersFromUserGroup($group, $documentId)
 {
     if (substr($documentId, 0, 8) == "STORAGE_") {
         $storageId = self::getStorageIdByType($documentId);
     } else {
         if (is_array($documentId)) {
             $documentId = intval($documentId[2]);
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         $storageId = $file->getStorageId();
     }
     if (strtolower($group) == "author") {
         $documentId = intval($documentId);
         if ($documentId <= 0) {
             return array();
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         return array($file->getCreatedBy());
     }
     if ($storageId) {
         $storage = Storage::loadById($storageId, array('ROOT_OBJECT'));
         if ($storage->getProxyType() instanceof ProxyType\Group) {
             $entityId = $storage->getEntityId();
             $group = strtoupper($group);
             if (Loader::includeModule("socialnetwork")) {
                 $listUserGroup = array();
                 if ($group == SONET_ROLES_OWNER) {
                     $listGroup = \CSocNetGroup::getByID($entityId);
                     if ($listGroup) {
                         $listUserGroup[] = $listGroup["OWNER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_MODERATOR) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_USER) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 }
                 return $listUserGroup;
             }
         }
     }
     $group = intval($group);
     if ($group <= 0) {
         return array();
     }
     $userIds = array();
     $filter = array("ACTIVE" => "Y");
     if ($group != 2) {
         $filter["GROUPS_ID"] = $group;
     }
     $query = \CUser::getList($b = "ID", $o = "ASC", $filter);
     while ($user = $query->fetch()) {
         $userIds[] = $user["ID"];
     }
     return $userIds;
 }
Пример #5
0
 private function getGroupBySection(array $sectionData)
 {
     if (empty($sectionData['SOCNET_GROUP_ID'])) {
         //todo implement search
         return array();
     }
     $group = \CSocNetGroup::getByID($sectionData['SOCNET_GROUP_ID']);
     return empty($group) ? array() : $group;
 }
Пример #6
0
 public static function GetPermissions($Params = array())
 {
     global $USER;
     $type = isset($Params['type']) ? $Params['type'] : self::$type;
     $ownerId = isset($Params['ownerId']) ? $Params['ownerId'] : self::$ownerId;
     $userId = isset($Params['userId']) ? $Params['userId'] : self::$userId;
     $bView = true;
     $bEdit = true;
     $bEditSection = true;
     if ($type == 'user' && $ownerId != $userId) {
         $bEdit = false;
         $bEditSection = false;
     }
     if ($type == 'group') {
         if (!$USER->CanDoOperation('edit_php')) {
             $keyOwner = 'SG' . $ownerId . '_A';
             $keyMod = 'SG' . $ownerId . '_E';
             $keyMember = 'SG' . $ownerId . '_K';
             $arCodes = array();
             $rCodes = CAccess::GetUserCodes($userId);
             while ($code = $rCodes->Fetch()) {
                 $arCodes[] = $code['ACCESS_CODE'];
             }
             if (CModule::IncludeModule("socialnetwork")) {
                 $group = CSocNetGroup::getByID($ownerId);
                 if (!empty($group['CLOSED']) && $group['CLOSED'] === 'Y' && \Bitrix\Main\Config\Option::get('socialnetwork', 'work_with_closed_groups', 'N') === 'N') {
                     self::$isArchivedGroup = true;
                 }
             }
             if (in_array($keyOwner, $arCodes)) {
                 $bEdit = true;
                 $bEditSection = true;
             } elseif (in_array($keyMod, $arCodes) && !self::$isArchivedGroup) {
                 $bEdit = true;
                 $bEditSection = true;
             } elseif (in_array($keyMember, $arCodes) && !self::$isArchivedGroup) {
                 $bEdit = true;
                 $bEditSection = false;
             } else {
                 $bEdit = false;
                 $bEditSection = false;
             }
         }
     }
     if ($type != 'user' && $type != 'group') {
         $bView = CCalendarType::CanDo('calendar_type_view', $type);
         $bEdit = CCalendarType::CanDo('calendar_type_edit', $type);
         $bEditSection = CCalendarType::CanDo('calendar_type_edit_section', $type);
     }
     if ($Params['setProperties'] !== false) {
         self::$perm['view'] = $bView;
         self::$perm['edit'] = $bEdit;
         self::$perm['section_edit'] = $bEditSection;
     }
     return array('view' => $bView, 'edit' => $bEdit, 'section_edit' => $bEditSection);
 }