add reopen feature

This commit is contained in:
DavidBadura 2015-02-10 20:49:30 +00:00
parent 37374f42db
commit 4a36d7e511
3 changed files with 56 additions and 1 deletions

View File

@ -141,6 +141,26 @@ class TaskManager
$this->refresh($task); $this->refresh($task);
} }
/**
* @param Task $task
*/
public function reopen(Task $task)
{
if (!$task->getUuid()) {
return;
}
if ($task->isPending() || $task->isWaiting() || $task->isReccuring()) {
return;
}
$this->taskwarrior->modify([
'status' => Task::STATUS_PENDING
], $task->getUuid());
$this->refresh($task);
}
/** /**
* @param Task $task * @param Task $task
*/ */
@ -212,7 +232,12 @@ class TaskManager
$this->setValue($old, 'urgency', $new->getUrgency()); $this->setValue($old, 'urgency', $new->getUrgency());
$this->setValue($old, 'status', $new->getStatus()); $this->setValue($old, 'status', $new->getStatus());
$this->setValue($old, 'modified', $new->getModified()); $this->setValue($old, 'modified', $new->getModified());
$this->setValue($old, 'end', $new->getEnd());
if ($new->isPending()) { // fix reopen problem
$this->setValue($old, 'end', null);
} else {
$this->setValue($old, 'end', $new->getEnd());
}
} }
/** /**

View File

@ -225,6 +225,10 @@ class Taskwarrior
} }
} }
if (array_key_exists('status', $params)) {
$options[] = 'status:' . $params['status'];
}
if (array_key_exists('description', $params)) { if (array_key_exists('description', $params)) {
$options[] = $params['description']; $options[] = $params['description'];
} }

View File

@ -592,6 +592,32 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($date2, $task1->getUntil()); $this->assertEquals($date2, $task1->getUntil());
} }
public function testReopen()
{
$task = new Task();
$task->setDescription('foo');
$this->taskManager->save($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
$this->taskManager->done($task);
$this->assertTrue($task->isCompleted());
$this->assertInstanceOf('Carbon\Carbon', $task->getEnd());
$this->taskManager->reopen($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
$this->taskManager->delete($task);
$this->assertTrue($task->isDeleted());
$this->assertInstanceOf('Carbon\Carbon', $task->getEnd());
$this->taskManager->reopen($task);
$this->assertTrue($task->isPending());
$this->assertNull($task->getEnd());
}
/** /**
* @param string $string * @param string $string
* @return \DateTime * @return \DateTime