summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controller/SubtaskConverterController.php2
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/Model/SubtaskModel.php27
-rw-r--r--app/Model/SubtaskTaskConversionModel.php41
-rw-r--r--app/ServiceProvider/ClassProvider.php1
-rw-r--r--tests/units/Model/SubtaskModelTest.php24
-rw-r--r--tests/units/Model/SubtaskTaskConversionModelTest.php37
7 files changed, 81 insertions, 52 deletions
diff --git a/app/Controller/SubtaskConverterController.php b/app/Controller/SubtaskConverterController.php
index 65bcd2da..404c50d0 100644
--- a/app/Controller/SubtaskConverterController.php
+++ b/app/Controller/SubtaskConverterController.php
@@ -26,7 +26,7 @@ class SubtaskConverterController extends BaseController
$project = $this->getProject();
$subtask = $this->getSubtask();
- $task_id = $this->subtaskModel->convertToTask($project['id'], $subtask['id']);
+ $task_id = $this->subtaskTaskConversionModel->convertToTask($project['id'], $subtask['id']);
if ($task_id !== false) {
$this->flash->success(t('Subtask converted to task successfully.'));
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 0230b671..8b9bf085 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -91,6 +91,7 @@ use Pimple\Container;
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
* @property \Kanboard\Model\SubtaskModel $subtaskModel
* @property \Kanboard\Model\SubtaskPositionModel $subtaskPositionModel
+ * @property \Kanboard\Model\SubtaskTaskConversionModel $subtaskTaskConversionModel
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
* @property \Kanboard\Model\SwimlaneModel $swimlaneModel
* @property \Kanboard\Model\TagDuplicationModel $tagDuplicationModel
diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php
index 5a4e87a2..2ac6095c 100644
--- a/app/Model/SubtaskModel.php
+++ b/app/Model/SubtaskModel.php
@@ -368,31 +368,4 @@ class SubtaskModel extends Base
}
});
}
-
- /**
- * Convert a subtask to a task
- *
- * @access public
- * @param integer $project_id
- * @param integer $subtask_id
- * @return integer
- */
- public function convertToTask($project_id, $subtask_id)
- {
- $subtask = $this->getById($subtask_id);
-
- $task_id = $this->taskCreationModel->create(array(
- 'project_id' => $project_id,
- 'title' => $subtask['title'],
- 'time_estimated' => $subtask['time_estimated'],
- 'time_spent' => $subtask['time_spent'],
- 'owner_id' => $subtask['user_id'],
- ));
-
- if ($task_id !== false) {
- $this->remove($subtask_id);
- }
-
- return $task_id;
- }
}
diff --git a/app/Model/SubtaskTaskConversionModel.php b/app/Model/SubtaskTaskConversionModel.php
new file mode 100644
index 00000000..8bf83d76
--- /dev/null
+++ b/app/Model/SubtaskTaskConversionModel.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Kanboard\Model;
+
+use Kanboard\Core\Base;
+
+/**
+ * Class SubtaskTaskConversionModel
+ *
+ * @package Kanboard\Model
+ * @author Frederic Guillot
+ */
+class SubtaskTaskConversionModel extends Base
+{
+ /**
+ * Convert a subtask to a task
+ *
+ * @access public
+ * @param integer $project_id
+ * @param integer $subtask_id
+ * @return integer
+ */
+ public function convertToTask($project_id, $subtask_id)
+ {
+ $subtask = $this->subtaskModel->getById($subtask_id);
+
+ $task_id = $this->taskCreationModel->create(array(
+ 'project_id' => $project_id,
+ 'title' => $subtask['title'],
+ 'time_estimated' => $subtask['time_estimated'],
+ 'time_spent' => $subtask['time_spent'],
+ 'owner_id' => $subtask['user_id'],
+ ));
+
+ if ($task_id !== false) {
+ $this->subtaskModel->remove($subtask_id);
+ }
+
+ return $task_id;
+ }
+}
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index d1415d8c..ad69d5fb 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -61,6 +61,7 @@ class ClassProvider implements ServiceProviderInterface
'RememberMeSessionModel',
'SubtaskModel',
'SubtaskPositionModel',
+ 'SubtaskTaskConversionModel',
'SubtaskTimeTrackingModel',
'SwimlaneModel',
'TagDuplicationModel',
diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php
index 3b25bb3b..d270e177 100644
--- a/tests/units/Model/SubtaskModelTest.php
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -229,30 +229,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(2, $subtasks[1]['position']);
}
- public function testConvertToTask()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
- $task_id = $subtaskModel->convertToTask(1, 1);
-
- $this->assertNotFalse($task_id);
- $this->assertEmpty($subtaskModel->getById(1));
-
- $task = $taskFinderModel->getById($task_id);
- $this->assertEquals('subtask #1', $task['title']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['time_spent']);
- $this->assertEquals(3, $task['time_estimated']);
- }
-
public function testGetProjectId()
{
$taskCreationModel = new TaskCreationModel($this->container);
diff --git a/tests/units/Model/SubtaskTaskConversionModelTest.php b/tests/units/Model/SubtaskTaskConversionModelTest.php
new file mode 100644
index 00000000..51a623b2
--- /dev/null
+++ b/tests/units/Model/SubtaskTaskConversionModelTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTaskConversionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskTaskConversionModelTest extends Base
+{
+ public function testConvertToTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskConversion = new SubtaskTaskConversionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
+ $task_id = $subtaskConversion->convertToTask(1, 1);
+
+ $this->assertNotFalse($task_id);
+ $this->assertEmpty($subtaskModel->getById(1));
+
+ $task = $taskFinderModel->getById($task_id);
+ $this->assertEquals('subtask #1', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(2, $task['time_spent']);
+ $this->assertEquals(3, $task['time_estimated']);
+ }
+}