/** * Save a TodoList * @param ListInterface $list The TODO List * @return boolean True if successful */ public function save(ListInterface $list) { $id = $list->get('id'); $archived = $list->get('archived'); $build = array(); $build[] = '# ' . $list->get('title'); $subtitle = $list->get('subtitle'); if ($subtitle) { $build[] = "({$subtitle})"; } $lastType = 'z'; $tasks = $list->tasks(); foreach ($tasks as $task) { $task = (string) $task; $type = $task[0]; if ($type != $lastType) { $build[] = ''; // Blank line between types of tasks $lastType = $type; } $build[] = $task; } $content = join("\n", $build); $filename = $this->fullpath($id, $archived); $result = File::put($filename, $content); return $result !== false; }
/** * Convert a TodoList to an associative array * @param ListInterface $list The List * @return array The associative array */ protected function toAssoc(ListInterface $list) { $return = array('list' => array('name' => $list->get('id'), 'title' => $list->get('title'), 'subtitle' => $list->get('subtitle'), 'archived' => $list->get('archived'), 'tasks' => array())); foreach ($list->tasks() as $task) { $array = array('isNext' => $task->isNextAction(), 'isCompleted' => $task->isComplete(), 'descript' => $task->description(), 'dateDue' => $task->dateDue(), 'dateCompleted' => $task->dateCompleted()); if ($array['dateDue']) { $array['dateDue'] = $array['dateDue']->timestamp * 1000; } if ($array['dateCompleted']) { $array['dateCompleted'] = $array['dateCompleted']->timestamp * 1000; } $return['list']['tasks'][] = $array; } return $return; }