Ejemplo n.º 1
0
 /**
  * Save the resource IFF it has changed.
  * @see \Todoist\Todoist::getApiSingleCommandResponse
  * @return \Todoist\Resource\Resource
  */
 public function &save()
 {
     $source = json_encode($this->source);
     $data = json_encode($this->data);
     if ($source === $data) {
         return $this;
     }
     // Attempt to perform the simple update.
     // This throws an exception if it would return anything other than TRUE.
     $this->engine->getApiSingleCommandResponse($this->update_method, $this->data);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @param array $conf
  * @return \Todoist\Task\Tasks
  */
 public function applyParentTasks($conf)
 {
     $conf = array_merge(array('apply' => 'prepend', 'strip_colon' => '', 'delimiter' => ': ', 'strlen_max' => NULL), (array) $conf);
     // Get the unfiltered tasks.
     $all = $this->engine->getTasks();
     $project_tasks = array();
     // Build a new array of tasks.
     $tasks = array();
     foreach ($this->getArrayCopy() as $task) {
         if (isset($conf['strlen_max']) && $conf['strlen_max'] < strlen($task['content'])) {
             // Do nothing if the task is already long enough.
         } elseif ($task['indent'] > 1) {
             // Look for the previous item
             $prev_indent = $task['indent'] - 1;
             $prev_order = $task['item_order'] - 1;
             $prev_project = $task['project_id'];
             if (!isset($project_tasks[$prev_project])) {
                 $project_tasks[$prev_project] = $all->filterByProject($prev_project);
             }
             while ($prev_order > 0) {
                 foreach ($project_tasks[$prev_project] as $item) {
                     if ($item['item_order'] == $prev_order) {
                         if ($prev_indent == $item['indent']) {
                             $parent = $item['content'];
                             switch (strtolower($conf['strip_colon'])) {
                                 case 'pre':
                                     $parent = preg_replace('@^.*:@s', '', $parent);
                                     break;
                                 case 'post':
                                     $parent = preg_replace('@:.*$@s', '', $parent);
                                     break;
                             }
                             $parent = trim($parent);
                             switch (strtolower($conf['apply'])) {
                                 case 'append':
                                     $task['content'] .= $conf['delimiter'] . $parent;
                                     break;
                                 case 'prepend':
                                     $task['content'] = $parent . $conf['delimiter'] . $task['content'];
                                     break;
                             }
                             break 2;
                         } else {
                             break;
                         }
                     }
                 }
                 $prev_order--;
             }
         }
         $tasks[] = $task;
     }
     return $this->factorySub($tasks);
 }
Ejemplo n.º 3
0
 public function getProject($id)
 {
     return $this->engine->getProject($id);
 }
Ejemplo n.º 4
0
 /**
  * Factory method to create a Todoist API object.
  * @param string $token
  * @return \Todoist\Todoist
  */
 public static function factory($token)
 {
     $ret = new Todoist();
     return $ret->setToken($token);
 }