Taskwarrior/README.md

225 lines
4.3 KiB
Markdown
Raw Permalink Normal View History

2015-02-06 07:26:04 -06:00
# Taskwarrior PHP lib
2015-02-05 13:41:03 -06:00
2015-05-27 04:07:49 -05:00
used by [doThings](https://github.com/DavidBadura/doThings) - a Taskwarrior web-ui.
2015-05-27 04:07:19 -05:00
2015-02-05 13:47:39 -06:00
[![Build Status](https://travis-ci.org/DavidBadura/Taskwarrior.svg?branch=master)](https://travis-ci.org/DavidBadura/Taskwarrior)
2015-02-05 13:44:44 -06:00
2015-02-06 07:26:04 -06:00
![WOW](http://i.imgur.com/mvSQh0M.gif)
2015-02-08 15:08:58 -06:00
## Install
```bash
2015-02-08 15:31:40 -06:00
composer require 'davidbadura/taskwarrior'
2015-02-08 15:08:58 -06:00
```
2015-06-17 03:58:54 -05:00
Unfortunately, the annotation reader is not automatically registered on composer. So you should add following line if you have `[Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property [...] does not exist, or could not be auto-loaded.` exception:
2015-06-17 03:55:59 -05:00
```php
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
```
2015-05-02 07:03:47 -05:00
## Requirements
2015-05-15 06:38:38 -05:00
Taskwarrior changes its behavior by patch level updates and it is very difficult to support all versions.
2016-03-12 04:23:18 -06:00
The current supported versions are:
|PHP Lib|Taskwarrior|PHP Version|
|----|---------|------|
|2.x|>=2.4.3|>=5.4|
|3.x|>=2.5.0|>=5.5|
2015-04-13 02:54:44 -05:00
2015-02-08 15:08:58 -06:00
## Usage
2015-02-05 13:41:03 -06:00
```php
2015-02-06 11:31:13 -06:00
use DavidBadura\Taskwarrior\TaskManager;
use DavidBadura\Taskwarrior\Task;
2015-02-08 07:00:15 -06:00
use DavidBadura\Taskwarrior\Recurring;
2016-03-12 04:23:18 -06:00
use DavidBadura\Taskwarrior\Annotation;
2015-02-05 13:41:03 -06:00
2015-02-06 11:31:13 -06:00
$tm = TaskManager::create();
$task = new Task();
2015-02-06 06:09:01 -06:00
$task->setDescription('program this lib');
2015-02-06 06:08:13 -06:00
$task->setProject('hobby');
2015-02-08 07:29:44 -06:00
$task->setDue('tomorrow');
2015-02-06 11:31:13 -06:00
$task->setPriority(Task::PRIORITY_HIGH);
$task->addTag('next');
2015-02-08 07:29:44 -06:00
$task->setRecurring(Recurring::DAILY);
2016-03-12 04:23:18 -06:00
$task->addAnnotation(new Annotation("and add many features"));
2015-02-05 13:41:03 -06:00
2015-02-06 05:38:54 -06:00
$tm->save($task);
2015-02-05 13:41:03 -06:00
2015-04-23 16:28:57 -05:00
$tasks = $tm->filterPending('project:hobby'); // one task
2015-02-06 06:14:58 -06:00
$tm->done($task);
2015-04-23 16:28:57 -05:00
$tasks = $tm->filterPending('project:hobby'); // empty
$tasks = $tm->filter('project:hobby'); // one task
2015-04-23 14:16:31 -05:00
2015-04-23 16:28:57 -05:00
$tasks = $tm->filterByReport('waiting'); // and sorting
2015-02-05 13:41:03 -06:00
```
2015-02-08 15:08:58 -06:00
## API
2015-04-23 16:28:57 -05:00
### Task
|attr|writeable|type|
|----|---------|----|
|uuid|false|string|
|description|true|string|
|priority|true|string|
|project|true|string|
|due|true|DateTime|
|wait|true|DateTime|
|tags|true|string[]|
2016-03-12 04:23:18 -06:00
|annotations|true|Annotation[]|
2015-04-23 16:28:57 -05:00
|urgency|false|float|
|entry|false|DateTime|
|start|false|DateTime|
|recur|true|Recurring|
|unti|true|DateTime|
|modified|false|DateTime|
|end|false|DateTime|
|status|false|string|
Example:
```php
$task = new Task();
$task->setDescription('program this lib');
$task->setProject('hobby');
$task->setDue('tomorrow');
$task->setPriority(Task::PRIORITY_HIGH);
$task->addTag('next');
$task->setRecurring(Recurring::DAILY);
```
### Taskwarrior
create TaskManager:
```php
$tm = TaskManager::create();
```
save a task:
```php
$task = new Task();
$task->setDescription('foo');
$tm->save($task);
```
find a task:
```php
$task = $tm->find('b1d46c75-63cc-4753-a20f-a0b376f1ead0');
```
filter tasks:
```php
$tasks = $tm->filter('status:pending');
$tasks = $tm->filter('status:pending +home');
$tasks = $tm->filter('status:pending and +home');
$tasks = $tm->filter(['status:pending', '+home']);
```
filter pending tasks:
```php
$tasks = $tm->filterPending('+home');
$tasks = $tm->filterPending('project:hobby +home');
$tasks = $tm->filterPending('project:hobby and +home');
$tasks = $tm->filterPending(['project:hobby', '+home']);
```
2016-03-12 04:23:18 -06:00
count tasks:
```php
$tasks = $tm->count('status:pending');
$tasks = $tm->count('status:pending +home');
$tasks = $tm->count('status:pending and +home');
$tasks = $tm->count(['status:pending', '+home']);
```
2015-04-23 16:28:57 -05:00
delete task:
```php
$tm->delete($task);
```
done task:
```php
$tm->done($task);
```
start task:
```php
$tm->start($task);
```
stop task:
```php
$tm->stop($task);
```
reopen task:
```php
$tm->reopen($task);
```
2015-04-06 17:03:22 -05:00
2015-07-08 06:41:05 -05:00
dependencies:
```php
$task1 = new Task();
$task1->setDescription('a');
$task2 = new Task();
$task2->setDescription('b');
$task1->addDependency($task2);
// the order is important!
$tm->save($task2);
$tm->save($task1);
$tm->clear(); // clear object cache
$task1 = $tm->find('uuid-from-task1');
$task2 = $task1->getDependencies()[0];
echo $task2->getDesciption(); // "b" <- lazy loading
```
2016-03-12 04:23:18 -06:00
annotations:
```php
$task = new Task();
$task->setDescription('a');
$task->addAnnotation(new Annotation("foobar"));
$tm->save($task);
$tm->clear(); // clear object cache
$task = $tm->find('uuid-from-task1');
$annotation = $task->getAnnotations()[0];
echo $annotation->getDesciption(); // "foobar"
```
2015-04-06 17:03:22 -05:00
### QueryBuilder
2015-04-23 16:28:57 -05:00
example:
2015-04-06 17:03:22 -05:00
```php
$tasks = $taskManager->createQueryBuilder()
->whereProject('hobby')
2015-04-23 12:03:13 -05:00
->orderBy(['entry' => 'DESC'])
2015-04-06 17:03:22 -05:00
->getResult()
2015-04-13 02:54:44 -05:00
```