A seriously powerful library for working with TODO list items and tasks.
- Parse and format
TaskItem
objects to and from JSON, and todo.txt format.
$parser = new Gravitask\Task\Parser\TodoTxtParser();
$input = "(A) Write the README file";
$task = $parser->parse($input);
$task->getPriority(); // Result: "A"
$task->getTask(); // Result: "Write the README file"
The recommended way to install this library is via Composer:
composer require gravitask/task
- PHP >= 5.4
This class is the "task object" and holds all of the information about the task, such as its creation date, priority, description, etc.
Name | Definition |
---|---|
STATUS_ACTIVE |
The status of the task is active - i.e. in progress, not completed. |
STATUS_COMPLETED |
The status of the task is completed. |
Set the name/description of the task to be completed.
$taskItem->setTask("Make another coffee");
Retrieve the name/description of the task.
$task->getTask();
// "Make another coffee"
Set the task's contexts to the items provided in the $contexts
array.
$contexts = ['email', 'computer'];
$task->setContexts($contexts);
Append a single context item to the pre-existing array of contexts.
$contexts = ['email'];
$task->setContexts($contexts);
$task->addContext('computer');
Retrieve an array of the task's contexts.
$contexts = ['email', 'computer'];
$task->setContexts($contexts);
$task->getContexts();
// ['email', 'computer']
Set the task's projects to the items provided in the $projects
array.
$projects = ['SecretProject'];
$task->setProjects($projects);
Append a single project item to the pre-existing array of projects.
$projects = ['SecretProject'];
$task->setProjects($projects);
$task->addProject('Work');
Retrieve an array of the task's projects.
$projects = ['SecretProject'];
$task->setProjects($projects);
$task->addProject('Work');
$task->getProjects();
// ['SecretProject', 'Work']
Set the task's optional creation date.
The $date
argument is a DateTime
object set to the required date and time.
$creationDate = new \DateTime::createFromFormat("Y-m-d", "2016-08-16");
$task->setCreationDate($creaionDate);
Retrieve the optional creation date value for the task.
$task->getCreationDate();
// \DateTime object
Set the date of when the task was completed.
The $date
argument is a DateTime
object set to the required date and time.
$task->setStatus(TaskItem::STATUS_COMPLETED);
$completionDate = new \DateTime::createFromFormat("Y-m-d", "2016-08-20");
$task->setCompletionDate($completionDate);
Retrieve the date that the task was completed.
$task->setStatus(TaskItem::STATUS_COMPLETED);
$completionDate = new \DateTime::createFromFormat("Y-m-d", "2016-08-20");
$task->setCompletionDate($completionDate);
$task->getCompletionDate()
// \DateTime object
Set the task's priority to the provided uppercase single letter of the alphabet. A
signifies the highest priority, whilst Z
represents the lowest.
$task->setPriority("B");
Retrieve the task's priority value represented by a single, uppercase letter of the alphabet.
$task->setPriority("F");
$task->getPriority();
// "F"
Set the status of the task to a different value.
Requirements:
- You should ONLY use the values provided as
TaskItem
constants beginning withSTATUS_
.
$task->setStatus(TaskItem::STATUS_COMPLETED);
Retrieve the current status of the task. By default this value will be
TaskItem::STATUS_ACTIVE
.
$task->setStatus(TaskItem::STATUS_COMPLETED);
$task->getStatus();
// Integer value representation of the status ENUM.
All formatters MUST implement the
Gravitask\Task\Formatter\FormatterInterface
.
Format the provided TaskItem
using the preferred formatter class, e.g. TodoTxtFormatter
.
$task->setPriority("A");
$task->setTask("Write example code");
$formatter = new Gravitask\Task\Formatter\TodoTxtFormatter();
$output = $formatter->format($task);
// "(A) Write example code"
All parsers MUST implement the
Gravitask\Task\Parser\ParserInterface
.
Parse the provided $input
variable and return a Gravitask\Task\TaskItem
object,
or FALSE
on failure to parse.
$parser = new Gravitask\Task\Parser\TodoTxtParser();
$input = "(A) Write the README file";
$task = $parser->parse($input);
$task->getPriority(); // Result: "A"
$task->getTask(); // Result: "Write the README file"