From d15e738692f23a7c98d7e58438e9653f0fe049a8 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 22 Jun 2011 20:45:42 +0000 Subject: [PATCH] Fix filter for personal categories under a global category --- admin/inc/class.admin_categories.inc.php | 25 ++++++++++++------- .../class.preferences_categories_ui.inc.php | 4 +-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/admin/inc/class.admin_categories.inc.php b/admin/inc/class.admin_categories.inc.php index 4a69e50656..5be37f4738 100644 --- a/admin/inc/class.admin_categories.inc.php +++ b/admin/inc/class.admin_categories.inc.php @@ -285,7 +285,7 @@ class admin_categories * @param array &$readonlys eg. to disable buttons based on acl, not use here, maybe in a derived class * @return int total number of rows */ - static function get_rows($query,&$rows,&$readonlys) + public function get_rows($query,&$rows,&$readonlys) { self::init_static(); @@ -310,15 +310,21 @@ class admin_categories $filter['owner'] = 0; } - //$cats = new categories($query['col_filter']['owner'] ? $query['col_filter']['owner'] : $query['filter'],$query['appname']); $cats = new categories($filter['owner'],$query['appname']); - $parent =array(0); - // Use all parents, in case user has their cat as a child of a global or something - //if($filter['owner']) $parent += $cats->return_array('all',0,false,'','ASC','',true,null,-1, 'id'); - $rows = $cats->return_sorted_array($query['start'],$query['num_rows'],$query['search'],$query['sort'],$query['order'],$globalcat,$parent,true, $filter); - foreach($rows as &$row) +$globalcat=1; +$parent = 0; + $rows = $cats->return_sorted_array($query['start'],false,$query['search'],$query['sort'],$query['order'],$globalcat,$parent,true); + $count = $cats->total_records; + foreach($rows as $key => &$row) { + if($filter['owner'] && $filter['owner'] != $row['owner']) + { + unset($rows[$key]); + $count--; + continue; + } + $row['level_spacer'] = str_repeat('    ',$row['level']); if ($row['data']['icon']) $row['icon_url'] = self::icon_url($row['data']['icon']); @@ -334,13 +340,14 @@ class admin_categories $readonlys["add[$row[id]]"] = !self::$acl_add_sub; $readonlys["delete[$row[id]]"] = !self::$acl_delete; } + $rows = $count <= $query['num_rows'] ? array_values($rows) : array_slice($rows, $query['start'], $query['num_rows']); // make appname available for actions $rows['appname'] = $query['appname']; - $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Global categories'). + $GLOBALS['egw_info']['flags']['app_header'] = lang($this->appname).' - '.lang('categories'). ($query['appname'] != categories::GLOBAL_APPNAME ? ': '.lang($query['appname']) : ''); - return $cats->total_records; + return $count; } /** diff --git a/preferences/inc/class.preferences_categories_ui.inc.php b/preferences/inc/class.preferences_categories_ui.inc.php index db2675dcf9..a082f88897 100644 --- a/preferences/inc/class.preferences_categories_ui.inc.php +++ b/preferences/inc/class.preferences_categories_ui.inc.php @@ -17,7 +17,7 @@ class preferences_categories_ui extends admin_categories { protected $appname = 'preferences'; - protected $get_rows = 'preferences_categories_ui::get_rows'; + protected $get_rows = 'preferencespreferences_categories_ui.get_rows'; protected $list_link = 'preferences.preferences_categories_ui.index'; protected $edit_link = 'preferences.preferences_categories_ui.edit'; protected $add_link = 'preferences.preferences_categories_ui.edit'; @@ -25,7 +25,7 @@ class preferences_categories_ui extends admin_categories { function __construct() { } - public static function get_rows(&$query, &$rows, &$readonlys) { + public function get_rows(&$query, &$rows, &$readonlys) { $count = parent::get_rows($query, $rows, $readonlys); $rows['edit_link'] = 'preferences.preferences_categories_ui.edit'; return $count;