recurs() public method

Returns whether this task is a recurring task.
public recurs ( ) : boolean
return boolean True if this is a recurring task.
Exemplo n.º 1
0
 /**
  * Retrieves tasks from the Kolab server.
  *
  * @param integer $completed  Which tasks to retrieve (1 = all tasks,
  *                            0 = incomplete tasks, 2 = complete tasks).
  */
 public function retrieve($completed = Nag::VIEW_ALL)
 {
     $dict = array();
     $this->tasks = new Nag_Task();
     $task_list = $this->_getData()->getObjects();
     if (empty($task_list)) {
         return;
     }
     foreach ($task_list as $task) {
         $tid = Horde_Url::uriB64Encode($task['uid']);
         $nag_task = $this->_buildTask($task);
         $nag_task['tasklist_id'] = $this->_tasklist;
         $t = new Nag_Task($this, $nag_task);
         $complete = $t->completed;
         if (empty($t->start)) {
             $start = null;
         } else {
             $start = $t->start;
         }
         switch ($completed) {
             case Nag::VIEW_INCOMPLETE:
                 if ($complete) {
                     continue;
                 }
                 if ($start && $t->recurs() && ($completions = $t->recurrence->getCompletions())) {
                     sort($completions);
                     list($year, $month, $mday) = sscanf(end($completions), '%04d%02d%02d');
                     $lastCompletion = new Horde_Date($year, $month, $mday);
                     $recurrence = clone $t->recurrence;
                     $recurrence->start = new Horde_Date($start);
                     $start = $recurrence->nextRecurrence($lastCompletion)->timestamp();
                     if ($start > $_SERVER['REQUEST_TIME']) {
                         continue;
                     }
                 }
                 break;
             case Nag::VIEW_COMPLETE:
                 if (!$complete) {
                     continue;
                 }
                 break;
             case Nag::VIEW_FUTURE:
                 if ($complete || $start == 0) {
                     continue;
                 }
                 if ($start && $t->recurs() && ($completions = $t->recurrence->getCompletions())) {
                     sort($completions);
                     list($year, $month, $mday) = sscanf(end($completions), '%04d%02d%02d');
                     $lastCompletion = new Horde_Date($year, $month, $mday);
                     $recurrence = clone $t->recurrence;
                     $recurrence->start = new Horde_Date($start);
                     $start = $recurrence->nextRecurrence($lastCompletion)->timestamp();
                     if ($start < $_SERVER['REQUEST_TIME']) {
                         continue;
                     }
                 }
                 break;
             case Nag::VIEW_FUTURE_INCOMPLETE:
                 if ($complete) {
                     continue;
                 }
                 break;
         }
         if (empty($t->parent_id)) {
             $this->tasks->add($t);
         } else {
             $dict[$tid] = $t;
         }
     }
     /* Build a tree from the subtasks. */
     foreach (array_keys($dict) as $key) {
         $task = $this->tasks->get($dict[$key]->parent_id);
         if ($task) {
             $task->add($dict[$key]);
         } elseif (isset($dict[$dict[$key]->parent_id])) {
             $dict[$dict[$key]->parent_id]->add($dict[$key]);
         } else {
             $this->tasks->add($dict[$key]);
         }
     }
 }
Exemplo n.º 2
0
Arquivo: Sql.php Projeto: horde/horde
 /**
  * Retrieves tasks from the database.
  *
  * @param integer $completed  Which tasks to retrieve (1 = all tasks,
  *                            0 = incomplete tasks, 2 = complete tasks,
  *                            3 = future tasks, 4 = future and incomplete
  *                            tasks).
  * @param boolean $include_history  Include created/changed data from
  *                                  Horde_History.
  *
  * @throws Nag_Exception
  */
 public function retrieve($completed = Nag::VIEW_ALL, $include_history = true)
 {
     /* Build the SQL query. */
     $query = 'SELECT * FROM nag_tasks WHERE task_owner = ?';
     $values = array($this->_tasklist);
     switch ($completed) {
         case Nag::VIEW_INCOMPLETE:
             $query .= ' AND task_completed = 0 AND (task_start IS NULL OR task_completions IS NOT NULL OR task_start = 0 OR task_start < ?)';
             $values[] = $_SERVER['REQUEST_TIME'];
             break;
         case Nag::VIEW_COMPLETE:
             $query .= ' AND task_completed = 1';
             break;
         case Nag::VIEW_FUTURE:
             $query .= ' AND task_completed = 0 AND (task_completions IS NOT NULL OR task_start > ?)';
             $values[] = $_SERVER['REQUEST_TIME'];
             break;
         case Nag::VIEW_FUTURE_INCOMPLETE:
             $query .= ' AND task_completed = 0';
             break;
     }
     try {
         $result = $this->_db->select($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Nag_Exception($e->getMessage());
     }
     /* Store the retrieved values in a fresh task list. */
     $this->tasks = new Nag_Task();
     $dict = array();
     foreach ($result as $row) {
         $task = new Nag_Task($this, $this->_buildTask($row, $include_history));
         if (($completed == Nag::VIEW_INCOMPLETE || $completed == Nag::VIEW_FUTURE) && $task->start && $task->recurs()) {
             $start = $task->getNextStart();
             if ($completed == Nag::VIEW_INCOMPLETE && $start->after($_SERVER['REQUEST_TIME']) || $completed == Nag::VIEW_FUTURE && $start->before($_SERVER['REQUEST_TIME'])) {
                 continue;
             }
         }
         /* Add task directly if it is a root task, otherwise store it in
          * the dictionary. */
         if (empty($row['task_parent'])) {
             $this->tasks->add($task);
         } else {
             $dict[$row['task_id']] = $task;
         }
     }
     /* Build a tree from the subtasks. */
     foreach (array_keys($dict) as $key) {
         $task = $this->tasks->get($dict[$key]->parent_id);
         if ($task) {
             $task->add($dict[$key]);
         } elseif (isset($dict[$dict[$key]->parent_id])) {
             $dict[$dict[$key]->parent_id]->add($dict[$key]);
         } else {
             $this->tasks->add($dict[$key]);
         }
     }
 }