Close all subtasks when a task is closed
This commit is contained in:
@@ -227,6 +227,18 @@ class Subtask extends Base
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close all subtasks of a task
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $task_id
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function closeAll($task_id)
|
||||||
|
{
|
||||||
|
return $this->db->table(self::TABLE)->eq('task_id', $task_id)->update(array('status' => self::STATUS_DONE));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get subtasks with consecutive positions
|
* Get subtasks with consecutive positions
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class TaskStatus extends Base
|
|||||||
*/
|
*/
|
||||||
public function close($task_id)
|
public function close($task_id)
|
||||||
{
|
{
|
||||||
|
$this->subtask->closeAll($task_id);
|
||||||
return $this->changeStatus($task_id, Task::STATUS_CLOSED, time(), Task::EVENT_CLOSE);
|
return $this->changeStatus($task_id, Task::STATUS_CLOSED, time(), Task::EVENT_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ class TaskStatus extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the status of task
|
* Check the status of a task
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param integer $task_id Task id
|
* @param integer $task_id Task id
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div class="confirm">
|
<div class="confirm">
|
||||||
<p class="alert alert-info">
|
<p class="alert alert-info">
|
||||||
<?= t('Do you really want to close this task: "%s"?', $this->e($task['title'])) ?>
|
<?= t('Do you really want to close the task "%s" as well as all subtasks?', $this->e($task['title'])) ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
@@ -11,6 +11,28 @@ use Model\User;
|
|||||||
|
|
||||||
class SubTaskTest extends Base
|
class SubTaskTest extends Base
|
||||||
{
|
{
|
||||||
|
public function testCloseAll()
|
||||||
|
{
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$s = new Subtask($this->container);
|
||||||
|
$p = new Project($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||||
|
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||||
|
|
||||||
|
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||||
|
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||||
|
|
||||||
|
$this->assertTrue($s->closeAll(1));
|
||||||
|
|
||||||
|
$subtasks = $s->getAll(1);
|
||||||
|
$this->assertNotEmpty($subtasks);
|
||||||
|
|
||||||
|
foreach ($subtasks as $subtask) {
|
||||||
|
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testMoveUp()
|
public function testMoveUp()
|
||||||
{
|
{
|
||||||
$tc = new TaskCreation($this->container);
|
$tc = new TaskCreation($this->container);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once __DIR__.'/Base.php';
|
require_once __DIR__.'/Base.php';
|
||||||
|
|
||||||
|
use Model\Subtask;
|
||||||
use Model\Task;
|
use Model\Task;
|
||||||
use Model\TaskCreation;
|
use Model\TaskCreation;
|
||||||
use Model\TaskFinder;
|
use Model\TaskFinder;
|
||||||
@@ -74,4 +75,27 @@ class TaskStatusTest extends Base
|
|||||||
$this->assertArrayHasKey('task_id', $event);
|
$this->assertArrayHasKey('task_id', $event);
|
||||||
$this->assertNotEmpty($event['task_id']);
|
$this->assertNotEmpty($event['task_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testThatAllSubtasksAreClosed()
|
||||||
|
{
|
||||||
|
$ts = new TaskStatus($this->container);
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$s = new Subtask($this->container);
|
||||||
|
$p = new Project($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||||
|
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||||
|
|
||||||
|
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||||
|
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||||
|
|
||||||
|
$this->assertTrue($ts->close(1));
|
||||||
|
|
||||||
|
$subtasks = $s->getAll(1);
|
||||||
|
$this->assertNotEmpty($subtasks);
|
||||||
|
|
||||||
|
foreach ($subtasks as $subtask) {
|
||||||
|
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user