]> git.mjollnir.org Git - s9y.git/commitdiff
allow to sort categories by custom fields
authorgarvinhicking <garvinhicking>
Fri, 29 Apr 2005 13:05:53 +0000 (13:05 +0000)
committergarvinhicking <garvinhicking>
Fri, 29 Apr 2005 13:05:53 +0000 (13:05 +0000)
docs/NEWS
include/functions_entries.inc.php
include/plugin_internal.inc.php

index 7652edfbb5ec6d6a5ff03d92192ccc72c546f586..02e9b1dc4a41d11024d74df5fbc393f0399d88ed 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Categories plugin now offers to sort by category name, description
+      or creation date. (garvinhicking)
+
     * Deactivated gzip compression by default, as in certain server
       setups it creates problem with double-encoding or missing
       ob_gzhandlers. (garvinhicking)
index 5c9f1332e5cb49d1e79a81f82661f463e96dbe60..9e7557698e92ca6691708cba685cbb6f7958b0c7 100644 (file)
@@ -356,7 +356,7 @@ function serendipity_fetchEntryProperties($id) {
 /**
 * Fetches a users categories
 **/
-function serendipity_fetchCategories($authorid = null, $name = '') {
+function serendipity_fetchCategories($authorid = null, $name = '', $order = 'category_name ASC') {
     global $serendipity;
 
     if (!isset($authorid) || $authorid === null) {
@@ -389,8 +389,12 @@ function serendipity_fetchCategories($authorid = null, $name = '') {
                            a.realname
                       FROM {$serendipity['dbPrefix']}category AS c
            LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a
-                        ON c.authorid = a.authorid $where
-                  ORDER BY category_name";
+                        ON c.authorid = a.authorid $where";
+
+    if (!empty($order)) {
+        $querystring .= "\n ORDER BY $order";
+    }
+
     return serendipity_db_query($querystring);
 }
 
index 749c16d42f6655b3da08943a13dbee88add08553..738dee3302c97308fd2febfcb07367139f4aed9a 100644 (file)
@@ -954,7 +954,7 @@ class serendipity_categories_plugin extends serendipity_plugin {
         $propbag->add('stackable',     true);
         $propbag->add('author',        'Serendipity Team');
         $propbag->add('version',       '1.0');
-        $propbag->add('configuration', array('authorid', 'image'));
+        $propbag->add('configuration', array('authorid', 'image', 'sort_order', 'sort_method'));
     }
 
     function introspect_config_item($name, &$propbag)
@@ -977,6 +977,29 @@ class serendipity_categories_plugin extends serendipity_plugin {
                 $propbag->add('default',     'all');
                 break;
 
+            case 'sort_order':
+                $select = array();
+                $select['category_name']        = CATEGORY;
+                $select['category_description'] = DESCRIPTION;
+                $select['none']                 = NONE;
+                $propbag->add('type',         'select');
+                $propbag->add('name',         SORT_ORDER);
+                $propbag->add('description',  '');
+                $propbag->add('select_values', $select);
+                $propbag->add('default',     'category_name');
+                break;
+
+            case 'sort_method':
+                $select = array();
+                $select['ASC'] = SORT_ORDER_ASC;
+                $select['DESC'] = SORT_ORDER_DESC;
+                $propbag->add('type',         'select');
+                $propbag->add('name',         SORT_ORDER);
+                $propbag->add('description',  '');
+                $propbag->add('select_values', $select);
+                $propbag->add('default',     'ASC');
+                break;
+
             case 'image':
                 $propbag->add('type',         'string');
                 $propbag->add('name',         XML_IMAGE_TO_DISPLAY);
@@ -994,7 +1017,13 @@ class serendipity_categories_plugin extends serendipity_plugin {
         global $serendipity;
 
         $which_category = $this->get_config('authorid');
-        $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category);
+        $sort = $this->get_config('sort_order');
+        if ($sort == 'none') {
+            $sort = '';
+        } else {
+            $sort .= ' ' . $this->get_config('sort_method');
+        }
+        $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort);
         $title = $this->title;
         $html       = '';
         $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));