PHP code example of davidbadura / taskwarrior

1. Go to this page and download the library: Download davidbadura/taskwarrior library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

davidbadura / taskwarrior example snippets


\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');

use DavidBadura\Taskwarrior\TaskManager;
use DavidBadura\Taskwarrior\Task;
use DavidBadura\Taskwarrior\Recurring;
use DavidBadura\Taskwarrior\Annotation;

$tm = TaskManager::create();

$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);
$task->addAnnotation(new Annotation("and add many features"));

$tm->save($task);

$tasks = $tm->filterPending('project:hobby'); // one task

$tm->done($task);

$tasks = $tm->filterPending('project:hobby'); // empty
$tasks = $tm->filter('project:hobby'); // one task

$tasks = $tm->filterByReport('waiting'); // and sorting

$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);

$tm = TaskManager::create();

$task = new Task();
$task->setDescription('foo');
$tm->save($task);

$task = $tm->find('b1d46c75-63cc-4753-a20f-a0b376f1ead0');

$tasks = $tm->filter('status:pending');
$tasks = $tm->filter('status:pending +home');
$tasks = $tm->filter('status:pending and +home');
$tasks = $tm->filter(['status:pending', '+home']);

$tasks = $tm->filterPending('+home');
$tasks = $tm->filterPending('project:hobby +home');
$tasks = $tm->filterPending('project:hobby and +home');
$tasks = $tm->filterPending(['project:hobby', '+home']);

$tasks = $tm->count('status:pending');
$tasks = $tm->count('status:pending +home');
$tasks = $tm->count('status:pending and +home');
$tasks = $tm->count(['status:pending', '+home']);

$tm->delete($task);

$tm->done($task);

$tm->start($task);

$tm->stop($task);

$tm->reopen($task);

$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

$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"

$tasks = $taskManager->createQueryBuilder()
    ->whereProject('hobby')
    ->orderBy(['entry' => 'DESC'])
    ->getResult()