mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:07 +01:00
Implement export filters for resources
This commit is contained in:
parent
a5ec4e5b36
commit
12e7552569
@ -22,8 +22,7 @@ class resources_egw_record implements importexport_iface_egw_record
|
|||||||
private $record = array();
|
private $record = array();
|
||||||
|
|
||||||
static $types = array(
|
static $types = array(
|
||||||
'select-account'=> array('creator', 'modifier'),
|
'date-time' => array(),
|
||||||
'date-time' => array('modified', 'created'),
|
|
||||||
'select-cat' => array('cat_id'),
|
'select-cat' => array('cat_id'),
|
||||||
'select-bool' => array('bookable'),
|
'select-bool' => array('bookable'),
|
||||||
// Links is field name => app name
|
// Links is field name => app name
|
||||||
|
@ -16,6 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
class resources_export_csv implements importexport_iface_export_plugin {
|
class resources_export_csv implements importexport_iface_export_plugin {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->bo = new resources_bo();
|
||||||
|
$this->get_selects();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports records as defined in $_definition
|
* Exports records as defined in $_definition
|
||||||
*
|
*
|
||||||
@ -24,7 +31,6 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
|||||||
public function export( $_stream, importexport_definition $_definition) {
|
public function export( $_stream, importexport_definition $_definition) {
|
||||||
$options = $_definition->plugin_options;
|
$options = $_definition->plugin_options;
|
||||||
|
|
||||||
$bo = new resources_bo();
|
|
||||||
$selection = array();
|
$selection = array();
|
||||||
if ($options['selection'] == 'selected') {
|
if ($options['selection'] == 'selected') {
|
||||||
// ui selection with checkbox 'selected'
|
// ui selection with checkbox 'selected'
|
||||||
@ -32,16 +38,42 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
|||||||
$query['num_rows'] = -1; // all
|
$query['num_rows'] = -1; // all
|
||||||
unset($query['store_state']);
|
unset($query['store_state']);
|
||||||
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
||||||
$bo->get_rows($query,$selection,$readonlys);
|
$this->bo->get_rows($query,$selection,$readonlys);
|
||||||
}
|
}
|
||||||
elseif ( $options['selection'] == 'all' ) {
|
elseif ( $options['selection'] == 'all' || $options['selection'] == 'filter') {
|
||||||
$query = array(
|
$query = array(
|
||||||
'num_rows' => -1,
|
'num_rows' => -1,
|
||||||
'filter2' => -3, // Accessories & resources
|
'filter2' => -3, // Accessories & resources
|
||||||
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
|
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
|
||||||
); // all
|
); // all
|
||||||
unset($query['store_state']);
|
|
||||||
$bo->get_rows($query,$selection,$readonlys);
|
if($options['selection'] == 'filter')
|
||||||
|
{
|
||||||
|
$filter = $_definition->filter;
|
||||||
|
// Handle ranges
|
||||||
|
foreach($filter as $field => $value)
|
||||||
|
{
|
||||||
|
if($field == 'cat_id')
|
||||||
|
{
|
||||||
|
$query['filter'] = $value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($field == 'filter2')
|
||||||
|
{
|
||||||
|
$query['filter2'] = $value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$query['col_filter'][$field] = $value;
|
||||||
|
if(!is_array($value) || (!$value['from'] && !$value['to'])) continue;
|
||||||
|
|
||||||
|
// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
|
||||||
|
if($value['from']) $query['col_filter'][] = "$field >= " . (int)$value['from'];
|
||||||
|
if($value['to']) $query['col_filter'][] = "$field <= " . (int)$value['to'];
|
||||||
|
unset($query['col_filter'][$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->bo->get_rows($query,$selection,$readonlys);
|
||||||
} else {
|
} else {
|
||||||
$selection = explode(',',$options['selection']);
|
$selection = explode(',',$options['selection']);
|
||||||
}
|
}
|
||||||
@ -57,20 +89,18 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$types = resources_egw_record::$types;
|
|
||||||
$types['select-bool'] = array('bookable');
|
|
||||||
|
|
||||||
foreach ($selection as $record) {
|
foreach ($selection as $record) {
|
||||||
if(!is_array($record) || !$record['res_id']) continue;
|
if(!is_array($record) || !$record['res_id']) continue;
|
||||||
|
|
||||||
if($need_custom) {
|
if($need_custom) {
|
||||||
$record = $bo->read($record['res_id']);
|
$record = $this->bo->read($record['res_id']);
|
||||||
}
|
}
|
||||||
$resource = new resources_egw_record();
|
$resource = new resources_egw_record();
|
||||||
$resource->set_record($record);
|
$resource->set_record($record);
|
||||||
$resource->long_description = strip_tags($resource->long_description);
|
$resource->long_description = strip_tags($resource->long_description);
|
||||||
if($options['convert']) {
|
if($options['convert']) {
|
||||||
importexport_export_csv::convert($resource, $types, 'resources');
|
importexport_export_csv::convert($resource, resources_egw_record::$types, 'resources', $this->selects);
|
||||||
} else {
|
} else {
|
||||||
// Implode arrays, so they don't say 'Array'
|
// Implode arrays, so they don't say 'Array'
|
||||||
foreach($resource->get_record_array() as $key => $value) {
|
foreach($resource->get_record_array() as $key => $value) {
|
||||||
@ -81,6 +111,7 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
|||||||
$export_object->export_record($resource);
|
$export_object->export_record($resource);
|
||||||
unset($resource);
|
unset($resource);
|
||||||
}
|
}
|
||||||
|
return $export_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,8 +159,40 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
|||||||
*/
|
*/
|
||||||
public function get_selectors_etpl() {
|
public function get_selectors_etpl() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'resources.export_csv_selectors',
|
'name' => 'importexport.export_csv_selectors',
|
||||||
'content' => 'selected'
|
'content' => 'selected'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get selectbox values
|
||||||
|
*/
|
||||||
|
protected function get_selects()
|
||||||
|
{
|
||||||
|
$this->selects = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize automatically generated filter fields
|
||||||
|
*/
|
||||||
|
public function get_filter_fields(Array &$filters)
|
||||||
|
{
|
||||||
|
// In resources, not all categories are used
|
||||||
|
$filters['cat_id']['type'] = 'select';
|
||||||
|
$filters['cat_id']['name'] = 'filter';
|
||||||
|
$filters['cat_id']['values']= (array)$this->bo->acl->get_cats(EGW_ACL_READ);
|
||||||
|
|
||||||
|
// Add in resources / accessories
|
||||||
|
$filters['filter2'] = array(
|
||||||
|
'name' => 'filter2',
|
||||||
|
'label' => 'Filter',
|
||||||
|
'type' => 'select',
|
||||||
|
'rows' => 5,
|
||||||
|
'values' => resources_bo::$filter_options
|
||||||
|
);
|
||||||
|
foreach($filters as $field_name => &$settings)
|
||||||
|
{
|
||||||
|
if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user