refactor: extract ical processor code into an interface type
This commit is contained in:
parent
84e96940ed
commit
2d2122e05d
@ -3,7 +3,7 @@
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
use DavidBadura\Taskwarrior\Taskwarrior;
|
||||
use Aerex\Taskwarrior\TaskwarriorManager;
|
||||
use Aerex\TaskwarriorPlugin\TaskwarriorManager;
|
||||
|
||||
class Config {
|
||||
|
||||
|
15
src/Processors/CalendarComponetInterface.php
Normal file
15
src/Processors/CalendarComponetInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
<?php
|
||||
|
||||
namespace ;
|
||||
|
||||
/**
|
||||
* Interface CalendarComponent
|
||||
* @author Aerex
|
||||
*/
|
||||
interface CalendarComponentInterface
|
||||
{
|
||||
public function import();
|
||||
public function export();
|
||||
?>
|
21
src/Processors/ToDo.php
Normal file
21
src/Processors/ToDo.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
|
||||
/**
|
||||
* Class iCalEvent
|
||||
*
|
||||
* @author yourname
|
||||
*/
|
||||
class ToDo implements CalendarComponentInterface
|
||||
{
|
||||
public
|
||||
|
||||
public function import(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
29
src/Task.php
Normal file
29
src/Task.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\TaskwarriorPlugin;
|
||||
use DavidBadura\Taskwarrior\Task as BasicTask;
|
||||
|
||||
/**
|
||||
* Task
|
||||
* @author Aerex
|
||||
*/
|
||||
class Task extends BasicTask {
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* If description is not available attempt to summary, otherwise throw Exception
|
||||
*/
|
||||
public function setDescription(VTodo $toDoComponent){
|
||||
|
||||
if(!isset($ToDoComponent->DESCRIPTION) && isset($ToDoComponent->SUMMARY)){
|
||||
$description = $summary;
|
||||
} else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){
|
||||
throw new Exception("Task must have a description or summary");
|
||||
}
|
||||
}
|
||||
|
||||
public
|
||||
|
||||
}
|
@ -61,6 +61,7 @@ class iCalEventProcessor {
|
||||
|
||||
public function importTask(VTodo $ToDoComponent = null){
|
||||
|
||||
echo $ToDoComponent->serialize();
|
||||
if(!isset($ToDoComponent)){
|
||||
$this->logger->error("vCal ToDo component is not defined");
|
||||
throw new Exception("vCal Todo component is not defined");
|
||||
@ -68,43 +69,71 @@ class iCalEventProcessor {
|
||||
|
||||
|
||||
if($this->taskwarrior->exists($ToDoComponent->UID)){
|
||||
$this->logger->error("Event already exists " . (string)$ToDoComponent->UID);
|
||||
$this->taskwarrior->updateTask($ToDoComponent);
|
||||
$this->logger->error("Updating task " . (string)$ToDoComponent->UID);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$task = $this->taskwarrior->createiCalTask($ToDoComponent->UID);
|
||||
|
||||
// get description
|
||||
if(!isset($ToDoComponent->DESCRIPTION) && isset($ToDoComponent->SUMMARY)){
|
||||
$description = $summary;
|
||||
} else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){
|
||||
throw new Exception("Task must have a description or summary");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
$start = $ToDoComponent->DSTART;
|
||||
$entry = $ToDoComponent->DSTAMP;
|
||||
$modified = $ToDoComponent->{'LAST-MODIFIED'};
|
||||
$end = $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
|
||||
// get start time
|
||||
if(!isset($ToDoComponent->DTSTAMP) && isset($ToDoComponent->DSTART)){
|
||||
$start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP);
|
||||
$entry = $start;
|
||||
} else if (!isset($ToDoComponent->DTSTAMP) && !isset($ToDoComponent->DSTART)){
|
||||
throw new Exception("Task must have an entry or start time");
|
||||
} else {
|
||||
$entry = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP);
|
||||
}
|
||||
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::ENTRY, $entry);
|
||||
|
||||
if(isset($ToDoComponent->DSTART)){
|
||||
$start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DSTART);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::START, $start);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->{'LAST-MODIFIED'})){
|
||||
$modified = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->{'LAST-MODIFIED'});
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DTEND)){
|
||||
$end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DUE)){
|
||||
$due = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DUE);
|
||||
$task->setDue($due);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->DTEND)){
|
||||
$end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND);
|
||||
$this->taskwarrior->setValue($task, $this->taskwarrior::END, $end);
|
||||
}
|
||||
|
||||
if(isset($ToDoComponent->CATEGORIES)){
|
||||
$tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES);
|
||||
$task->setTags($tags);
|
||||
}
|
||||
|
||||
$this->taskwarrior->save($task);
|
||||
|
||||
} catch(Exception $e){
|
||||
echo $e->getMessage();
|
||||
|
||||
$this->logger->error($e->message);
|
||||
throw $e;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user