add start&stop

This commit is contained in:
DavidBadura 2015-04-23 19:33:10 +00:00
parent f4ba78f822
commit 9f3ea62916
4 changed files with 83 additions and 5 deletions

View File

@ -84,6 +84,13 @@ class Task
*/ */
private $entry; private $entry;
/**
* @var Carbon
*
* @JMS\Type("Carbon")
*/
private $start;
/** /**
* @var string * @var string
* *
@ -186,7 +193,7 @@ class Task
} }
/** /**
* @return \DateTime * @return Carbon
*/ */
public function getDue() public function getDue()
{ {
@ -202,7 +209,7 @@ class Task
} }
/** /**
* @return \DateTime * @return Carbon
*/ */
public function getWait() public function getWait()
{ {
@ -284,7 +291,7 @@ class Task
} }
/** /**
* @return \DateTime * @return Carbon
*/ */
public function getUntil() public function getUntil()
{ {
@ -300,7 +307,7 @@ class Task
} }
/** /**
* @return \DateTime * @return Carbon
*/ */
public function getEntry() public function getEntry()
{ {
@ -308,7 +315,15 @@ class Task
} }
/** /**
* @return \DateTime * @return Carbon
*/
public function getStart()
{
return $this->start;
}
/**
* @return Carbon
*/ */
public function getModified() public function getModified()
{ {

View File

@ -155,6 +155,32 @@ class TaskManager
$this->refresh($task); $this->refresh($task);
} }
/**
* @param Task $task
*/
public function start(Task $task)
{
if (!$task->getUuid()) {
return;
}
$this->taskwarrior->start($task->getUuid());
$this->refresh($task);
}
/**
* @param Task $task
*/
public function stop(Task $task)
{
if (!$task->getUuid()) {
return;
}
$this->taskwarrior->stop($task->getUuid());
$this->refresh($task);
}
/** /**
* @param Task $task * @param Task $task
*/ */
@ -313,6 +339,7 @@ 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, 'start', $new->getStart());
if ($new->isPending()) { // fix reopen problem if ($new->isPending()) { // fix reopen problem
$this->setValue($old, 'end', null); $this->setValue($old, 'end', null);

View File

@ -62,6 +62,22 @@ class Taskwarrior
$this->command('done', $filter); $this->command('done', $filter);
} }
/**
* @param string $filter
*/
public function start($filter)
{
$this->command('start', $filter);
}
/**
* @param string $filter
*/
public function stop($filter)
{
$this->command('stop', $filter);
}
/** /**
* @param array $params * @param array $params
*/ */

View File

@ -270,6 +270,26 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('DateTime', $task1->getEnd()); $this->assertInstanceOf('DateTime', $task1->getEnd());
} }
public function testStart()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->assertNull($task1->getStart());
$this->taskManager->start($task1);
$this->taskManager->save($task1);
$this->assertInstanceOf('DateTime', $task1->getStart());
$this->taskManager->stop($task1);
$this->taskManager->save($task1);
$this->assertNull($task1->getStart());
}
public function testPending() public function testPending()
{ {
$task1 = new Task(); $task1 = new Task();