diff --git a/resources/inc/class.resources_bo.inc.php b/resources/inc/class.resources_bo.inc.php index 70a148f5f6..5da06521e2 100755 --- a/resources/inc/class.resources_bo.inc.php +++ b/resources/inc/class.resources_bo.inc.php @@ -38,6 +38,16 @@ class resources_bo */ var $cats; + /** + * List of filter options + */ + public static $filter_options = array( + -1 => 'resources', + -2 => 'accessories', + -3 => 'resources and accessories' + // Accessories of a resource added when resource selected + ); + function __construct() { $this->so = new resources_so(); @@ -71,8 +81,34 @@ class resources_bo if ($this->debug) _debug_array($query); $read_onlys = 'res_id,name,short_description,quantity,useable,bookable,buyable,cat_id,location,storage_info'; - $accessory_of = $query['view_accs_of'] ? $query['view_accs_of'] : -1; - $filter = array('accessory_of' => $accessory_of); + $filter = array(); + $join = ''; + $extra_cols = array(); + + // Sub-query to get the count of accessories + $acc_join = "LEFT JOIN (SELECT accessory_of AS accessory_id, count(res_id) as acc_count FROM {$this->so->table_name} GROUP BY accessory_of) AS acc ON acc.accessory_id = {$this->so->table_name}.res_id "; + + switch($query['filter2']) + { + case -1: + // Resources only + $filter['accessory_of'] = -1; + $join = $acc_join; + $extra_cols[] = 'acc_count'; + break; + case -2: + // Accessories only + $filter[] = 'accessory_of != -1'; + break; + case -3: + // All + $join = $acc_join; + $extra_cols[] = 'acc_count'; + break; + default: + $filter['accessory_of'] = $query['view_accs_of']; + } + if ($query['filter']) { if (($children = $this->acl->get_cats(EGW_ACL_READ,$query['filter']))) @@ -102,7 +138,7 @@ class resources_bo $start = (int)$query['start']; foreach ($filter as $k => $v) $query['col_filter'][$k] = $v; - $this->so->get_rows($query, $rows, $readonlys); + $this->so->get_rows($query, $rows, $readonlys, $join, false, false, $extra_cols); $nr = $this->so->total; // we are called to serve bookable resources (e.g. calendar-dialog) @@ -150,21 +186,12 @@ class resources_bo $readonlys["buyable[$resource[res_id]]"] = true; $resource['class'] .= 'no_buy '; } - $readonlys["view_acc[$resource[res_id]]"] = true; - $links = egw_link::get_links('resources',$resource['res_id']); - if(count($links) != 0 && $accessory_of == -1) + $readonlys["view_acc[{$resource['res_id']}]"] = ($resource['acc_count'] == 0); + if($resource['acc_count']) { - foreach ($links as $link_num => $link) - { - if($link['app'] == 'resources') - { - if($this->so->get_value('accessory_of',$link['res_id']) != -1) - { - $readonlys["view_acc[$resource[res_id]]"] = false; - } - } - } + $resource['class'] .= 'hasAccessories '; } + $rows[$num]['picture_thumb'] = $this->get_picture($resource); $rows[$num]['admin'] = $this->acl->get_cat_admin($resource['cat_id']); } diff --git a/resources/inc/class.resources_ui.inc.php b/resources/inc/class.resources_ui.inc.php index 0b9ce5630c..f527b754a0 100755 --- a/resources/inc/class.resources_ui.inc.php +++ b/resources/inc/class.resources_ui.inc.php @@ -58,6 +58,7 @@ class resources_ui { unset($sessiondata['view_accs_of']); unset($sessiondata['no_filter']); + unset($sessiondata['filter2']); $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata); return $this->index(); } @@ -120,8 +121,7 @@ class resources_ui $content['nm']['get_rows'] = 'resources.resources_bo.get_rows'; $content['nm']['no_filter'] = False; $content['nm']['filter_label'] = lang('Category'); - $content['nm']['filter_help'] = lang('Select a category'); // is this used??? - $content['nm']['no_filter2'] = true; + $content['nm']['filter2_label'] = 'Display'; $content['nm']['filter_no_lang'] = true; $content['nm']['no_cat'] = true; $content['nm']['bottom_too'] = true; @@ -136,9 +136,15 @@ class resources_ui $content['nm'] = $nm_session_data; } $content['nm']['options-filter']= array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ); + $content['nm']['options-filter2'] = resources_bo::$filter_options; + if($_GET['search']) { $content['nm']['search'] = $_GET['search']; } + if($_GET['view_accs_of']) + { + $content['nm']['view_accs_of'] = (int)$_GET['view_accs_of']; + } $content['nm']['actions'] = $this->get_actions(); // check if user is permitted to add resources @@ -181,10 +187,10 @@ class resources_ui if($content['nm']['view_accs_of']) { $master = $this->bo->so->read(array('res_id' => $content['nm']['view_accs_of'])); - $content['view_accs_of'] = $content['nm']['view_accs_of']; + $content['view_accs_of'] = $content['nm']['filter2'] = $content['nm']['view_accs_of']; + $content['nm']['options-filter2'] = array($master['res_id'] => lang('accessories of') . ' ' . $master['name']); $content['nm']['get_rows'] = 'resources.resources_bo.get_rows'; $content['nm']['no_filter'] = true; - $content['nm']['no_filter2'] = true; $no_button['back'] = false; $no_button['add'] = true; $no_button['add_sub'] = false; @@ -222,6 +228,16 @@ class resources_ui 'popup' => egw_link::get_registry('resources', 'view_popup'), 'group' => $group, ), + 'view-acc' => array( + 'caption' => 'View accessories', + 'icon' => 'view_acc', + 'allowOnMultiple' => false, + 'url' => 'menuaction=resources.resources_ui.index&view_accs_of=$id', + 'group' => $group, + 'enableClass' => 'hasAccessories' + ), + + 'add' => array( 'caption' => 'Add', 'url' => 'menuaction=resources.resources_ui.edit', diff --git a/resources/lang/egw_en.lang b/resources/lang/egw_en.lang index 0859db056c..9db05752d2 100644 --- a/resources/lang/egw_en.lang +++ b/resources/lang/egw_en.lang @@ -1,4 +1,5 @@ accessories of resources en Accessories of +accessories resources en Accessories accessories: resources en Accessories: actions resources en Actions add accessory resources en Add accessory @@ -82,6 +83,7 @@ read permissions resources en Read permissions related links resources en Related links resource id resources en Resource ID resources common en Resources +resources and accessories resources en Resources and Accessories resources csv export resources en Resources CSV export resources csv import resources en Resources CSV import resources list resources en Resources list