phpgroupware-developers
[Top][All Lists]
Advanced

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

[Phpgroupware-developers] Category sorting issues


From: Randy Smith
Subject: [Phpgroupware-developers] Category sorting issues
Date: Thu, 10 Jan 2002 09:47:50 -0700

Hi all,

On Dec. 27 I emailed this list regarding a problem with the sorting of the 
categories in phpgw 0.9.12. The problem still exists in phpgw 0.9.13.017. 
Here's a link to my original message and problem description in the archives: 
http://mail.gnu.org/pipermail/phpgroupware-developers/2001-December/000423.html

After much pain and anguish, I have worked up a patch that solves the sorting 
issues. The only catch is that I don't know how to use the $limit parameter 
to limit the number of categories returned while still doing the sorting and 
nesting. If someone has any ideas, please let me know (or solve it yourself 
:-) ).

I also made a minor cosmetic change that makes the subcategories more obvious 
in the various select boxes.

Let me know if you want the patch submitted in some other way or if you have 
any questions.

-- 
Randy Smith
Amigo.Net Systems Administrator
1-719-589-6100 x 4185
http://www.amigo.net/

--- class.categories.inc.org.php        Wed Jan  9 13:42:59 2002
+++ class.categories.inc.php    Thu Jan 10 08:55:19 2002
@@ -126,15 +126,6 @@
                                $sort = 'ASC';
                        }
 
-                       if ($order)
-                       {
-                               $ordermethod = " ORDER BY $order $sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' ORDER BY cat_main, cat_level, 
cat_name ASC';
-                       }
-
                        if (is_array($this->grants))
                        {
                                $grants = $this->grants;
@@ -150,45 +141,126 @@
                                $grant_cats = " cat_owner='" . 
$this->account_id . "' ";
                        }
 
-                       if ($parent_id)
-                       {
-                               $parent_filter = " AND cat_parent='$parent_id'";
-                       }
-
                        if ($query)
                        {
                                $querymethod = " AND (cat_name LIKE '%$query%' 
OR cat_description LIKE 
'%$query%') ";
                        }
 
-                       $sql = "SELECT * from phpgw_categories WHERE 
(cat_appname='" . 
$this->app_name . "' AND" . $grant_cats . $public_cats . ")"
-                               . $parent_filter . $querymethod . $filter;
-
-                       if ($limit)
+                       if ($order)
                        {
-                               $this->db->limit_query($sql . 
$ordermethod,$start,__LINE__,__FILE__);
+                               if ($parent_id)
+                               {
+                                       $parent_filter = " AND 
cat_parent='$parent_id'";
+                               }
+
+                               $ordermethod = " ORDER BY $order $sort";
+
+                               $sql = "SELECT * from phpgw_categories WHERE 
(cat_appname='" . 
$this->app_name . "' AND" . $grant_cats . $public_cats . ")"
+                                       . $parent_filter . $querymethod . 
$filter;
+
+                               if ($limit)
+                               {
+                                       $this->db->limit_query($sql . 
$ordermethod,$start,__LINE__,__FILE__);
+                               }
+                               else
+                               {
+                                       $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
+                               }
+
+                               $this->total_records = $this->db->num_rows();
+       
+                               $i = 0;
+                               while ($this->db->next_record())
+                               {
+                                       $cats[$i]['id']          = 
$this->db->f('cat_id');
+                                       $cats[$i]['owner']       = 
$this->db->f('cat_owner');
+                                       $cats[$i]['access']      = 
$this->db->f('cat_access');
+                                       $cats[$i]['app_name']    = 
$this->db->f('cat_appname');
+                                       $cats[$i]['main']        = 
$this->db->f('cat_main');
+                                       $cats[$i]['level']       = 
$this->db->f('cat_level');
+                                       $cats[$i]['parent']      = 
$this->db->f('cat_parent');
+                                       $cats[$i]['name']        = 
$this->db->f('cat_name');
+                                       $cats[$i]['description'] = 
$this->db->f('cat_description');
+                                       $cats[$i]['data']        = 
$this->db->f('cat_data');
+                                       $i++;
+                               }
                        }
                        else
                        {
-                               $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
-                       }
+                               $sql = "SELECT * from phpgw_categories WHERE 
(cat_appname='" . 
$this->app_name . "' AND" . $grant_cats . $public_cats . ")"
+                                       . $querymethod . $filter;
 
-                       $this->total_records = $this->db->num_rows();
+                               $orderby = ' order by cat_name';
 
-                       $i = 0;
-                       while ($this->db->next_record())
-                       {
-                               $cats[$i]['id']          = 
$this->db->f('cat_id');
-                               $cats[$i]['owner']       = 
$this->db->f('cat_owner');
-                               $cats[$i]['access']      = 
$this->db->f('cat_access');
-                               $cats[$i]['app_name']    = 
$this->db->f('cat_appname');
-                               $cats[$i]['main']        = 
$this->db->f('cat_main');
-                               $cats[$i]['level']       = 
$this->db->f('cat_level');
-                               $cats[$i]['parent']      = 
$this->db->f('cat_parent');
-                               $cats[$i]['name']        = 
$this->db->f('cat_name');
-                               $cats[$i]['description'] = 
$this->db->f('cat_description');
-                               $cats[$i]['data']        = 
$this->db->f('cat_data');
-                               $i++;
+                               if (0) // if ($limit)
+                               {
+                                       // do something to limit the number 
returned ?
+                               }
+                               else
+                               {
+                                       $this->db->query($sql . ' AND cat_level 
= 0' . $orderby, __LINE,__FILE);
+                                       $i = 0;
+                                       while ($this->db->next_record())
+                                       {
+                                               $cats[$i]['id']          = 
$this->db->f('cat_id');
+                                               $cats[$i]['owner']       = 
$this->db->f('cat_owner');
+                                               $cats[$i]['access']      = 
$this->db->f('cat_access');
+                                               $cats[$i]['app_name']    = 
$this->db->f('cat_appname');
+                                               $cats[$i]['main']        = 
$this->db->f('cat_main');
+                                               $cats[$i]['level']       = 
$this->db->f('cat_level');
+                                               $cats[$i]['parent']      = 
$this->db->f('cat_parent');
+                                               $cats[$i]['name']        = 
$this->db->f('cat_name');
+                                               $cats[$i]['description'] = 
$this->db->f('cat_description');
+                                               $cats[$i]['data']        = 
$this->db->f('cat_data');
+                                               $i++;
+                                       }
+                                       $num_cats = count($cats);
+                                       for ($i = 0; $i < $num_cats; $i++)
+                                       {
+                                               $newsql = $sql . " and 
cat_parent=".$cats[$i]['id']
+                                                       . " and 
cat_level=".($cats[$i]['level']+1)
+                                                       . $orderby;
+                                               
$this->db->query($newsql,__LINE__,__FILE__);
+                                               $j = 0;
+                                               $subcats = array();
+                                               while ($this->db->next_record())
+                                               {
+                                                       $subcats[$j]['id']      
    = $this->db->f('cat_id');
+                                                       $subcats[$j]['owner']   
    = $this->db->f('cat_owner');
+                                                       $subcats[$j]['access']  
    = $this->db->f('cat_access');
+                                                       
$subcats[$j]['app_name']    = $this->db->f('cat_appname');
+                                                       $subcats[$j]['main']    
    = $this->db->f('cat_main');
+                                                       $subcats[$j]['level']   
    = $this->db->f('cat_level');
+                                                       $subcats[$j]['parent']  
    = $this->db->f('cat_parent');
+                                                       $subcats[$j]['name']    
    = $this->db->f('cat_name');
+                                                       
$subcats[$j]['description'] = $this->db->f('cat_description');
+                                                       $subcats[$j]['data']    
    = $this->db->f('cat_data');
+                                                       $j++;
+                                               }
+                                               // PHP4: $cats = 
array_merge(array_slice($cats,0,$i), $subcats, 
array_slice($cats,$i+1));
+                                               $num_subcats = count($subcats);
+                                               if ($num_subcats != 0)
+                                               {
+                                                       $newcats = array();
+                                                       for ($k = 0; $k <= $i; 
$k++)
+                                                       {
+                                                               $newcats[$k] = 
$cats[$k];
+                                                       }
+                                                       for ($k = 0; $k < 
$num_subcats; $k++)
+                                                       {
+                                                               
$newcats[$k+$i+1] = $subcats[$k];
+                                                       }
+                                                       for ($k = $i+1; $k < 
$num_cats; $k++)
+                                                       {
+                                                               
$newcats[$k+$num_subcats] = $cats[$k];
+                                                       }
+                                                       $cats = $newcats;
+                                                       $num_cats = 
count($cats);
+                                               }
+                                       }
+                               }
                        }
+
                        return $cats;
                }
 
@@ -262,7 +334,12 @@
                                        {
                                                $s .= ' selected';
                                        }
-                                       $s .= '>' . 
$GLOBALS['phpgw']->strip_html($cats[$i]['name']);
+                                       $s .= '>';
+                                       for ($j=0;$j<$cats[$i]['level'];$j++)
+                                       {
+                                               $s .= '&nbsp;';
+                                       }
+                                       $s .= 
$GLOBALS['phpgw']->strip_html($cats[$i]['name']);
                                        if ($cats[$i]['app_name'] == 'phpgw')
                                        {
                                                $s .= '&lt;' . lang('Global') . 
'&gt;';



reply via email to

[Prev in Thread] Current Thread [Next in Thread]