mergeChildren() public method

Merges an array of tasks into this task's children.
public mergeChildren ( array $children )
$children array A list of Nag_Tasks.
Example #1
0
 /**
  * Retrieves the current user's task list from storage.
  *
  * This function will also sort the resulting list, if requested.
  *
  * @param arary $options  Options array:
  *   - altsortby: (string) The secondary sort field. Same values as sortdir.
  *                DEFAULT: altsortby pref is used.
  *   - completed: (integer) Which task to retrieve. A Nag::VIEW_* constant.
  *                DEFAULT: show_completed pref is used.
  *   - external: (boolean) Whether to include tasks from other applications
  *               too.
  *               DEFAULT: true.
  *   - include_history: (boolean) Autoload created/modified data from
  *                      Horde_History.
  *                      DEFAULT: true (Automatically load history data).
  *   - include_tags: (boolean) Autoload all tags.
  *                   DEFAULT: false (Tags are lazy loaded as needed.)
  *   - sortby: (string)  A Nag::SORT_* constant for the field to sort by.
  *             DEFAULT: sortby pref is used.
  *   - sortdir: (string) Direction of sort. NAG::SORT_ASCEND or
  *              NAG::SORT_DESCEND.
  *              DEFAULT: sortdir pref is used.
  *   - tasklists: (array) An array of tasklists to include.
  *                DEFAULT: Use $GLOBALS['display_tasklists'];
  *
  * @return Nag_Task  A list of the requested tasks.
  */
 public static function listTasks(array $options = array())
 {
     global $prefs, $registry;
     // Prevent null tasklists value from obscuring the default value.
     if (array_key_exists('tasklists', $options) && empty($options['tasklists'])) {
         unset($options['tasklists']);
     }
     $options = array_merge(array('sortby' => $prefs->getValue('sortby'), 'sortdir' => $prefs->getValue('sortdir'), 'altsortby' => $prefs->getValue('altsortby'), 'tasklists' => $GLOBALS['display_tasklists'], 'completed' => $prefs->getValue('show_completed'), 'include_tags' => false, 'external' => true, 'include_history' => true), $options);
     if (!is_array($options['tasklists'])) {
         $options['tasklists'] = array($options['tasklists']);
     }
     $tasks = new Nag_Task();
     foreach ($options['tasklists'] as $tasklist) {
         $storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($tasklist);
         // Retrieve the tasklist from storage.
         $storage->retrieve($options['completed'], $options['include_history']);
         $tasks->mergeChildren($storage->tasks->children);
     }
     // Process all tasks.
     $tasks->process();
     if ($options['external'] && ($apps = @unserialize($prefs->getValue('show_external'))) && is_array($apps)) {
         foreach ($apps as $app) {
             // We look for registered apis that support listAs(taskHash).
             if ($app == 'nag' || !$registry->hasMethod('getListTypes', $app)) {
                 continue;
             }
             try {
                 $types = $registry->callByPackage($app, 'getListTypes');
             } catch (Horde_Exception $e) {
                 continue;
             }
             if (empty($types['taskHash'])) {
                 continue;
             }
             try {
                 $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
                 foreach ($newtasks as $task) {
                     if (!isset($task['priority'])) {
                         $task['priority'] = 3;
                     }
                     $task['tasklist_id'] = '**EXTERNAL**';
                     $task['tasklist_name'] = $registry->get('name', $app);
                     $task = new Nag_Task(null, $task);
                     if ($options['completed'] == Nag::VIEW_INCOMPLETE && ($task->completed || $task->start > $_SERVER['REQUEST_TIME']) || $options['completed'] == Nag::VIEW_COMPLETE && !$task->completed || $options['completed'] == Nag::VIEW_FUTURE && ($task->completed || !$task->start || $task->start < $_SERVER['REQUEST_TIME']) || $options['completed'] == Nag::VIEW_FUTURE_INCOMPLETE && $task->completed) {
                         continue;
                     }
                     $tasks->add($task);
                 }
             } catch (Horde_Exception $e) {
                 Horde::log($e);
             }
         }
     }
     // Sort the array.
     $tasks->sort($options['sortby'], $options['sortdir'], $options['altsortby']);
     // Preload tags if requested.
     if ($options['include_tags']) {
         $tasks->loadTags();
     }
     return $tasks;
 }
Example #2
0
 /**
  * Retrieves sub-tasks from the database.
  *
  * @param string $parentId          The parent id for the sub-tasks to
  *                                  retrieve.
  * @param boolean $include_history  Include created/modified info? Not
  *                                  currently honored.
  *
  * @return array  List of sub-tasks.
  * @throws Nag_Exception
  */
 public function getChildren($parentId, $include_history = true)
 {
     $task_list = $this->_getData()->getObjects();
     if (empty($task_list)) {
         return array();
     }
     $tasks = array();
     foreach ($task_list as $task) {
         if (Horde_Url::uriB64Encode($task['parent']) != $parentId) {
             continue;
         }
         $t = new Nag_Task($this, $this->_buildTask($task));
         $children = $this->getChildren($t->id);
         $t->mergeChildren($children);
         $tasks[] = $t;
     }
     return $tasks;
 }
Example #3
0
 /**
  * Retrieves sub-tasks from the database.
  *
  * @param string $parentId          The parent id for the sub-tasks to
  *                                  retrieve.
  * @param boolean $include_history  Include created/modified info?
  *
  * @return array  List of sub-tasks.
  * @throws Nag_Exception
  */
 public function getChildren($parentId, $include_history = true)
 {
     // Build the SQL query.
     $query = sprintf('SELECT * FROM %s WHERE task_owner = ? AND task_parent = ?', $this->_params['table']);
     $values = array($this->_tasklist, $parentId);
     try {
         $result = $this->_db->selectAll($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Nag_Exception($e->getMessage());
     }
     // Store the retrieved values in a fresh task list.
     $tasks = array();
     foreach ($result as $row) {
         $task = new Nag_Task($this, $this->_buildTask($row, $include_history));
         $children = $this->getChildren($task->id);
         $task->mergeChildren($children);
         $tasks[] = $task;
     }
     return $tasks;
 }