In Eventum, when sorting by Priority, it will actually _not_ sort by
the Priority rank, it will sort by the priority rank's id (iss_pri_id
instead of pri_rank).

So, unless I'm lucky enough to have added my priorities in a
successive order, and haven't moved them around at all, my sorting
will be arbitrary (in relation to rank).

On top of that, after patching this first issue, when I'm sorting per
Priority in Descending order, I would expect it to sort it like it's
done in the Priority adminstration view, where rank 1 is Highest, rank
5 is lowest. It doesn't. This means a Descending priority search will
actually list issues in Ascending priority order instead, which is the
opposite of what I want.

So, here's a patch, that's slightly contrived, but it fixes it the way
I want it.
So, have any of you noticed the annoying sort order of Priority? And
are you ok with such a patch?

The template patch has already been committed -- to sort by pri_rank
instead -- the inverse sorting is left to be fixed for this special
case.

If someone can patch it in a less-kludgy way, please do.

Comments?

--
Mikael
=== modified file 'lib/eventum/class.search.php'
--- lib/eventum/class.search.php	2011-10-08 07:56:29 +0000
+++ lib/eventum/class.search.php	2011-12-09 11:42:31 +0000
@@ -143,6 +143,43 @@
         return $cookie;
     }
 
+    /**
+     * Method which checks for special sorting fields which
+     * might have different ordering logic.
+     *
+     * @param  string $field
+     * @param  string $order
+     * @return string The proper sort order of the field, or same.
+     */
+    private static function getDBSortingOrder($field, $order)
+    {
+        switch ($field) {
+            case "pri_rank":
+                $order = self::invertDBSortingOrder($order);
+                break;
+        }
+        return $order;
+    }
+
+    /**
+     * Method which inverses the current order
+     * returns desc for asc, and asc for desc.
+     *
+     * @param  string $order The current sort order
+     * @return string The inverse sort order.
+     */
+    private static function invertDBSortingOrder($order)
+    {
+        if ($order == "asc") {
+            return "desc";
+        }
+        elseif ($order == "desc") {
+            return "asc";
+        }
+        else {
+            return $order;
+        }
+    }
 
     /**
      * Method used to get the current sorting options used in the grid layout
@@ -355,7 +392,7 @@
                  GROUP BY
                     iss_id
                  ORDER BY
-                    " . $sort_by . " " . Misc::escapeString($options["sort_order"]) . ",
+                    " . $sort_by . " " . self::getDBSortingOrder($sort_by, Misc::escapeString($options["sort_order"])) . ",
                     iss_id DESC";
         $total_rows = Pager::getTotalRows($stmt);
         $stmt .= "

=== modified file 'templates/adv_search.tpl.html'
--- templates/adv_search.tpl.html	2011-10-08 07:56:29 +0000
+++ templates/adv_search.tpl.html	2011-12-09 13:53:46 +0000
@@ -288,7 +288,7 @@
             <span class="default">{t}Sort By{/t}:</span><br />
             <select name="sort_by" class="default">
               <option value="last_action_date" {if $options.cst_sort_by == "last_action_date"}selected{/if}>{t}Last Action Date{/t}</option>
-              <option value="iss_pri_id" {if $options.cst_sort_by == "iss_pri_id"}selected{/if}>{t}Priority{/t}</option>
+              <option value="pri_rank" {if $options.cst_sort_by == "pri_rank"}selected{/if}>{t}Priority{/t}</option>
               <option value="iss_id" {if $options.cst_sort_by == "iss_id"}selected{/if}>{t}Issue ID{/t}</option>
               <option value="sta_rank" {if $options.cst_sort_by == "sta_rank"}selected{/if}>{t}Status{/t}</option>
               <option value="iss_summary" {if $options.cst_sort_by == "iss_summary"}selected{/if}>{t}Summary{/t}</option>

-- 
Mailing list: https://launchpad.net/~eventum-users
Post to     : eventum-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~eventum-users
More help   : https://help.launchpad.net/ListHelp

Reply via email to