/**
  * 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;
 }
 /**
  * Get the task # of a list, either from the argument or prompt the user.
  * Keep in mind the # present to the user always begins with 1, but the
  * number we return is always one less (starting with 0)
  *
  * @param ListInterface $list The Todo List
  * @param bool $showNext Show next actions in prompt list
  * @param bool $showNormal Show normal tasks in prompt list
  * @param bool $showComplete Show completed tasks in prompt list
  * @return mixed NULL if user aborts, otherwise integer of task number
  */
 protected function getTaskNo(\GSD\Entities\ListInterface $list, $showNext, $showNormal, $showComplete)
 {
     // Return the # if provided on command line
     $taskNo = $this->argument('task-number');
     if (!is_null($taskNo)) {
         return (int) $taskNo - 1;
     }
     // Build list of tasks
     $tasks = array();
     foreach ($list->tasks() as $task) {
         if ($task->isComplete()) {
             if ($showComplete) {
                 $tasks[] = (string) $task;
             }
         } elseif ($task->isNextAction()) {
             if ($showNext) {
                 $tasks[] = (string) $task;
             }
         } elseif ($showNormal) {
             $tasks[] = (string) $task;
         }
     }
     // Let user pick from list, return result
     $selectTitle = rtrim($this->taskNoDescription, '.') . ':';
     $result = pick_from_list($this, $selectTitle, $tasks, 0, "Cancel");
     if ($result == -1) {
         return null;
     }
     return $result - 1;
 }
 /**
  * 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;
 }