Taskwarrior/src/Task.php

378 lines
6.2 KiB
PHP
Raw Normal View History

2015-02-05 13:41:03 -06:00
<?php
namespace DavidBadura\Taskwarrior;
use JMS\Serializer\Annotation as JMS;
/**
* @author David Badura <d.a.badura@gmail.com>
*/
class Task
{
2015-02-05 17:09:29 -06:00
const STATUS_PENDING = 'pending';
2015-02-05 16:00:30 -06:00
const STATUS_COMPLETED = 'completed';
2015-02-05 17:09:29 -06:00
const STATUS_DELETED = 'deleted';
const STATUS_WAITING = 'waiting';
2015-02-05 16:00:30 -06:00
2015-02-06 11:31:13 -06:00
const PRIORITY_LOW = 'L';
2015-02-06 11:05:29 -06:00
const PRIORITY_MEDIUM = 'M';
2015-02-06 11:31:13 -06:00
const PRIORITY_HIGH = 'H';
2015-02-06 11:05:29 -06:00
2015-02-05 13:41:03 -06:00
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $uuid;
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $description;
2015-02-06 11:05:29 -06:00
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $priority;
2015-02-06 06:08:13 -06:00
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $project;
2015-02-05 17:09:29 -06:00
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $due;
2015-02-06 17:22:17 -06:00
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $wait;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $until;
2015-02-06 11:31:13 -06:00
/**
* @var array
*
* @JMS\Type(name="array<string>")
*/
private $tags;
2015-02-05 17:09:29 -06:00
/**
* @var float
*
* @JMS\Type(name="float")
*/
private $urgency;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $entry;
2015-02-06 17:22:17 -06:00
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $modified;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $end;
2015-02-05 16:00:30 -06:00
/**
* @var string
*
* @JMS\Type(name="string")
*/
private $status;
/**
*
*/
public function __construct()
{
2015-02-05 17:09:29 -06:00
$this->urgency = 0;
$this->entry = new \DateTime('now', new \DateTimeZone('UTC'));
$this->status = self::STATUS_PENDING;
2015-02-05 16:00:30 -06:00
}
2015-02-05 13:41:03 -06:00
/**
* @return string
*/
public function getUuid()
{
return $this->uuid;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
2015-02-05 16:00:30 -06:00
2015-02-06 11:05:29 -06:00
/**
* @return string
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param string $priority
*/
public function setPriority($priority)
{
$this->priority = $priority;
}
2015-02-06 06:08:13 -06:00
/**
* @return string
*/
public function getProject()
{
return $this->project;
}
/**
* @param string $project
*/
public function setProject($project)
{
$this->project = $project;
}
2015-02-05 16:00:30 -06:00
/**
2015-02-05 17:09:29 -06:00
* @return \DateTime
2015-02-05 16:00:30 -06:00
*/
2015-02-05 17:09:29 -06:00
public function getDue()
2015-02-05 16:00:30 -06:00
{
2015-02-05 17:09:29 -06:00
return $this->due;
}
/**
2015-02-06 17:22:17 -06:00
* @param \DateTime|string $due
*/
public function setDue($due = null)
{
$this->due = $this->parseDateTime($due);
}
/**
* @return \DateTime
*/
public function getWait()
{
return $this->wait;
}
/**
* @param \DateTime|string $wait
2015-02-05 17:09:29 -06:00
*/
2015-02-06 17:22:17 -06:00
public function setWait($wait = null)
2015-02-05 17:09:29 -06:00
{
2015-02-06 17:22:17 -06:00
$this->wait = $this->parseDateTime($wait);
}
/**
* @return \DateTime
*/
public function getUntil()
{
return $this->until;
}
/**
* @param \DateTime|string $until
*/
public function setUntil($until = null)
{
$this->until = $this->parseDateTime($until);
2015-02-05 16:00:30 -06:00
}
2015-02-06 11:31:13 -06:00
/**
* @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 (!$this->tags) {
$this->tags = [$tag];
}
2015-02-06 11:31:13 -06:00
if (!in_array($tag, $this->tags)) {
$this->tags[] = $tag;
}
}
/**
* @param string $tag
*/
public function removeTag($tag)
{
if (!$this->tags) {
return;
}
2015-02-06 11:31:13 -06:00
if (false !== $key = array_search($tag, $this->tags)) {
unset($this->tags[$key]);
}
}
2015-02-05 16:00:30 -06:00
/**
2015-02-05 17:09:29 -06:00
* @return \DateTime
2015-02-05 16:00:30 -06:00
*/
2015-02-05 17:09:29 -06:00
public function getEntry()
2015-02-05 16:00:30 -06:00
{
2015-02-05 17:09:29 -06:00
return $this->entry;
}
2015-02-06 17:22:17 -06:00
/**
* @return \DateTime
*/
public function getModified()
{
return $this->modified;
}
/**
* @return \DateTime
*/
public function getEnd()
{
return $this->end;
}
2015-02-05 17:09:29 -06:00
/**
* @return float
*/
public function getUrgency()
{
return $this->urgency;
}
/**
* @return string
*/
public function getStatus()
{
return $this->status;
2015-02-05 16:00:30 -06:00
}
/**
* @return bool
*/
public function isPending()
{
return $this->status == self::STATUS_PENDING;
}
/**
* @return bool
*/
public function isCompleted()
{
return $this->status == self::STATUS_COMPLETED;
}
/**
* @return bool
*/
public function isWaiting()
{
return $this->status == self::STATUS_WAITING;
}
/**
* @return bool
*/
public function isDeleted()
{
return $this->status == self::STATUS_DELETED;
}
2015-02-06 12:01:04 -06:00
2015-02-06 17:22:17 -06:00
/**
* @param string|\DateTime|null $date
* @return \DateTime|null
* @throws TaskwarriorException
*/
private function parseDateTime($date)
{
if ($date instanceof \DateTime) {
$date = clone $date;
$date->setTimezone(new \DateTimeZone('UTC'));
return $date;
}
if (is_string($date)) {
return new \DateTime($date, new \DateTimeZone('UTC'));
}
if ($date === null) {
return null;
}
throw new TaskwarriorException();
}
2015-02-06 12:01:04 -06:00
/**
*
*/
public function __clone()
{
$this->uuid = null;
$this->entry = new \DateTime('now', new \DateTimeZone('UTC'));
$this->status = self::STATUS_PENDING;
}
2015-02-05 13:41:03 -06:00
}