Update with some best practices:

- Change backend to use so_sql_cf to get custom fields into nextmatch
- Change file names to resources_*
- Fix missing category filter when returning from viewing accessories
This commit is contained in:
Nathan Gray 2011-03-23 15:25:59 +00:00
parent 0b2168e924
commit 0abd9582cd
12 changed files with 51 additions and 81 deletions

View File

@ -16,7 +16,7 @@
*
* @package resources
*/
class bo_resources
class resources_bo
{
const PICTURE_NAME = '.picture.jpg';
var $resource_icons = '/resources/templates/default/images/resource_icons/';
@ -38,9 +38,9 @@ class bo_resources
*/
var $cats;
function bo_resources()
function __construct()
{
$this->so =& CreateObject('resources.so_resources');
$this->so = new resources_so();
$this->acl =& CreateObject('resources.bo_acl');
$this->cats = $this->acl->egw_cats;
@ -69,7 +69,6 @@ class bo_resources
}
}
if ($this->debug) _debug_array($query);
$criteria = $query['search'];
$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;
@ -91,7 +90,9 @@ class bo_resources
$filter['cat_id'] = array_keys($readcats);
}
// if there is no catfilter -> this means you have no rights, so set the cat filter to null
if (!isset($filter['cat_id']) || empty($filter['cat_id'])) $filter['cat_id'] = NUll;
if (!isset($filter['cat_id']) || empty($filter['cat_id'])) {
$filter['cat_id'] = NUll;
}
if ($query['show_bookable'])
{
@ -100,7 +101,8 @@ class bo_resources
$order_by = $query['order'] ? $query['order'].' '. $query['sort'] : '';
$start = (int)$query['start'];
$rows = $this->so->search($criteria,$read_onlys,$order_by,'','%',$empty=False,$op='OR',$start,$filter,$join='',$need_full_no_count=false);
$query['col_filter'] = $filter;
$this->so->get_rows($query, $rows, $readonlys);
$nr = $this->so->total;
// we are called to serve bookable resources (e.g. calendar-dialog)
@ -318,7 +320,7 @@ class bo_resources
*/
function get_calendar_info($res_id)
{
//echo "<p>bo_resources::get_calendar_info(".print_r($res_id,true).")</p>\n";
//echo "<p>resources_bo::get_calendar_info(".print_r($res_id,true).")</p>\n";
if(!is_array($res_id) && $res_id < 1) return;
$data = $this->so->search(array('res_id' => $res_id),self::TITLE_COLS.',useable');

View File

@ -30,7 +30,7 @@ class resources_egw_record implements importexport_iface_egw_record
public function __construct( $_identifier='' ) {
$this->identifier = $_identifier;
if($this->identifier) {
$this->record = ExecMethod('resources.bo_resources.read', $this->identifier);
$this->record = ExecMethod('resources.resources_bo.read', $this->identifier);
}
}

View File

@ -24,7 +24,7 @@ class resources_export_csv implements importexport_iface_export_plugin {
public function export( $_stream, importexport_definition $_definition) {
$options = $_definition->plugin_options;
$bo = CreateObject('resources.bo_resources');
$bo = new resources_bo();
$selection = array();
if ($options['selection'] == 'selected') {
// ui selection with checkbox 'selected'

View File

@ -28,12 +28,12 @@ class resources_hooks
{
$title = $GLOBALS['egw_info']['apps']['resources']['title'].' '.lang('Menu');
$file = array(
'Resources list' => egw::link('/index.php',array('menuaction' => 'resources.ui_resources.index' )),
'Resources list' => egw::link('/index.php',array('menuaction' => 'resources.resources_ui.index' )),
);
if($this->acl->get_cats(EGW_ACL_ADD))
{
$file['Add resource'] = "javascript:egw_openWindowCentered2('".egw::link('/index.php',array(
'menuaction' => 'resources.ui_resources.edit',
'menuaction' => 'resources.resources_ui.edit',
),false)."','_blank',800,600,'yes')";
}
display_sidebox($appname,$title,$file);
@ -82,17 +82,17 @@ class resources_hooks
function search_link($args)
{
return array(
'query' => 'resources.bo_resources.link_query',
'title' => 'resources.bo_resources.link_title',
'titles' => 'resources.bo_resources.link_titles',
'query' => 'resources.resources_bo.link_query',
'title' => 'resources.resources_bo.link_title',
'titles' => 'resources.resources_bo.link_titles',
'view' => array(
'menuaction' => 'resources.ui_resources.show'
'menuaction' => 'resources.resources_ui.show'
),
'view_id' => 'res_id',
'view_popup' => '850x600',
'view_list' => 'resources.ui_resources.index',
'view_list' => 'resources.resources_ui.index',
'add' => array(
'menuaction' => 'resources.ui_resources.edit',
'menuaction' => 'resources.resources_ui.edit',
),
'add_app' => 'link_app',
'add_id' => 'link_id',
@ -105,15 +105,15 @@ class resources_hooks
{
return array(
'widget' => 'resources_select',// widget to use for the selection of resources
'info' => 'resources.bo_resources.get_calendar_info',// info method, returns array with id, type & name for a given id
'info' => 'resources.resources_bo.get_calendar_info',// info method, returns array with id, type & name for a given id
'max_quantity' => 'useable',// if set, key for max. quantity in array returned by info method
'new_status' => 'resources.bo_resources.get_calendar_new_status',// method returning the status for new items, else 'U' is used
'new_status' => 'resources.resources_bo.get_calendar_new_status',// method returning the status for new items, else 'U' is used
'type' => 'r',// one char type-identifiy for this resources
'icon' => 'calicon',//icon
'participants_header' => lang('resources'), // header of participants from this type
'cal_sidebox' => array(
'menu_title' => lang('Select resources'),
'file' => 'resources.ui_resources.get_calendar_sidebox'
'file' => 'resources.resources_ui.get_calendar_sidebox'
)
);
}
@ -162,7 +162,7 @@ class resources_hooks
// Get any resources affected
$query = array('filter' => $args['cat_id']);
$bo = CreateObject('resources.bo_resources');
$bo = new resources_bo();
$bo->get_rows($query, $resources, $readonly);
foreach($resources as $resource)
{

View File

@ -110,7 +110,7 @@ class resources_import_csv implements importexport_iface_import_plugin {
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
// fetch the resource bo
$this->bo = CreateObject('resources.bo_resources');
$this->bo = new resources_bo();
// set FieldMapping.
$import_csv->mapping = $_definition->plugin_options['field_mapping'];

View File

@ -58,7 +58,7 @@ class resources_select_widget
{
// no acl check here cause names are allways viewable
list($res_id,$quantity) = explode(':',$value);
$data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id);
$data = ExecMethod('resources.resources_bo.get_calendar_info',$res_id);
$cell['type'] = 'label';
$value = $data[0]['name']. ($data[0]['useable'] > 1 ? ' ['. ($quantity > 1 ? $quantity : 1). '/'. $data[0]['useable']. ']' : '');
return true;
@ -80,7 +80,7 @@ class resources_select_widget
foreach((array)$value as $id)
{
list($res_id,$quantity) = explode(':',$id);
$data = ExecMethod('resources.bo_resources.get_calendar_info',$res_id);
$data = ExecMethod('resources.resources_bo.get_calendar_info',$res_id);
$sel_options[$data[0]['res_id'].($quantity > 1 ? (':'.$quantity) : '')] =
$data[0]['name'].' ['.($quantity > 1 ? $quantity : 1).'/'.$data[0]['useable'].']';
}

View File

@ -16,17 +16,14 @@
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
* @package resources
*/
class so_resources extends so_sql
class resources_so extends so_sql_cf
{
function so_resources()
function __construct()
{
parent::__construct('resources','egw_resources');
$this->customfields = config::get_customfields('resources');
$this->soextra = new so_sql('resources','egw_resources_extra');
parent::__construct('resources','egw_resources', 'egw_resources_extra', '',
'extra_name', 'extra_value', 'extra_id' );
$this->columns_to_search = array('name','short_description','inventory_number','long_description','location');
}
/**
@ -52,16 +49,6 @@ class so_resources extends so_sql
// read main data
$resource = parent::read($res_id);
// read customfields
$keys = array(
'extra_id' => $res_id,
'extra_owner' => -1,
);
$customfields = $this->soextra->search($keys,false);
foreach ((array)$customfields as $field)
{
$resource['#'.$field['extra_name']] = $field['extra_value'];
}
return $resource;
}
@ -77,20 +64,6 @@ class so_resources extends so_sql
if(parent::save() != 0) return false;
$res_id = $this->data['res_id'];
// save customfields
foreach ($this->customfields as $field => $options)
{
$value = $resource['#'.$field];
$data = array(
'extra_id' => $res_id,
'extra_name' => $field,
'extra_owner' => -1,
'extra_value' => $value,
);
$this->soextra->data = $data;
$error_nr = $this->soextra->save();
if($error_nr) return false;
}
return $res_id;
}

View File

@ -15,7 +15,7 @@
*
* @package resources
*/
class ui_resources
class resources_ui
{
var $public_functions = array(
'index' => True,
@ -33,19 +33,10 @@ class ui_resources
{
// print_r($GLOBALS['egw_info']); die();
$this->tmpl = new etemplate('resources.show');
$this->bo =& CreateObject('resources.bo_resources');
$this->bo = new resources_bo();
// $this->calui = CreateObject('resources.ui_calviews');
}
/**
* PHP4 constructor
*
* @deprecated use __construct();
*/
function ui_resources()
{
self::__construct();
}
/**
* main resources list.
@ -66,6 +57,7 @@ class ui_resources
if (isset($content['back']))
{
unset($sessiondata['view_accs_of']);
unset($sessiondata['no_filter']);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
return $this->index();
}
@ -101,7 +93,7 @@ class ui_resources
$content['msg'] = $msg;
$content['nm']['header_left'] = 'resources.resource_select.header';
$content['nm']['get_rows'] = 'resources.bo_resources.get_rows';
$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???
@ -162,7 +154,7 @@ class ui_resources
{
$master = $this->bo->so->read(array('res_id' => $content['nm']['view_accs_of']));
$content['view_accs_of'] = $content['nm']['view_accs_of'];
$content['nm']['get_rows'] = 'resources.bo_resources.get_rows';
$content['nm']['get_rows'] = 'resources.resources_bo.get_rows';
$content['nm']['no_filter'] = true;
$content['nm']['no_filter2'] = true;
$no_button['back'] = false;
@ -174,7 +166,7 @@ class ui_resources
$preserv = $content;
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']);
$this->tmpl->read('resources.show');
return $this->tmpl->exec('resources.ui_resources.index',$content,$sel_options,$no_button,$preserv);
return $this->tmpl->exec('resources.resources_ui.index',$content,$sel_options,$no_button,$preserv);
}
/**
@ -210,7 +202,7 @@ class ui_resources
return $this->edit($content);
}
$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',
array('menuaction' => 'resources.ui_resources.index'))."';";
array('menuaction' => 'resources.resources_ui.index'))."';";
$js .= 'window.close();';
echo "<html><body><script>$js</script></body></html>\n";
$GLOBALS['egw']->common->egw_exit();
@ -256,7 +248,7 @@ class ui_resources
$no_button = array(); // TODO: show delete button only if allowed to delete resource
$preserv = $content;
$this->tmpl->read('resources.edit');
return $this->tmpl->exec('resources.ui_resources.edit',$content,$sel_options,$no_button,$preserv,2);
return $this->tmpl->exec('resources.resources_ui.edit',$content,$sel_options,$no_button,$preserv,2);
}
@ -278,7 +270,7 @@ class ui_resources
return $this->show($content);
}
$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',
array('menuaction' => 'resources.ui_resources.index'))."';";
array('menuaction' => 'resources.resources_ui.index'))."';";
$js .= 'window.close();';
echo "<html><body><script>$js</script></body></html>\n";
$GLOBALS['egw']->common->egw_exit();
@ -333,7 +325,7 @@ class ui_resources
);
$preserv = $content;
$this->tmpl->read('resources.showdetails');
return $this->tmpl->exec('resources.ui_resources.show',$content,$sel_options,$no_button,$preserv,2);
return $this->tmpl->exec('resources.resources_ui.show',$content,$sel_options,$no_button,$preserv,2);
}
@ -454,7 +446,7 @@ class ui_resources
$content['nm'] = array(
'header_left' => 'resources.resource_select.header',
'show_bookable' => true,
'get_rows' => 'resources.bo_resources.get_rows',
'get_rows' => 'resources.resources_bo.get_rows',
'filter_label' => 'Category',
'filter_help' => lang('Select a category'),
'options-filter'=> array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ),
@ -472,7 +464,7 @@ class ui_resources
$sel_options = array();
$no_button = array();
$this->tmpl->read('resources.resource_select');
return $this->tmpl->exec('resources.ui_resources.select',$content,$sel_options,$no_button,$preserv,2);
return $this->tmpl->exec('resources.resources_ui.select',$content,$sel_options,$no_button,$preserv,2);
}
/**

View File

@ -10,5 +10,5 @@
* @version $Id$
*/
header('Location: ../index.php?menuaction=resources.ui_resources.index'.
header('Location: ../index.php?menuaction=resources.resources_ui.index'.
(isset($_GET['sessionid']) ? '&sessionid='.$_GET['sessionid'].'&kp3='.$_GET['kp3'] : ''));

File diff suppressed because one or more lines are too long

View File

@ -13,11 +13,10 @@
$setup_info['resources']['name'] = 'resources';
$setup_info['resources']['title'] = 'Resources';
$setup_info['resources']['version'] = '1.8';
$setup_info['resources']['version'] = '1.9.001';
$setup_info['resources']['app_order'] = 5;
$setup_info['resources']['tables'] = array('egw_resources','egw_resources_extra');
$setup_info['resources']['enable'] = 1;
$setup_info['resources']['index'] = 'resources.ui_resources.index';
$setup_info['resources']['author'] = 'Cornelius Weiss';
$setup_info['resources']['license'] = 'GPL';

View File

@ -318,3 +318,7 @@ function resources_upgrade1_6()
{
return $GLOBALS['setup_info']['resources']['currentver'] = '1.8';
}
function resources_upgrade1_8()
{
return $GLOBALS['setup_info']['resources']['currentver'] = '1.9.001';
}