diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-02 15:29:48 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-02 15:29:48 -0400 |
commit | b7ac354e83af122e94cec1f9306aca6355a02a39 (patch) | |
tree | 5baef2bd1bbd7928a965cfc69c68875bfaa9b5e1 | |
parent | 6d5577fa0bc108fcafa92fc4ac4b9ed621bfe33e (diff) |
Move Task::duplicate() to class ProjectTaskDuplicationModel
-rw-r--r-- | app/Core/Base.php | 1 | ||||
-rw-r--r-- | app/Model/ProjectDuplicationModel.php | 4 | ||||
-rw-r--r-- | app/Model/ProjectTaskDuplicationModel.php | 35 | ||||
-rw-r--r-- | app/Model/TaskModel.php | 83 | ||||
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 1 | ||||
-rw-r--r-- | app/Template/project_creation/create.php | 2 | ||||
-rw-r--r-- | app/Template/project_view/duplicate.php | 2 | ||||
-rw-r--r-- | tests/units/Model/ProjectDuplicationModelTest.php | 6 |
8 files changed, 75 insertions, 59 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php index a8274152..7320aebf 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -86,6 +86,7 @@ use Pimple\Container; * @property \Kanboard\Model\ProjectGroupRoleModel $projectGroupRoleModel * @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel * @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel + * @property \Kanboard\Model\ProjectTaskDuplicationModel $projectTaskDuplicationModel * @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel * @property \Kanboard\Model\SubtaskModel $subtaskModel * @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel diff --git a/app/Model/ProjectDuplicationModel.php b/app/Model/ProjectDuplicationModel.php index 4db8f767..f6b9683e 100644 --- a/app/Model/ProjectDuplicationModel.php +++ b/app/Model/ProjectDuplicationModel.php @@ -29,7 +29,7 @@ class ProjectDuplicationModel extends Base 'swimlaneModel', 'tagDuplicationModel', 'projectMetadataModel', - 'taskModel', + 'projectTaskDuplicationModel', ); } @@ -49,7 +49,7 @@ class ProjectDuplicationModel extends Base 'swimlaneModel', 'tagDuplicationModel', 'projectMetadataModel', - 'taskModel', + 'projectTaskDuplicationModel', ); } diff --git a/app/Model/ProjectTaskDuplicationModel.php b/app/Model/ProjectTaskDuplicationModel.php new file mode 100644 index 00000000..5d2e1322 --- /dev/null +++ b/app/Model/ProjectTaskDuplicationModel.php @@ -0,0 +1,35 @@ +<?php + +namespace Kanboard\Model; + +use Kanboard\Core\Base; + +/** + * Project Task Duplication Model + * + * @package Kanboard\Model + * @author Frederic Guillot + */ +class ProjectTaskDuplicationModel extends Base +{ + /** + * Duplicate all tasks to another project + * + * @access public + * @param integer $src_project_id + * @param integer $dst_project_id + * @return boolean + */ + public function duplicate($src_project_id, $dst_project_id) + { + $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); + + foreach ($task_ids as $task_id) { + if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/TaskModel.php b/app/Model/TaskModel.php index b945ee44..5df41f3c 100644 --- a/app/Model/TaskModel.php +++ b/app/Model/TaskModel.php @@ -17,80 +17,80 @@ class TaskModel extends Base * * @var string */ - const TABLE = 'tasks'; + const TABLE = 'tasks'; /** * Task status * * @var integer */ - const STATUS_OPEN = 1; - const STATUS_CLOSED = 0; + const STATUS_OPEN = 1; + const STATUS_CLOSED = 0; /** * Events * * @var string */ - const EVENT_MOVE_PROJECT = 'task.move.project'; - const EVENT_MOVE_COLUMN = 'task.move.column'; - const EVENT_MOVE_POSITION = 'task.move.position'; - const EVENT_MOVE_SWIMLANE = 'task.move.swimlane'; - const EVENT_UPDATE = 'task.update'; - const EVENT_CREATE = 'task.create'; - const EVENT_CLOSE = 'task.close'; - const EVENT_OPEN = 'task.open'; - const EVENT_CREATE_UPDATE = 'task.create_update'; + const EVENT_MOVE_PROJECT = 'task.move.project'; + const EVENT_MOVE_COLUMN = 'task.move.column'; + const EVENT_MOVE_POSITION = 'task.move.position'; + const EVENT_MOVE_SWIMLANE = 'task.move.swimlane'; + const EVENT_UPDATE = 'task.update'; + const EVENT_CREATE = 'task.create'; + const EVENT_CLOSE = 'task.close'; + const EVENT_OPEN = 'task.open'; + const EVENT_CREATE_UPDATE = 'task.create_update'; const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change'; - const EVENT_OVERDUE = 'task.overdue'; - const EVENT_USER_MENTION = 'task.user.mention'; - const EVENT_DAILY_CRONJOB = 'task.cronjob.daily'; + const EVENT_OVERDUE = 'task.overdue'; + const EVENT_USER_MENTION = 'task.user.mention'; + const EVENT_DAILY_CRONJOB = 'task.cronjob.daily'; /** * Recurrence: status * * @var integer */ - const RECURRING_STATUS_NONE = 0; - const RECURRING_STATUS_PENDING = 1; - const RECURRING_STATUS_PROCESSED = 2; + const RECURRING_STATUS_NONE = 0; + const RECURRING_STATUS_PENDING = 1; + const RECURRING_STATUS_PROCESSED = 2; /** * Recurrence: trigger * * @var integer */ - const RECURRING_TRIGGER_FIRST_COLUMN = 0; - const RECURRING_TRIGGER_LAST_COLUMN = 1; - const RECURRING_TRIGGER_CLOSE = 2; + const RECURRING_TRIGGER_FIRST_COLUMN = 0; + const RECURRING_TRIGGER_LAST_COLUMN = 1; + const RECURRING_TRIGGER_CLOSE = 2; /** * Recurrence: timeframe * * @var integer */ - const RECURRING_TIMEFRAME_DAYS = 0; - const RECURRING_TIMEFRAME_MONTHS = 1; - const RECURRING_TIMEFRAME_YEARS = 2; + const RECURRING_TIMEFRAME_DAYS = 0; + const RECURRING_TIMEFRAME_MONTHS = 1; + const RECURRING_TIMEFRAME_YEARS = 2; /** * Recurrence: base date used to calculate new due date * * @var integer */ - const RECURRING_BASEDATE_DUEDATE = 0; - const RECURRING_BASEDATE_TRIGGERDATE = 1; + const RECURRING_BASEDATE_DUEDATE = 0; + const RECURRING_BASEDATE_TRIGGERDATE = 1; /** * Remove a task * * @access public - * @param integer $task_id Task id + * @param integer $task_id Task id * @return boolean */ public function remove($task_id) { - if (! $this->taskFinderModel->exists($task_id)) { + if (!$this->taskFinderModel->exists($task_id)) { return false; } @@ -105,7 +105,7 @@ class TaskModel extends Base * Example: "Fix bug #1234" will return 1234 * * @access public - * @param string $message Text + * @param string $message Text * @return integer */ public function getTaskIdFromText($message) @@ -179,8 +179,8 @@ class TaskModel extends Base * Get task progress based on the column position * * @access public - * @param array $task - * @param array $columns + * @param array $task + * @param array $columns * @return integer */ public function getProgress(array $task, array $columns) @@ -201,25 +201,4 @@ class TaskModel extends Base return round(($position * 100) / count($columns), 1); } - - /** - * Helper method to duplicate all tasks to another project - * - * @access public - * @param integer $src_project_id - * @param integer $dst_project_id - * @return boolean - */ - public function duplicate($src_project_id, $dst_project_id) - { - $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); - - foreach ($task_ids as $task_id) { - if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { - return false; - } - } - - return true; - } } diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 1f584fca..2d485e22 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -55,6 +55,7 @@ class ClassProvider implements ServiceProviderInterface 'ProjectNotificationModel', 'ProjectMetadataModel', 'ProjectGroupRoleModel', + 'ProjectTaskDuplicationModel', 'ProjectUserRoleModel', 'RememberMeSessionModel', 'SubtaskModel', diff --git a/app/Template/project_creation/create.php b/app/Template/project_creation/create.php index dc1bc370..d00883ba 100644 --- a/app/Template/project_creation/create.php +++ b/app/Template/project_creation/create.php @@ -26,7 +26,7 @@ <?= $this->form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?> <?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?> <?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, true) ?> - <?= $this->form->checkbox('taskModel', t('Tasks'), 1, false) ?> + <?= $this->form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?> </div> <div class="form-actions"> diff --git a/app/Template/project_view/duplicate.php b/app/Template/project_view/duplicate.php index a9680016..d66ff591 100644 --- a/app/Template/project_view/duplicate.php +++ b/app/Template/project_view/duplicate.php @@ -19,7 +19,7 @@ <?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?> <?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, false) ?> <?= $this->form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?> - <?= $this->form->checkbox('taskModel', t('Tasks'), 1, false) ?> + <?= $this->form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?> <div class="form-actions"> <button type="submit" class="btn btn-red"><?= t('Duplicate') ?></button> diff --git a/tests/units/Model/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php index de7b0d79..41e59c9c 100644 --- a/tests/units/Model/ProjectDuplicationModelTest.php +++ b/tests/units/Model/ProjectDuplicationModelTest.php @@ -428,7 +428,7 @@ class ProjectDuplicationModelTest extends Base $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); - $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'taskModel'))); + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'projectTaskDuplicationModel'))); // Check if Tasks have been duplicated $tasks = $taskFinderModel->getAll(2); @@ -458,7 +458,7 @@ class ProjectDuplicationModelTest extends Base $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel'))); + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'projectTaskDuplicationModel'))); // Check if Swimlanes have been duplicated $swimlanes = $swimlaneModel->getAll(2); @@ -496,7 +496,7 @@ class ProjectDuplicationModelTest extends Base $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B')))); $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C')))); - $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'taskModel'))); + $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'projectTaskDuplicationModel'))); $tasks = $taskFinderModel->getAll(2); $this->assertCount(3, $tasks); |