refactor: leverage Task and TaskManager external api methods to create task
refactor: remove uneeded configuration
This commit is contained in:
@@ -2,61 +2,56 @@
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
|
||||
use DavidBadura\Taskwarrior\Taskwarrior;
|
||||
use Aerex\Taskwarrior\TaskwarriorManager;
|
||||
|
||||
class Config {
|
||||
|
||||
public function __construct(){
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $bin;
|
||||
|
||||
}
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $taskrc;
|
||||
|
||||
public function getTaskwarriorInstance(){
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $taskData;
|
||||
|
||||
if(!$this->isValidConfiguration()){
|
||||
$invalidConfigurationString = $this->invalidConfigurations();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $rcOptions;
|
||||
|
||||
$invalidConfigurationMessage = sprintf('The following configurations are invalid %s and' .
|
||||
' the default configurations will be used', $invalidConfigurationString);
|
||||
echo($invalidConfigurationMessage);
|
||||
|
||||
$this->setDefaults();
|
||||
public function __construct($taskrc='~/.taskrc', $taskData='~/.task',$rcOptions = [], $bin='task'){
|
||||
$this->taskrc = $taskrc;
|
||||
$this->bin = $bin;
|
||||
$this->taskDat = $taskData;
|
||||
$this->rcOptions = $rcOptions;
|
||||
|
||||
}
|
||||
|
||||
$this->taskrc = $this->getTaskRC();
|
||||
$this->taskDataDir = $this->getTaskDataDir();
|
||||
$this->taskBinFile = $this->getTaskBinFile();
|
||||
public function getTaskwarriorInstance(){
|
||||
|
||||
$this->taskwarrior = new $Taskwarrior($this->taskrc,$this->taskdatadir, [], $this->taskbinfile);
|
||||
}
|
||||
$this->taskwarrior = new Taskwarrior($this->taskrc,$this->taskdatadir, [], $this->taskbinfile);
|
||||
$this->taskwarriorManager = new TaskwarriorManager($this->taskwarrior);
|
||||
|
||||
return $this->taskwarriorManager;
|
||||
}
|
||||
|
||||
|
||||
public function getLogger(){
|
||||
return $this->logger;
|
||||
}
|
||||
public function setLogger($logger){
|
||||
$this->logger = $logger;
|
||||
public function getLogger(){
|
||||
return $this->logger;
|
||||
}
|
||||
public function setLogger($logger){
|
||||
$this->logger = $logger;
|
||||
|
||||
}
|
||||
public function isValidConfigurations(){
|
||||
|
||||
}
|
||||
|
||||
public function setDefaults(){
|
||||
|
||||
}
|
||||
|
||||
public function getTaskRC() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getTaskDataDir(){
|
||||
|
||||
}
|
||||
|
||||
public function getTaskBinFile(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
@@ -3,18 +3,43 @@
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
use Aerex\TaskwarriorPlugin\Taskwarrior;
|
||||
use DavidBadura\Taskwarrior\TaskManager;
|
||||
use DavidBadura\Taskwarrior\Task;
|
||||
|
||||
class Taskwarrior {
|
||||
class TaskwarriorManager extends TaskManager {
|
||||
|
||||
const DESCRIPTION = 'description';
|
||||
const CATEGORIES = 'categories';
|
||||
const TASK_UUID = 'uuid';
|
||||
const ICAL_UID = 'uid';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \DavidBadura\Taskwarrior\Task
|
||||
*/
|
||||
private $tasks;
|
||||
|
||||
function __constructor(TaskwarriorConfig $taskConfig){
|
||||
$this->taskConfig = $taskConfig;
|
||||
$this->taskWarriorJSON = array();
|
||||
const ENTRY = 'entry';
|
||||
const START = 'start';
|
||||
const MODIFIED = 'modified';
|
||||
const END = 'end';
|
||||
|
||||
public function __construct($taskwarrior){
|
||||
parent::__construct($taskwarrior);
|
||||
}
|
||||
|
||||
public function createTask($UUID){
|
||||
$task = new Task();
|
||||
$this->setValue($task, $ICAL_UID, $UUID);
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function export(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setEntryTime($entry){
|
||||
}
|
||||
|
||||
@@ -41,7 +66,10 @@ class Taskwarrior {
|
||||
|
||||
$this->taskWarriorJSON[self::CATEGORIES] = $categories;
|
||||
}
|
||||
private function taskExists($taskUuid){
|
||||
|
||||
|
||||
|
||||
public function taskExists($taskUuid){
|
||||
$taskIsInCache = isset($this->cachedTasks[$taskUuid]);
|
||||
|
||||
if($taskIsInCache){
|
||||
@@ -58,12 +86,26 @@ class Taskwarrior {
|
||||
public function save(){
|
||||
|
||||
}
|
||||
public function setUUID(){
|
||||
}
|
||||
public function build(){
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param Task $task
|
||||
* @param string $attr
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setValue(Task $task, $attr, $value)
|
||||
{
|
||||
$refClass = new \ReflectionClass(Task::class);
|
||||
$refProp = $refClass->getProperty($attr);
|
||||
$refProp->setAccessible(true);
|
||||
$refProp->setValue($task, $value);
|
||||
}
|
||||
|
||||
|
||||
function setDescription($description){}
|
||||
function parseiCalDateTime($iCalDateTime){}
|
||||
function convertToStringArray($categories){}
|
||||
function setDueDate($dueDate){}
|
||||
}
|
||||
|
@@ -69,24 +69,35 @@ class iCalEventProcessor {
|
||||
|
||||
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();
|
||||
// parse iCalendar event times to DateTime objects
|
||||
$entry = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTAMP);
|
||||
$start = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DSTART);
|
||||
$modified = $this->taskwarrior->parseiCalDateTime($ToDoComponent->{'LAST-MODIFIED'});
|
||||
$end = $this->taskwarrior->parseiCalDateTime($ToDoComponent->DTEND);
|
||||
|
||||
$task = $this->taskwarrior->createTask($ToDoComponent->UID);
|
||||
|
||||
$tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES);
|
||||
$task->setTags($tags);
|
||||
|
||||
$task->setDue($ToDoComponent->DUE->getDateTime());
|
||||
$task->setDescription($ToDoComponent->DESCRIPTION);
|
||||
|
||||
|
||||
// override protected taskwarrior properties using iCal event
|
||||
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::ENTRY, $entry);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::START, $start);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::END, $end);
|
||||
|
||||
$this->taskwarrior->save($task);
|
||||
|
||||
} catch(Exception $e){
|
||||
$this->logger->error($e->message);
|
||||
|
Reference in New Issue
Block a user