/** * * 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(); }
private function checkHasAccess() { if ($this->hasAccess === null) { try { if (Loader::includeModule("tasks")) { $task = new \CTaskItem($this->getId(), $this->getUser()->getId()); $this->hasAccess = $task->checkCanRead(); } else { return false; } } catch (\TasksException $e) { return false; } } return $this->hasAccess; }
public static function checkUserReadAccess(array $params) { $task = new \CTaskItem($params['taskId'], static::getUser()->GetID()); $access = $task->checkCanRead(); return !!$access; }