115 lines
2.2 KiB
PHP
115 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Aerex\TaskwarriorPlugin;
|
||
|
|
||
|
use Aerex\TaskwarriorPlugin\Config;
|
||
|
use Sabre\DAV\Exception;
|
||
|
use Sabre\VObject\Component\VEvent;
|
||
|
use Sabre\VObject\Component\VTodo;
|
||
|
|
||
|
|
||
|
class iCalEventProcessor {
|
||
|
|
||
|
/**
|
||
|
* @var Config
|
||
|
*/
|
||
|
private $config;
|
||
|
|
||
|
/**
|
||
|
* @var string
|
||
|
*
|
||
|
*/
|
||
|
private $taskrc;
|
||
|
|
||
|
/**
|
||
|
* @var string
|
||
|
*/
|
||
|
|
||
|
private $taskDataDir;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @var array
|
||
|
*/
|
||
|
private $cachedTasks = [];
|
||
|
|
||
|
/**
|
||
|
* @var string
|
||
|
*/
|
||
|
|
||
|
private $taskBinFile;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @var Taskwarrior
|
||
|
*/
|
||
|
|
||
|
private $taskwarrior;
|
||
|
|
||
|
|
||
|
public function __construct(Config $taskConfig = null){
|
||
|
if(!is_null($taskConfig)){
|
||
|
$this->taskConfig = $taskConfig;
|
||
|
} else {
|
||
|
$this->taskConfig = new Config();
|
||
|
}
|
||
|
|
||
|
$this->taskwarrior = $this->taskConfig->getTaskwarriorInstance();
|
||
|
$this->logger = $this->taskConfig->getLogger();
|
||
|
}
|
||
|
|
||
|
|
||
|
public function importTask(VTodo $ToDoComponent = null){
|
||
|
|
||
|
if(!isset($ToDoComponent)){
|
||
|
$this->logger->error("vCal ToDo component is not defined");
|
||
|
throw new Exception("vCal Todo component is not defined");
|
||
|
}
|
||
|
|
||
|
|
||
|
if($this->taskwarrior->exists($ToDoComponent->UID)){
|
||
|
$this->logger->error("Event already exists " . (string)$ToDoComponent->UID);
|
||
|
throw new Exception\BadRequest("Event already exists " . $ToDoComponent->UID);
|
||
|
}
|
||
|
|
||
|
|
||
|
try {
|
||
|
$this->taskwarrior->setUUID($ToDoComponent->UID);
|
||
|
$this->taskwarrior->setEntryTime($ToDoComponent->DSTAMP);
|
||
|
$this->taskwarrior->setDueDate($ToDoComponent->DUE);
|
||
|
$this->taskwarrior->setModifiedTime($ToDoComponent->{'LAST-MODIFIED'});
|
||
|
$this->taskwarrior->setStartTime($ToDoComponent->DSTART);
|
||
|
$this->taskwarrior->setEndTime($ToDoComponent->DTEND);
|
||
|
$this->taskwarrior->setSummary($ToDoComponent->DESCRIPTION);
|
||
|
$this->taskwarrior->setCategories($ToDoComponent->CATEGORIES);
|
||
|
$this->taskwarrior->setDescription($ToDoComponent->DESCRIPTION);
|
||
|
|
||
|
$this->taskwarrior->build();
|
||
|
|
||
|
$this->taskwarrior->save();
|
||
|
|
||
|
} catch(Exception $e){
|
||
|
$this->logger->error($e->message);
|
||
|
throw $e;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
?>
|