/** * * 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(); }
/** * Update a task with some new data */ public function update($id, array $data, array $parameters = array()) { global $USER; $result = array(); if ($id = $this->checkTaskId($id)) { if (!empty($data)) { $cacheAFWasDisabled = \CTasks::disableCacheAutoClear(); $notifADWasDisabled = \CTaskNotifications::disableAutoDeliver(); $task = new \CTaskItem($id, $USER->GetId()); $task->update($data); if ($notifADWasDisabled) { \CTaskNotifications::enableAutoDeliver(); } if ($cacheAFWasDisabled) { \CTasks::enableCacheAutoClear(); } if ($parameters['RETURN_OPERATION_RESULT_DATA']) { $result['DATA']['OPERATION_RESULT'] = $task->getLastOperationResultData('UPDATE'); } } } return $result; }
private function moveSubTasksToGroup($groupId) { static::enableUpdateBatchMode(); $subTasks = CTasks::getTaskSubTree($this->taskId); foreach ($subTasks as $sTaskId) { try { $sub = new CTaskItem($sTaskId, $this->executiveUserId); $sub->update(array('GROUP_ID' => $groupId), array('SUBTASKS_CHANGE_GROUP' => false)); } catch (TasksException $e) { static::disableUpdateBatchMode(); if (!$e->checkIsActionNotAllowed()) { throw $e; } } } static::disableUpdateBatchMode(); }