Example #1
0
 protected function handleRequest(array $request)
 {
     $listId = $request[self::FIELD_LIST_ID];
     $list = TasksList::fetch($listId);
     $projectId = $list->getProjectId();
     Project::lock($projectId);
     TasksList::erase($listId);
     TasksList::shiftLeft($projectId, $list->getOrd());
 }
Example #2
0
 protected function handleRequest(array $request)
 {
     $projectId = $request[self::FIELD_PROJECT_ID];
     $beforeId = $request[self::FIELD_BEFORE_LIST_ID];
     $title = $request[self::FIELD_TITLE];
     Project::lock($projectId);
     $ord = null;
     if ($beforeId) {
         $beforeList = TasksList::fetch($beforeId);
         if ($beforeList->getProjectId() !== $projectId) {
             throw new Exception("Insertion point for a new list is in another project", EndPoint::STATUS_BAD_REQUEST);
         }
         $ord = $beforeList->getOrd();
         TasksList::shiftRight($projectId, $ord);
     } else {
         $ord = TasksList::getNextOrd($projectId);
     }
     $listId = TasksList::create($projectId, $ord, $title);
     return array(self::FIELD_LIST_ID => $listId);
 }
Example #3
0
 protected function handleRequest(array $request)
 {
     $listId = $request[self::FIELD_LIST_ID];
     $beforeListId = $request[self::FIELD_BEFORE_LIST_ID];
     $list = TasksList::fetch($listId);
     $projectId = $list->getProjectId();
     Project::lock($projectId);
     if ($beforeListId) {
         TasksList::shiftLeft($projectId, $list->getOrd());
         if ($beforeListId === $listId) {
             throw new Exception("Can't move list before itself", EndPoint::STATUS_BAD_REQUEST);
         }
         $beforeList = TasksList::fetch($beforeListId);
         if ($beforeList->getProjectId() !== $projectId) {
             throw new Exception("Insertion point for a list is in another project", EndPoint::STATUS_BAD_REQUEST);
         }
         TasksList::shiftRight($projectId, $beforeList->getOrd());
         TasksList::updateOrd($listId, $beforeList->getOrd());
     } else {
         TasksList::shiftLeft($projectId, $list->getOrd());
         TasksList::updateOrd($listId, TasksList::getNextOrd($projectId));
     }
 }
Example #4
0
 protected function handleRequest(array $request)
 {
     $taskId = $request[self::FIELD_TASK_ID];
     $dstListId = $request[self::FIELD_LIST_ID];
     $beforeTaskId = $request[self::FIELD_BEFORE_TASK_ID];
     if (isset($request[self::FIELD_AFTER_LAST_OPEN])) {
         if ($request[self::FIELD_AFTER_LAST_OPEN]) {
             $beforeTaskId = Task::findNextTaskIdAfterLastOpenTask($dstListId);
         }
     }
     $task = Task::fetch($taskId);
     $srcListId = $task->getListId();
     if ($srcListId !== $dstListId) {
         $srcList = TasksList::fetch($srcListId);
         $dstList = TasksList::fetch($dstListId);
         if ($srcList->getProjectId() !== $dstList->getProjectId()) {
             throw new Exception("Insertion point for a task is in another project list", EndPoint::STATUS_BAD_REQUEST);
         }
     }
     TasksList::lock($srcListId, $dstListId);
     if ($beforeTaskId) {
         Task::shiftLeft($srcListId, $task->getOrd());
         if ($beforeTaskId === $taskId) {
             throw new Exception("Can't move task before itself", EmdPoint::STATUS_BAD_REQUEST);
         }
         $beforeTask = Task::fetch($beforeTaskId);
         if ($beforeTask->getListId() !== $dstListId) {
             throw new Exception("Insertion point for a task is not in destination list", EndPoint::STATUS_BAD_REQUEST);
         }
         Task::shiftRight($dstListId, $beforeTask->getOrd());
         Task::updateListAndOrd($taskId, $dstListId, $beforeTask->getOrd());
     } else {
         Task::shiftLeft($srcListId, $task->getOrd());
         Task::updateListAndOrd($taskId, $dstListId, Task::getNextOrd($dstListId));
     }
 }