1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
namespace Kanboard\Model;
use Kanboard\Event\TaskEvent;
/**
* Task Project Move
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TaskProjectMoveModel extends TaskDuplicationModel
{
/**
* Move a task to another project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return boolean
*/
public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{
$task = $this->taskFinderModel->getById($task_id);
$values = $this->prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, $task);
$this->checkDestinationProjectValues($values);
$this->tagDuplicationModel->syncTaskTagsToAnotherProject($task_id, $project_id);
if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) {
$event = new TaskEvent(array_merge($task, $values, array('task_id' => $task['id'])));
$this->dispatcher->dispatch(TaskModel::EVENT_MOVE_PROJECT, $event);
}
return true;
}
/**
* Prepare new task values
*
* @access protected
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @param array $task
* @return array
*/
protected function prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, array $task)
{
$values = array();
$values['is_active'] = 1;
$values['project_id'] = $project_id;
$values['column_id'] = $column_id !== null ? $column_id : $task['column_id'];
$values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1;
$values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id'];
$values['category_id'] = $category_id !== null ? $category_id : $task['category_id'];
$values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id'];
$values['priority'] = $task['priority'];
return $values;
}
}
|