This patch adds the possibility to sort by "Voted" and "Notify" columns
in package search results. Fixes FS#13643 [1] (and maybe also FS#5401
[2]).

[1] http://bugs.archlinux.org/task/13643
[2] http://bugs.archlinux.org/task/5401
>From f2864b6ac2465fa7fe464efedb794373bb2a1862 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <[email protected]>
Date: Sun, 30 May 2010 00:20:42 +0200
Subject: [PATCH] Add sorting by "Voted" and "Notify" fields

---
 web/lib/pkgfuncs.inc                |   26 ++++++++++++++++++++------
 web/template/pkg_search_form.php    |    2 +-
 web/template/pkg_search_results.php |    8 ++++++--
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index 49bedc3..43a7a6f 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -515,32 +515,46 @@ function pkg_search_page($SID="") {
 
        $order = $_GET["SO"] == 'd' ? 'DESC' : 'ASC';
 
+       $q_sort = "ORDER BY Name ".$order.", LocationID ASC, CategoryID DESC ";
        switch ($_GET["SB"]) {
        case 'c':
-               $q.= "ORDER BY CategoryID ".$order.", Name ASC, LocationID ASC 
";
+               $q_sort = "ORDER BY CategoryID ".$order.", Name ASC, LocationID 
ASC ";
                $_GET["SB"] = 'c';
                break;
        case 'l':
-               $q.= "ORDER BY LocationID ".$order.", Name ASC, CategoryID DESC 
";
+               $q_sort = "ORDER BY LocationID ".$order.", Name ASC, CategoryID 
DESC ";
                $_GET["SB"] = 'l';
                break;
        case 'v':
-               $q.= "ORDER BY NumVotes ".$order.", Name ASC, CategoryID DESC ";
+               $q_sort = "ORDER BY NumVotes ".$order.", Name ASC, CategoryID 
DESC ";
                $_GET["SB"] = 'v';
                break;
+       case 'w':
+               if ($SID) {
+                       $q_sort = "ORDER BY Voted ".$order.", Name ASC, 
CategoryID DESC ";
+               }
+               $_GET["SB"] = 'w';
+               break;
+       case 'o':
+               if ($SID) {
+                       $q_sort = "ORDER BY Notify ".$order.", Name ASC, 
CategoryID DESC ";
+               }
+               $_GET["SB"] = 'o';
+               break;
        case 'm':
-               $q.= "ORDER BY Maintainer ".$order.", Name ASC, LocationID ASC 
";
+               $q_sort = "ORDER BY Maintainer ".$order.", Name ASC, LocationID 
ASC ";
                $_GET["SB"] = 'm';
                break;
        case 'a':
-               $q.= "ORDER BY GREATEST(SubmittedTS,ModifiedTS) ".$order.", 
Name ASC, LocationID ASC ";
+               $q_sort = "ORDER BY GREATEST(SubmittedTS,ModifiedTS) 
".$order.", Name ASC, LocationID ASC ";
                $_GET["SB"] = 'a';
                break;
        default:
-               $q.= "ORDER BY Name ".$order.", LocationID ASC, CategoryID DESC 
";
                break;
        }
 
+       $q.= $q_sort;
+
        $q.= "LIMIT ".$_GET["O"].", ".$_GET["PP"];
 
        $result = db_query($q, $dbh);
diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php
index 88cc698..0947ba8 100644
--- a/web/template/pkg_search_form.php
+++ b/web/template/pkg_search_form.php
@@ -56,7 +56,7 @@
                                                <label><?php print __("Sort 
by"); ?></label>
                                                <select name='SB'>
                                                        <?php
-                                                       $sortby = array('n' => 
'Name', 'c' => 'Category', 'l' => 'Location', 'v' => 'Votes', 'm' => 
'Maintainer', 'a' => 'Age');
+                                                       $sortby = array('n' => 
'Name', 'c' => 'Category', 'l' => 'Location', 'v' => 'Votes', 'w' => 'Voted', 
'o' => 'Notify', 'm' => 'Maintainer', 'a' => 'Age');
                                                        foreach ($sortby as $k 
=> $v):
                                                                if 
($_REQUEST['SB'] == $k):
                                                        ?>
diff --git a/web/template/pkg_search_results.php 
b/web/template/pkg_search_results.php
index b7015ce..364a352 100644
--- a/web/template/pkg_search_results.php
+++ b/web/template/pkg_search_results.php
@@ -29,8 +29,12 @@
        </span></th>
 
        <?php if ($SID): ?>
-       <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'><?php print __("Voted") ?></span></th>
-       <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'><?php print __("Notify") ?></span></th>
+       <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'>
+               <a href='?<?php print mkurl('SB=w&SO=' . $SO_next) ?>'><?php 
print __("Voted") ?></a>
+       </span></th>
+       <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'>
+               <a href='?<?php print mkurl('SB=o&SO=' . $SO_next) ?>'><?php 
print __("Notify") ?></a>
+       </span></th>
        <?php endif; ?>
        <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'><?php print __("Description") ?></span></th>
        <th style='border-bottom: #666 1px solid; vertical-align: bottom'><span 
class='f2'>
-- 
1.7.1

Reply via email to