85 lines
1.7 KiB
PHP
85 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Aerex\TaskwarriorPlugin\Taskwarrior;
|
|
|
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Taskwarrior;
|
|
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
|
|
use Sabre\VObject\Component\VTodo;
|
|
|
|
class TaskwarriorManager {
|
|
|
|
|
|
/**
|
|
* @var TodoStrategy
|
|
*/
|
|
private $todoStrategy;
|
|
|
|
public function __construct($taskwarrior){
|
|
if(!isset($taskwarrior)){
|
|
$this->taskwarrior = new Taskwarrior();
|
|
} else {
|
|
$this->taskwarrior = $taskwarrior;
|
|
}
|
|
// Initialize strategies
|
|
$this->todoStrategy = new TodoStrategy($this->taskwarrior->getConfig());
|
|
}
|
|
|
|
|
|
public function addTask(VTodo $document){
|
|
$this->taskwarrior->setStrategy($this->todoStrategy);
|
|
|
|
$task = $this->taskwarrior->createTask((string)$document->UID);
|
|
|
|
$task->setDescription($document);
|
|
|
|
$task->setEntryTime($document);
|
|
|
|
$task->setDue($document);
|
|
|
|
$task->setCategories($document);
|
|
|
|
$task->setStatus($document);
|
|
|
|
$task->setRecurrence($document);
|
|
|
|
return $this->taskwarrior->add($task);
|
|
|
|
}
|
|
|
|
public function updateTask(VTodo $document){
|
|
|
|
$task = $this->taskwarrior->get($document->UID);
|
|
|
|
$task->setDescription($document);
|
|
|
|
$task->setEntry($document);
|
|
|
|
$task->setStartTime($document);
|
|
|
|
$task->setModifiedTime($document);
|
|
|
|
$task->setStopTime($document);
|
|
|
|
$task->setDue($document);
|
|
|
|
$task->setCategories($document);
|
|
|
|
$task->setStatus($document);
|
|
|
|
$task->setRecurrence($document);
|
|
|
|
$updatedTask = $this->taskwarrior->modify($task);
|
|
|
|
return $upatedTask;
|
|
}
|
|
|
|
public function taskExists($taskUuid){
|
|
$this->taskwarrior->setStrategy($this->$todoStrategy);
|
|
return $this->taskwarrior->count((string)$taskUuid);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|