This commit is contained in:
DavidBadura 2015-02-06 17:31:13 +00:00
parent b81cad6243
commit a58ceedefc
5 changed files with 92 additions and 5 deletions

View File

@ -5,14 +5,18 @@
![WOW](http://i.imgur.com/mvSQh0M.gif) ![WOW](http://i.imgur.com/mvSQh0M.gif)
```php ```php
$tm = \DavidBadura\Taskwarrior\TaskManager::create(); use DavidBadura\Taskwarrior\TaskManager;
use DavidBadura\Taskwarrior\Task;
$task = new \DavidBadura\Taskwarrior\Task(); $tm = TaskManager::create();
$task = new Task();
$task->setDescription('program this lib'); $task->setDescription('program this lib');
$task->setProject('hobby'); $task->setProject('hobby');
$task->setDue(new \DateTime('tomorrow')); $task->setDue(new \DateTime('tomorrow'));
$task->setPriority(Task::PRIORITY_HIGH);
$task->addTag('next'); // todo :D $task->addTag('next');
$tm->save($task); $tm->save($task);

View File

@ -14,9 +14,9 @@ class Task
const STATUS_DELETED = 'deleted'; const STATUS_DELETED = 'deleted';
const STATUS_WAITING = 'waiting'; const STATUS_WAITING = 'waiting';
const PRIORITY_LOW = 'L'; const PRIORITY_LOW = 'L';
const PRIORITY_MEDIUM = 'M'; const PRIORITY_MEDIUM = 'M';
const PRIORITY_HIGH = 'H'; const PRIORITY_HIGH = 'H';
/** /**
* @var string * @var string
@ -53,6 +53,13 @@ class Task
*/ */
private $due; private $due;
/**
* @var array
*
* @JMS\Type(name="array<string>")
*/
private $tags;
/** /**
* @var float * @var float
* *
@ -156,6 +163,42 @@ class Task
$this->due = $due; $this->due = $due;
} }
/**
* @return array
*/
public function getTags()
{
return (array)$this->tags;
}
/**
* @param array $tags
*/
public function setTags(array $tags = array())
{
$this->tags = $tags;
}
/**
* @param string $tag
*/
public function addTag($tag)
{
if (!in_array($tag, $this->tags)) {
$this->tags[] = $tag;
}
}
/**
* @param string $tag
*/
public function removeTag($tag)
{
if (false !== $key = array_search($tag, $this->tags)) {
unset($this->tags[$key]);
}
}
/** /**
* @return \DateTime * @return \DateTime
*/ */

View File

@ -192,6 +192,7 @@ class TaskManager
'description' => $task->getDescription(), 'description' => $task->getDescription(),
'project' => $task->getProject(), 'project' => $task->getProject(),
'priority' => $task->getPriority(), 'priority' => $task->getPriority(),
'tags' => $task->getTags(),
'due' => $task->getDue() ? $task->getDue()->format('Ymd\THis\Z') : null, 'due' => $task->getDue() ? $task->getDue()->format('Ymd\THis\Z') : null,
], ],
$task->getUuid() $task->getUuid()

View File

@ -70,6 +70,14 @@ class Taskwarrior
$options[] = 'priority:' . $params['priority']; $options[] = 'priority:' . $params['priority'];
} }
if (array_key_exists('tags', $params)) {
if (is_array($params['tags'])) {
$options[] = 'tags:' . implode(',', $params['tags']);
} else {
$options[] = 'tags:' . $params['tags'];
}
}
if (array_key_exists('description', $params)) { if (array_key_exists('description', $params)) {
$options[] = $params['description']; $options[] = $params['description'];
} }

View File

@ -373,6 +373,37 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(Task::PRIORITY_HIGH, $task1->getPriority()); $this->assertEquals(Task::PRIORITY_HIGH, $task1->getPriority());
} }
public function testTag()
{
$task1 = new Task();
$task1->setDescription('foo1');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEmpty($task1->getTags());
$task1->setTags(array('a', 'b', 'c'));
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(array('a', 'b', 'c'), $task1->getTags());
$task1->addTag('d');
$task1->removeTag('a');
$this->taskManager->save($task1);
$this->taskManager->clear();
$task1 = $this->taskManager->find($task1->getUuid());
$this->assertEquals(array('b', 'c', 'd'), $task1->getTags());
$this->assertCount(0, $this->taskManager->filter('+a'));
$this->assertCount(1, $this->taskManager->filter('+b'));
}
/** /**
* @param string $string * @param string $string
* @return \DateTime * @return \DateTime