Nag: Add View/sort-by for Start Date
authorJoel Smith <js-horde@jk1.net>
Tue, 8 Jun 2010 18:28:36 +0000 (12:28 -0600)
committerJan Schneider <jan@horde.org>
Wed, 9 Jun 2010 09:31:37 +0000 (11:31 +0200)
Signed-off-by: Jan Schneider <jan@horde.org>
nag/config/prefs.php.dist
nag/lib/Nag.php
nag/lib/Task.php
nag/templates/list/task_headers.inc
nag/templates/list/task_summaries.inc

index b4362f8..341fc8d 100644 (file)
@@ -56,6 +56,7 @@ $_prefs['tasklist_columns'] = array(
         'priority' => _("Priority"),
         'assignee' => _("Assignee"),
         'due' => _("Due Date"),
+        'start' => _("Due Date"),
         'estimate' => _("Estimated Time"),
         'category' => _("Category")
     ),
@@ -77,6 +78,7 @@ $_prefs['sortby'] = array(
         Nag::SORT_NAME => _("Task Name"),
         Nag::SORT_CATEGORY => _("Category"),
         Nag::SORT_DUE => _("Due Date"),
+        Nag::SORT_START => _("Start Date"),
         Nag::SORT_COMPLETION => _("Completed?"),
         Nag::SORT_ESTIMATE => _("Estimated Time"),
         Nag::SORT_ASSIGNEE => _("Assignee"),
@@ -94,6 +96,7 @@ $_prefs['altsortby'] = array(
         Nag::SORT_NAME => _("Task Name"),
         Nag::SORT_CATEGORY => _("Category"),
         Nag::SORT_DUE => _("Due Date"),
+        Nag::SORT_START => _("Start Date"),
         Nag::SORT_COMPLETION => _("Completed?"),
         Nag::SORT_ESTIMATE => _("Estimated Time"),
         Nag::SORT_ASSIGNEE => _("Assignee"),
index 463b4cd..3c72678 100644 (file)
@@ -28,6 +28,11 @@ class Nag
     const SORT_DUE = 'due';
 
     /**
+     * Sort by start date.
+     */
+    const SORT_START = 'start';
+
+    /**
      * Sort by completion.
      */
     const SORT_COMPLETION = 'completed';
@@ -1336,6 +1341,58 @@ class Nag
     }
 
     /**
+     * Comparison function for sorting tasks by start date.
+     *
+     * @param array $a  Task one.
+     * @param array $b  Task two.
+     *
+     * @return integer  1 if task one is greater, -1 if task two is greater;
+     *                  0 if they are equal.
+     */
+    public static function _sortByStart($a, $b)
+    {
+        if ($a->start == $b->start) {
+            return self::_sortByIdentity($a, $b);
+        }
+
+        // Treat empty start dates as farthest into the future.
+        if ($a->start == 0) {
+            return 1;
+        }
+        if ($b->start == 0) {
+            return -1;
+        }
+
+        return ($a->start > $b->start) ? 1 : -1;
+    }
+
+    /**
+     * Comparison function for reverse sorting tasks by start date.
+     *
+     * @param array $a  Task one.
+     * @param array $b  Task two.
+     *
+     * @return integer  -1 if task one is greater, 1 if task two is greater,
+     *                  0 if they are equal.
+     */
+    public static function _rsortByStart($a, $b)
+    {
+        if ($a->start == $b->start) {
+            return self::_sortByIdentity($b, $a);
+        }
+
+        // Treat empty start dates as farthest into the future.
+        if ($a->start == 0) {
+            return -1;
+        }
+        if ($b->start == 0) {
+            return 1;
+        }
+
+        return ($a->start < $b->start) ? 1 : -1;
+    }
+
+    /**
      * Comparison function for sorting tasks by completion status.
      *
      * @param array $a  Task one.
index 66402be..2a6a9a8 100644 (file)
@@ -580,6 +580,7 @@ class Nag_Task {
             Nag::SORT_NAME => 'ByName',
             Nag::SORT_CATEGORY => 'ByCategory',
             Nag::SORT_DUE => 'ByDue',
+            Nag::SORT_START => 'ByStart',
             Nag::SORT_COMPLETION => 'ByCompletion',
             Nag::SORT_ASSIGNEE => 'ByAssignee',
             Nag::SORT_ESTIMATE => 'ByEstimate',
index 93c440f..51c7fa8 100644 (file)
@@ -51,6 +51,10 @@ function doPrefsUpdate(column, sortDown)
   <th id="s<?php echo Nag::SORT_DUE ?>"<?php if ($sortby == Nag::SORT_DUE) echo ' class="' . $sortdirclass . '"' ?> width="2%">
    <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($baseurl, 'sortby', Nag::SORT_DUE)), _("Sort by Due Date"), 'sortlink', '', '', _("_Due Date")) ?>&nbsp;
   </th>
+<?php endif; if (in_array('start', $columns)): ?>
+  <th id="s<?php echo Nag::SORT_START ?>"<?php if ($sortby == Nag::SORT_START) echo ' class="' . $sortdirclass . '"' ?> width="2%">
+   <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($baseurl, 'sortby', Nag::SORT_START)), _("Sort by Start Date"), 'sortlink', '', '', _("_Start Date")) ?>&nbsp;
+  </th>
 <?php endif; if (in_array('estimate', $columns)): ?>
   <th id="s<?php echo Nag::SORT_ESTIMATE ?>"<?php if ($sortby == Nag::SORT_ESTIMATE) echo ' class="' . $sortdirclass . '"' ?> width="10%">
    <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($baseurl, 'sortby', Nag::SORT_ESTIMATE)), _("Sort by estimated time"), 'sortlink', '', '', _("Estimated Time")) ?>&nbsp;
index 95fa818..f3fdc8c 100644 (file)
@@ -61,6 +61,10 @@ if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
   <td class="nowrap" sortval="<?php echo $task->due ? (int)$task->due : PHP_INT_MAX ?>">
     <?php echo $task->due ? strftime($dateFormat, $task->due) : '&nbsp;' ?>
   </td>
+<?php endif; if (in_array('start', $columns)): ?>
+  <td class="nowrap" sortval="<?php echo $task->start ? (int)$task->start : PHP_INT_MAX ?>">
+    <?php echo $task->start ? strftime($dateFormat, $task->start) : '&nbsp;' ?>
+  </td>
 <?php endif; if (in_array('estimate', $columns)): ?>
   <td class="nowrap" sortval="<?php echo htmlspecialchars($task->estimation()) ?>">
    <?php echo htmlspecialchars($task->estimation()) ?>