Create new class SubtaskTaskConversionModel

This commit is contained in:
Frederic Guillot 2016-07-23 21:22:24 -04:00
parent 2a7ca0405c
commit f216e345ba
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
7 changed files with 81 additions and 52 deletions

View File

@ -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.'));

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -61,6 +61,7 @@ class ClassProvider implements ServiceProviderInterface
'RememberMeSessionModel',
'SubtaskModel',
'SubtaskPositionModel',
'SubtaskTaskConversionModel',
'SubtaskTimeTrackingModel',
'SwimlaneModel',
'TagDuplicationModel',

View File

@ -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);

View File

@ -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']);
}
}