[art-web] [themes] add popularity sort to theme pages



commit 7ec5cb688d96479ed9ffb925e31a369437e77739
Author: Thomas Wood <thos gnome org>
Date:   Sun Nov 22 23:04:26 2009 +0000

    [themes] add popularity sort to theme pages

 controllers/themes.php |   27 +++++++++++++++++++++++++--
 views/themes.php       |   21 +++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/controllers/themes.php b/controllers/themes.php
index 998941f..f25e340 100644
--- a/controllers/themes.php
+++ b/controllers/themes.php
@@ -50,6 +50,29 @@ $limit = GET ('limit');
 if (!is_numeric ($limit))
   $limit = 12;
 
+$set_sort = GET ('sort');
+if ($set_sort)
+{
+  setcookie ('sort', $set_sort);
+  $sort = $set_sort;
+}
+else
+  $sort = (array_key_exists ('sort', $_COOKIE)) ? $_COOKIE['sort'] : 'name';
+
+if ($sort)
+{
+  if ($sort == 'rating')
+    $sortby = 'rating DESC';
+  else if ($sort == 'name')
+    $sortby = 'name';
+  else if ($sort == 'popularity')
+    $sortby = 'download_count DESC';
+  else
+    $sortby = 'name';
+}
+else
+  $sortby = 'name';
+
 $start = ($page - 1) * $limit;
 
 if ($category)
@@ -59,7 +82,7 @@ if ($category)
     $search = "theme.name LIKE '%".$search."%'";
     $search_text = htmlspecialchars (GET ('text'));
 
-    $view_data = $themes->search_items ($search, $start, $limit, "name");
+    $view_data = $themes->search_items ($search, $start, $limit, $sortby);
     $total_themes = $themes->search_total ($search);
   }
   else
@@ -71,7 +94,7 @@ if ($category)
     }
     else
     {
-      $view_data = $themes->get_items ($category, $start, $limit, "name");
+      $view_data = $themes->get_items ($category, $start, $limit, $sortby);
       $total_themes = $themes->get_total ($category);
     }
   }
diff --git a/views/themes.php b/views/themes.php
index dceb451..6459517 100644
--- a/views/themes.php
+++ b/views/themes.php
@@ -71,6 +71,12 @@ $display_cat = array (
   else
     $d_category = $display_cat [$category];
 
+function selected ($a, $b)
+{
+  if ($a == $b)
+    echo ' selected="selected"';
+}
+
 ?>
 
 
@@ -83,6 +89,18 @@ String.prototype.rot13 = rot13 = function(s)
 
 <h2><a href="/themes">Themes</a> / <?php echo $d_category; ?></h2>
 <div style="text-align:center"><?php $p->print_pagination (); ?></div>
+
+<form method="get" style="text-align:center; font-size: small;">
+  <label>Sort By:
+  <select name="sort" onchange="this.form.submit()" style="font-size: small">
+    <option value="name"<?php selected ($sort, 'name')?>>Name</option>
+    <option value="popularity"<?php selected ($sort, 'popularity')?>>Popularity</option>
+  </select>
+  <noscript>
+    <input type="submit" value="Go" style="font-size: small;">
+  </noscript>
+  </label>
+</form>
 <br>
 <?php foreach ($view_data as $row): ?>
 
@@ -93,6 +111,9 @@ String.prototype.rot13 = rot13 = function(s)
   <br>
   <img style="margin:0.5em;" width="96" alt="Preview" src='/images/thumbnails/<?php echo $row['category']?>/<?php echo $row['thumbnail_filename']?>'>
   <br>
+  <span class="item-detail">
+  <?php echo number_format ($row['download_count']) ?> downloads
+  </span><br>
    <a href="/download/themes/<?php printf ("%s/%s/%s", $row['category'], $row['themeID'], $row['download_filename'])?>">Download</a>
 </div>
 <?php endforeach ?>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]