Nag_Task::hasTask PHP Method

hasTask() public method

Return the task, if present anywhere in this tasklist, regardless of child depth.
public hasTask ( string $taskId ) : Nag_Task | false
$taskId string The task id we are looking for.
return Nag_Task | false The task object, if found. Otherwise false.
    public function hasTask($taskId)
    {
        $this->reset();
        while ($task = $this->each()) {
            if ($task->id == $taskId) {
                return $task;
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Perform the search
  *
  * @param integer $page     The page number
  * @param integer $perpage  The number of results per page.
  *
  * @return Nag_Task
  */
 protected function _search($page, $perpage)
 {
     global $injector, $prefs;
     if (!empty($this->_due)) {
         $parser = Horde_Date_Parser::factory(array('locale' => $GLOBALS['prefs']->getValue('language')));
         $date = $parser->parse($this->_due[1]);
         $date->mday += $this->_due[0];
         $date = $date->timestamp();
     } else {
         $date = false;
     }
     // Get the full, sorted task list.
     $tasks = Nag::listTasks(array('tasklists' => $this->_tasklists, 'completed' => $this->_completed, 'include_history' => false));
     if (!empty($this->_search)) {
         $pattern = '/' . preg_quote($this->_search, '/') . '/i';
     }
     $search_results = new Nag_Task();
     if (!empty($this->_tags)) {
         $tagged_tasks = $injector->getInstance('Nag_Tagger')->search($this->_tags, array('list' => $GLOBALS['display_tasklists']));
     }
     $tasks->reset();
     while ($task = $tasks->each()) {
         // Need to empty the children since they might not be in the results
         $task = clone $task;
         $task->orphan();
         if (!empty($date)) {
             if (empty($task->due) || $task->due > $date) {
                 continue;
             }
         }
         // If we have a search string and it doesn't match name|desc continue
         if (!empty($this->_search) && !($this->_mask & self::MASK_NAME && preg_match($pattern, $task->name)) && !($this->_mask & self::MASK_DESC && preg_match($pattern, $task->desc))) {
             continue;
         }
         // No tags to search? Add it to results. Otherwise, make sure it
         // has the requested tags.
         if (empty($this->_tags) || in_array($task->uid, $tagged_tasks)) {
             $search_results->add($task);
         }
     }
     // Now try to maintain parent/child relationships when they are both
     // in the result set.
     $search_results->reset();
     $search_results_copy = clone $search_results;
     $processed_results = new Nag_Task();
     while ($result = $search_results_copy->each()) {
         if ($result->parent_id && ($parent_task = $search_results->hasTask($result->parent_id))) {
             $parent_task->add($result, true);
             $processed_results->add($parent_task, true);
         } else {
             $result->parent_id = '';
             $processed_results->add($result);
         }
     }
     // Now that we have filtered results, load all tags at once.
     $processed_results->loadTags();
     $processed_results->process();
     return $processed_results;
 }