console = $console; $this->configs = $configs['taskwarrior']; $this->logger = new Logger($configs, 'Taskwarrior'); } public function getConfig() { return $this->config; } public function refresh() { $output = $this->console->execute('task', ['sync'], null, ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); $this->logger->info($output); } public function vObjectToTask($vtodo) { if (isset($this->tasks[(string)$vtodo->UID])) { $task = $this->tasks[(string)$vtodo->UID]; } else { $task = []; $task['uid'] = (string)$vtodo->UID; } if (isset($vtodo->SUMMARY) && !isset($vtodo->DESCRIPTION)){ $task['description'] = (string)$vtodo->SUMMARY; } else if(isset($vtodo->DESCRIPTION)) { $task['description'] = (string)$vtodo->DESCRIPTION; } if (isset($vtodo->DTSTAMP)){ $task['entry'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C)); } if (isset($vtodo->DTSTART)) { $task['start'] = new Carbon($vtodo->DTSTART->getDateTime()->format(\DateTime::W3C)); } if (isset($vtodo->DTEND)){ $task['end'] = new Carbon($vtodo->DTEND->getDateTime()->format(\DateTime::W3C)); } if (isset($vtodo->{'LAST-MODIFIED'})) { $task['modified'] = new Carbon($vtodo->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C)); } if (isset($vtodo->PRIORITY)) { $priority = $vtodo->PRIORITY->getJsonValue(); if ($priority < 5) { $task['priority'] = 'H'; } else if ($priority === 5) { $task['priority'] = 'M'; } else if ($priority > 5 && $priority < 10) { $task['priority'] = 'L'; } } if (isset($vtodo->DUE)){ $task['due'] = new Carbon($vtodo->DUE->getDateTime()->format(\DateTime::W3C)); } if (isset($vtodo->RRULE)) { $rules = $vtodo->RRULE->getParts(); if (isset($rules['FREQ'])) { $task['recu'] = $rules['FREQ']; } if (isset($rules['UNTIL'])) { $task['until'] = $rules['UNTIL']; } } if (isset($vtodo->STATUS)) { switch((string)$vtodo->STATUS) { case 'NEEDS-ACTION': $task['status'] = 'pending'; break; case 'COMPLETED': $task['status'] = 'completed'; if (!isset($task['end'])) { $task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C)); } break; case 'CANCELED': $task['status'] = 'deleted'; if (!isset($task['end'])) { $task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C)); } break; } } if (isset($vtodo->CATEGORIES)) { $task['tags'] = []; foreach ($vtodo->CATEGORIES as $category) { if (isset($this->configs['project_tag_suffix'])) { $projTagSuffixRegExp = sprintf('/^%s_/', $this->configs['project_tag_suffix']); if (preg_match($category, $projTagSuffixRegExp)) { $task['project'] = preg_replace($projTagSuffixRegExp, '', $category); continue; } } $task['tags'] = $category; } } return $task; } public function save(Calendar $c) { if (!isset($c->VTODO)){ throw new \Exception('Calendar event does not contain VTODO'); $this->logger->error('Calendar event does not contain VTODO'); } $this->logger->info($c->VTODO->getJsonValue()); $this->refresh(); $task = $this->vObjectToTask($c->VTODO); $this->logger->info(json_encode($task)); $this->logger->info( sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], $task) ); $output = $this->console->execute('task', ['import'], $task, ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); $this->logger->info($output); } }