diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-08-30 22:35:50 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-08-30 22:35:50 -0800 |
commit | 7e44dee903015399e221cdda52e540e75c2484f5 (patch) | |
tree | 48ddc68daa00b857bde78be9b6bd5ef5dbf36e5d /app/Model | |
parent | 9e36f84fbc672e8d63a189c6c6365a6eca97f718 (diff) |
Move a task to another project
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Acl.php | 1 | ||||
-rw-r--r-- | app/Model/Board.php | 2 | ||||
-rw-r--r-- | app/Model/Task.php | 53 |
3 files changed, 54 insertions, 2 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php index b2644686..23f6ff44 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -52,6 +52,7 @@ class Acl extends Base 'confirmremove', 'editdescription', 'savedescription', + 'move', ), ); diff --git a/app/Model/Board.php b/app/Model/Board.php index 74e29040..8fb30e70 100644 --- a/app/Model/Board.php +++ b/app/Model/Board.php @@ -35,7 +35,7 @@ class Board extends Base foreach ($positions as $value) { // We trigger events only for the selected task - if (! $this->task->move($value['task_id'], $value['column_id'], $value['position'], $value['task_id'] == $selected_task_id)) { + if (! $this->task->movePosition($value['task_id'], $value['column_id'], $value['position'], $value['task_id'] == $selected_task_id)) { $this->db->cancelTransaction(); return false; } diff --git a/app/Model/Task.php b/app/Model/Task.php index 09c77573..64f3b74c 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -545,7 +545,7 @@ class Task extends Base * @param boolean $trigger_events Flag to trigger events * @return boolean */ - public function move($task_id, $column_id, $position, $trigger_events = true) + public function movePosition($task_id, $column_id, $position, $trigger_events = true) { $this->event->clearTriggeredEvents(); @@ -559,6 +559,35 @@ class Task extends Base } /** + * Move a task to another project + * + * @access public + * @param integer $project_id Project id + * @param array $task Task data + * @return boolean + */ + public function moveToAnotherProject($project_id, array $task) + { + $values = array(); + + // Clear values (categories are different for each project) + $values['category_id'] = 0; + $values['owner_id'] = 0; + + // Check if the assigned user is allowed for the new project + if ($task['owner_id'] && $this->project->isUserAllowed($project_id, $task['owner_id'])) { + $values['owner_id'] = $task['owner_id']; + } + + // We use the first column of the new project + $values['column_id'] = $this->board->getFirstColumn($project_id); + $values['position'] = $this->countByColumnId($project_id, $values['column_id']); + $values['project_id'] = $project_id; + + return $this->db->table(self::TABLE)->eq('id', $task['id'])->update($values); + } + + /** * Validate task creation * * @access public @@ -663,6 +692,28 @@ class Task extends Base } /** + * Validate project modification + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateProjectModification(array $values) + { + $v = new Validator($values, array( + new Validators\Required('id', t('The id is required')), + new Validators\Integer('id', t('This value must be an integer')), + new Validators\Required('project_id', t('The project is required')), + new Validators\Integer('project_id', t('This value must be an integer')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** * Return a timestamp if the given date format is correct otherwise return 0 * * @access public |