From 181642ff3b9837a6b7607a6323c2cb16e8163554 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 5 Aug 2009 18:14:55 +0200 Subject: [PATCH] Use constants for the different views. Use strings in the nag api for the different views. --- kronolith/ajax.php | 4 ++-- kronolith/js/kronolith.js | 18 +++++++----------- nag/config/prefs.php.dist | 7 ++++--- nag/lib/Api.php | 27 +++++++++++++++++---------- nag/lib/Driver/Kolab.php | 18 +++++++++--------- nag/lib/Driver/Sql.php | 10 +++++----- nag/lib/Forms/task.php | 2 +- nag/lib/Nag.php | 25 +++++++++++++++++++++++++ nag/list.php | 8 ++++---- 9 files changed, 74 insertions(+), 45 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index 166bf8a2d..2b953b080 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -131,7 +131,7 @@ try { } $taskList = Horde_Util::getFormData('list'); - $taskType = (int)Horde_Util::getFormData('taskType'); + $taskType = Horde_Util::getFormData('taskType'); $tasks = $registry->call('tasks/listTasks', array(null, null, null, $taskList, $taskType, true)); if (is_a($tasks, 'PEAR_Error')) { @@ -339,7 +339,7 @@ try { break; } $taskList = Horde_Util::getFormData('taskList'); - $taskType = (int)Horde_Util::getFormData('taskType'); + $taskType = Horde_Util::getFormData('taskType'); $taskId = Horde_Util::getFormData('taskId'); $saved = $registry->call('tasks/toggleCompletion', array($taskId, $taskList)); diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 020158151..cde84e51d 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -26,7 +26,7 @@ KronolithCore = { eventsLoading: $H(), loading: 0, date: new Date(), - taskType: 1, //Default to all tasks view + taskType: 'all', doActionOpts: { onException: function(r, e) { KronolitCore.debug('onException', e); }, @@ -1280,11 +1280,9 @@ KronolithCore = { /** * Loads tasks, either from cache or from the server. * - * @param integer taskType The tasks type, (1 = all tasks, - * 0 = incomplete tasks, 2 = complete tasks, - * 3 = future tasks, 4 = future and incomplete - * tasks) - * @param Array tasksLists The lists from where to obtain the tasks + * @param integer taskType The tasks type (all, incomplete, complete, + * future or future_incomplete). + * @param Array tasksLists The lists from where to obtain the tasks. */ _loadTasks: function(taskType, taskLists) { @@ -1338,11 +1336,9 @@ KronolithCore = { /** * Reads tasks from the cache and inserts them into the view. * - * @param integer taskType The tasks type, (1 = all tasks, - * 0 = incomplete tasks, 2 = complete tasks, - * 3 = future tasks, 4 = future and incomplete - * tasks) - * @param string tasksList The task list to be drawn + * @param integer taskType The tasks type (all, incomplete, complete, + * future or future_incomplete). + * @param string tasksList The task list to be drawn. */ _insertTasks: function(taskType, taskList) { diff --git a/nag/config/prefs.php.dist b/nag/config/prefs.php.dist index 65968d4b0..9565566ff 100644 --- a/nag/config/prefs.php.dist +++ b/nag/config/prefs.php.dist @@ -203,9 +203,10 @@ $_prefs['show_completed'] = array( 'locked' => false, 'shared' => false, 'type' => 'enum', - 'enum' => array(1 => _("All tasks"), - 0 => _("Incomplete tasks"), - 2 => _("Complete tasks")), + 'enum' => array(Nag::VIEW_ALL => _("All tasks"), + Nag::VIEW_INCOMPLETE => _("Incomplete tasks"), + Nag::VIEW_COMPLETE => _("Complete tasks"), + Nag::VIEW_FUTURE => _("Future tasks")), 'desc' => _("Show complete, incomplete, or all tasks in the task list?"), ); diff --git a/nag/lib/Api.php b/nag/lib/Api.php index aaa5f1a2a..5788a75fb 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -90,7 +90,7 @@ class Nag_Api extends Horde_Registry_Api 'sortdir' => 'int', 'altsortby' => 'string', 'tasklists' => '{urn:horde}stringArray', - 'completed' => 'int', + 'completed' => 'string', 'json' => 'boolean' ), 'type' => '{urn:horde}stringArray', @@ -348,25 +348,30 @@ class Nag_Api extends Horde_Registry_Api * @param string $sortby The field by which to sort * (NAG_SORT_PRIORITY, NAG_SORT_NAME * NAG_SORT_DUE, NAG_SORT_COMPLETION). - * @param integer $sortdir The direction by which to sort + * @param integer $sortdir The direction by which to sort. * @param string $altsortby The secondary sort field. * @param array $tasklists An array of tasklist to display or * null/empty to display taskslists * $GLOBALS['display_tasklists']. - * @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 string $completed Which tasks to retrieve (all, incomplete, + * complete, future or future_incomplete). * @param boolean $json Retrieve the results of the tasks in - * 'json format' + * 'json format'. * * @return Nag_Task A list of the requested tasks. */ - public function listTasks($sortby = null, $sortdir = null, $altsortby = null, - $tasklists = null, $completed = null, $json = false) + public function listTasks($sortby = null, $sortdir = null, + $altsortby = null, $tasklists = null, + $completed = null, $json = false) { require_once dirname(__FILE__) . '/base.php'; + $completedArray = array('incomplete' => Nag::VIEW_INCOMPLETE, + 'all' => Nag::VIEW_ALL, + 'complete' => Nag::VIEW_COMPLETE, + 'future' => Nag::VIEW_FUTURE, + 'future_incomplete' => Nag::VIEW_FUTURE_INCOMPLETE); + if (!isset($sortby)) { $sortby = $GLOBALS['prefs']->getValue('sortby'); } @@ -379,8 +384,10 @@ class Nag_Api extends Horde_Registry_Api if (is_null($tasklists)) { $tasklists = $GLOBALS['display_tasklists']; } - if (is_null($completed)) { + if (is_null($completed) || !isset($completedArray[$completed]) { $completed = $GLOBALS['prefs']->getValue('show_completed'); + } else { + $completed = $completedArray[$completed]; } $tasks = Nag::listTasks($sortby, $sortdir, $altsortby, $tasklists); diff --git a/nag/lib/Driver/Kolab.php b/nag/lib/Driver/Kolab.php index c6d4ab4d5..e3f46ee8a 100644 --- a/nag/lib/Driver/Kolab.php +++ b/nag/lib/Driver/Kolab.php @@ -533,7 +533,7 @@ class Nag_Driver_kolab_wrapper_old extends Nag_Driver_kolab_wrapper { * * @return mixed True on success, PEAR_Error on failure. */ - function retrieve($completed = 1) + function retrieve($completed = Nag::VIEW_ALL) { $tasks = array(); @@ -553,11 +553,11 @@ class Nag_Driver_kolab_wrapper_old extends Nag_Driver_kolab_wrapper { } $complete = Kolab::percentageToBoolean($this->_kolab->getVal('completed')); $start_date = Kolab::decodeDateOrDateTime($this->_kolab->getVal('start-date')); - if (($completed == 0 && ($complete || $start_date > time())) || - ($completed == 2 && !$complete) || - ($completed == 3 && + if (($completed == Nag::VIEW_INCOMPLETE && ($complete || $start_date > time())) || + ($completed == Nag::VIEW_COMPLETE && !$complete) || + ($completed == Nag::VIEW_FUTURE && ($complete || $start_date == 0 || $start_date < time())) || - ($completed == 4 && $complete)) { + ($completed == Nag::VIEW_FUTURE_INCOMPLETE && $complete)) { continue; } $tasks[$this->_kolab->getUID()] = new Nag_Task($this->_buildTask()); @@ -969,11 +969,11 @@ class Nag_Driver_kolab_wrapper_new extends Nag_Driver_kolab_wrapper { $start = $t->start; } - if (($completed == 0 && ($complete || $start > time())) || - ($completed == 2 && !$complete) || - ($completed == 3 && + if (($completed == Nag::VIEW_INCOMPLETE && ($complete || $start > time())) || + ($completed == Nag::VIEW_COMPLETE && !$complete) || + ($completed == Nag::VIEW_FUTURE && ($complete || $start == 0 || $start < time())) || - ($completed == 4 && $complete)) { + ($completed == Nag::VIEW_FUTURE_INCOMPLETE && $complete)) { continue; } if (empty($t->parent_id)) { diff --git a/nag/lib/Driver/Sql.php b/nag/lib/Driver/Sql.php index 16003130a..f2ac012ea 100644 --- a/nag/lib/Driver/Sql.php +++ b/nag/lib/Driver/Sql.php @@ -375,25 +375,25 @@ class Nag_Driver_Sql extends Nag_Driver { * * @return mixed True on success, PEAR_Error on failure. */ - function retrieve($completed = 1) + function retrieve($completed = Nag::VIEW_ALL) { /* Build the SQL query. */ $query = sprintf('SELECT * FROM %s WHERE task_owner = ?', $this->_params['table']); $values = array($this->_tasklist); switch ($completed) { - case 0: + case Nag::VIEW_INCOMPLETE: $query .= ' AND task_completed = 0 AND (task_start IS NULL OR task_start = 0 OR task_start < ?)'; $values[] = time(); break; - case 2: + case Nag::VIEW_COMPLETE: $query .= ' AND task_completed = 1'; break; - case 3: + case Nag::VIEW_FUTURE: $query .= ' AND task_completed = 0 AND task_start > ?'; $values[] = time(); break; - case 4: + case Nag::VIEW_FUTURE_INCOMPLETE: $query .= ' AND task_completed = 0'; break; } diff --git a/nag/lib/Forms/task.php b/nag/lib/Forms/task.php index 32784d0c4..4719569c1 100644 --- a/nag/lib/Forms/task.php +++ b/nag/lib/Forms/task.php @@ -37,7 +37,7 @@ class Nag_TaskForm extends Horde_Form { reset($tasklists); $tasklist = key($tasklists); } - $tasks = Nag::listTasks(null, null, null, array($tasklist), 4); + $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE); $task_enums = array('' => _("No parent task")); $tasks->reset(); while ($task = $tasks->each()) { diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index fb3c76c70..d1052dd05 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -62,6 +62,31 @@ class Nag */ const SORT_DESCEND = 1; + /** + * Incomplete tasks + */ + const VIEW_INCOMPLETE = 0; + + /** + * All tasks + */ + const VIEW_ALL = 1; + + /** + * Complete tasks + */ + const VIEW_COMPLETE = 2; + + /** + * Future tasks + */ + const VIEW_FUTURE = 3; + + /** + * Future and incompleted tasks + */ + const VIEW_FUTURE_INCOMPLETE = 4; + public static function secondsToString($seconds) { $hours = floor($seconds / 3600); diff --git a/nag/list.php b/nag/list.php index 52c796f95..a9298614f 100644 --- a/nag/list.php +++ b/nag/list.php @@ -103,10 +103,10 @@ if ($print_view) { if (!$prefs->isLocked('show_completed')) { $listurl = Horde::applicationUrl('list.php'); $tabs = new Horde_UI_Tabs('show_completed', $vars); - $tabs->addTab(_("_All tasks"), $listurl, 1); - $tabs->addTab(_("Incom_plete tasks"), $listurl, 0); - $tabs->addTab(_("_Future tasks"), $listurl, 3); - $tabs->addTab(_("_Completed tasks"), $listurl, 2); + $tabs->addTab(_("_All tasks"), $listurl, Nag::VIEW_ALL); + $tabs->addTab(_("Incom_plete tasks"), $listurl, Nag::VIEW_INCOMPLETE); + $tabs->addTab(_("_Future tasks"), $listurl, Nag::VIEW_FUTURE); + $tabs->addTab(_("_Completed tasks"), $listurl, Nag::VIEW_COMPLETE); echo $tabs->render($vars->get('show_completed')); } } -- 2.11.0