twCalManager = new CalendarProcessor(new TaskwarriorManager($taskwarrior)); } else { $this->twCalManager = new CalendarProcessor(new TaskwarriorManager()); } } /** * Sets up the plugin * * @param Server $server * @return void */ function initialize(Server $server) { $this->server = $server; $server->on('calendarObjectChange', [$this, 'calendarObjectChange']); } /** * Returns a plugin name. * * Using this name other plugins will be able to access other plugins * using DAV\Server::getPlugin * * @return string */ function getPluginName() { return 'taskwarrior'; } /** * This method will parse a calendar object and create an new task in taskwarrior * * @param VCalendar $vCal parsed calendar object */ function processCalendarEventForTaskwarrior(Document $vCal){ try { if(isset($vCal->VTODO)){ $response = $this->twCalManager->importTask($vCal->VTODO); } } catch(BadRequest $e){ throw new BadRequest($e->getMessage(), null, $e); } catch(Exception $e){ throw new Exception($e->getMessage(), null, $e); } return $response; } /** * * This method is triggered whenever there was a calendar object gets * * created or updated. * * * * @param RequestInterface $request HTTP request * * @param ResponseInterface $response HTTP Response * * @param VCalendar $vCal Parsed iCalendar object * * @param mixed $calendarPath Path to calendar collection * * @param mixed $modified The iCalendar object has been touched. * * @param mixed $isNew Whether this was a new item or we're updating one * * @return void * */ function calendarObjectChange(RequestInterface $request, ResponseInterface $response, Document $vCal, $calendarPath, &$modified, $isNew) { $calendarNode = $this->server->tree->getNodeForPath($calendarPath); $body = ''; if ($isNew) { try { $body = $this->processCalendarEventForTaskwarrior($vCal); } catch(Exception\BadRequest $e){ $response->setHeader('X-Sabre-Real-Status', $e->getHTTPCode()); } } $response->setStatus(200); $response->setBody(''); $response->setHeader('Content-Type', 'text/plain'); return true; } /** * Returns a bunch of meta-data about the plugin. * * Providing this information is optional, and is mainly displayed by the * Browser plugin. * * The description key in the returned array may contain html and will not * be sanitized. * * @return array */ function getPluginInfo() { return [ 'name' => $this->getPluginName(), 'description' => 'The Core plugin provides syncronization between tasks and iCAL events', 'link' => null, ]; } }