Logo Search packages:      
Sourcecode: nag2 version File versions  Download package

Nag::listTasks ( sortby = null,
sortdir = null,
altsortby = null 
)

Retrieves the current user's task list from storage. This function will also sort the resulting list, if requested.

Parameters:
Nag_Driver$storageThe current storage object.
constant$sortbyThe field by which to sort (NAG_SORT_PRIORITY, NAG_SORT_NAME NAG_SORT_DUE, NAG_SORT_COMPLETION).
constant$sortdirThe direction by which to sort (NAG_SORT_ASC, NAG_SORT_DESC).
constant$altsortbyThe secondary sort field.
Returns:
array A list of the requested tasks.
See also:
Nag_Driver::listTasks()

Definition at line 80 of file Nag.php.

References Nag_Driver::singleton().

    {
        global $prefs, $registry;

        if (is_null($sortby)) {
            $sortby = $prefs->getValue('sortby');
        }
        if (is_null($sortdir)) {
            $sortdir = $prefs->getValue('sortdir');
        }
        if (is_null($altsortby)) {
            $altsortby = $prefs->getValue('altsortby');
        }

        /* Sorting criteria for the task list. */
        $sort_functions = array(
            NAG_SORT_PRIORITY => 'ByPriority',
            NAG_SORT_NAME => 'ByName',
            NAG_SORT_CATEGORY => 'ByCategory',
            NAG_SORT_DUE => 'ByDue',
            NAG_SORT_COMPLETION => 'ByCompletion',
            NAG_SORT_OWNER => 'ByOwner'
        );

        $tasks = array();
        foreach ($GLOBALS['display_tasklists'] as $tasklist) {
            /* Create a Nag storage instance. */
            $storage = &Nag_Driver::singleton($tasklist);
            $storage->retrieve();

            /* Retrieve the tasklist from storage. */
            $newtasks = $storage->listTasks();
            if (is_a($newtasks, 'PEAR_Error')) {
                return $newtasks;
            }

            foreach ($newtasks as $taskID => $task) {
                $url = Util::addParameter('view.php',
                                          array('task' => $task['task_id'],
                                                'tasklist' => $task['tasklist_id']));
                $newtasks[$taskID]['view_link'] = Horde::applicationUrl($url);

                $url = Util::addParameter('task.php',
                                          array('task' => $task['task_id'],
                                                'tasklist' => $task['tasklist_id']));
                $url = Horde::applicationUrl($url);
                $newtasks[$taskID]['complete_link'] = Util::addParameter($url, 'actionID', 'complete_task');
                $newtasks[$taskID]['edit_link'] = Util::addParameter($url, 'actionID', 'modify_task');
                $newtasks[$taskID]['delete_link'] = Util::addParameter($url, 'actionID', 'delete_tasks');
            }

            $tasks = array_merge($tasks, $newtasks);
        }

        /* We look for registered apis that support listAs(taskHash). */
        $apps = @unserialize($prefs->getValue('show_external'));
        if (is_array($apps)) {
            foreach ($apps as $app) {
                if ($app != 'nag' &&
                    $registry->hasMethod('getListTypes', $app)) {
                    $types = $registry->callByPackage($app, 'getListTypes');
                    if (!empty($types['taskHash'])) {
                        $newtasks = $registry->callByPackage($app, 'listAs', array('taskHash'));
                        if (is_a($newtasks, 'PEAR_Error')) {
                            Horde::logMessage($newtasks, __FILE__, __LINE__, PEAR_LOG_ERR);
                        } else {
                            $tasks = array_merge($tasks, $newtasks);
                        }
                    }
                }
            }
        }

        /* Filter complete/incomplete tasks if the user doesn't want them
         * shown. */
        switch ($prefs->getValue('show_completed')) {
        case 0:
            foreach ($tasks as $taskID => $task) {
                if (!empty($task['completed'])) {
                    unset($tasks[$taskID]);
                }
            }
            break;

        case 2:
            foreach ($tasks as $taskID => $task) {
                if (empty($task['completed'])) {
                    unset($tasks[$taskID]);
                }
            }
            break;
        }

        /* Sort the array if we have a sort function defined for this
         * field. */
        if (isset($sort_functions[$sortby])) {
            $prefix = ($sortdir == NAG_SORT_DESCEND) ? '_rsort' : '_sort';
            uasort($tasks, array('Nag', $prefix . $sort_functions[$sortby]));
            if (isset($sort_functions[$altsortby]) && $altsortby !== $sortby) {
                $task_buckets = array();
                foreach ($tasks as $id => $task) {
                    if (!isset($task_buckets[$task[$sortby]])) {
                        $task_buckets[$task[$sortby]] = array();
                    }
                    $task_buckets[$task[$sortby]][] = $task;
                }
                $tasks = array();
                foreach ($task_buckets as $task_bucket) {
                    uasort($task_bucket, array('Nag', $prefix . $sort_functions[$altsortby]));
                    $tasks = array_merge($tasks, $task_bucket);
                }
            }
        }

        return $tasks;
    }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index