add tags
This commit is contained in:
parent
b81cad6243
commit
a58ceedefc
10
README.md
10
README.md
|
@ -5,14 +5,18 @@
|
|||
![WOW](http://i.imgur.com/mvSQh0M.gif)
|
||||
|
||||
```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->setProject('hobby');
|
||||
$task->setDue(new \DateTime('tomorrow'));
|
||||
$task->setPriority(Task::PRIORITY_HIGH);
|
||||
|
||||
$task->addTag('next'); // todo :D
|
||||
$task->addTag('next');
|
||||
|
||||
$tm->save($task);
|
||||
|
||||
|
|
47
src/Task.php
47
src/Task.php
|
@ -14,9 +14,9 @@ class Task
|
|||
const STATUS_DELETED = 'deleted';
|
||||
const STATUS_WAITING = 'waiting';
|
||||
|
||||
const PRIORITY_LOW = 'L';
|
||||
const PRIORITY_LOW = 'L';
|
||||
const PRIORITY_MEDIUM = 'M';
|
||||
const PRIORITY_HIGH = 'H';
|
||||
const PRIORITY_HIGH = 'H';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
@ -53,6 +53,13 @@ class Task
|
|||
*/
|
||||
private $due;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* @JMS\Type(name="array<string>")
|
||||
*/
|
||||
private $tags;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
|
@ -156,6 +163,42 @@ class Task
|
|||
$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
|
||||
*/
|
||||
|
|
|
@ -192,6 +192,7 @@ class TaskManager
|
|||
'description' => $task->getDescription(),
|
||||
'project' => $task->getProject(),
|
||||
'priority' => $task->getPriority(),
|
||||
'tags' => $task->getTags(),
|
||||
'due' => $task->getDue() ? $task->getDue()->format('Ymd\THis\Z') : null,
|
||||
],
|
||||
$task->getUuid()
|
||||
|
|
|
@ -70,6 +70,14 @@ class Taskwarrior
|
|||
$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)) {
|
||||
$options[] = $params['description'];
|
||||
}
|
||||
|
|
|
@ -373,6 +373,37 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$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
|
||||
* @return \DateTime
|
||||
|
|
Loading…
Reference in New Issue