mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-22 21:30:54 +01:00
- Implement export filters for resouces
- Stop using a preference for export selection default. If the definition has a filter set, use filter, otherwise default to search results
This commit is contained in:
parent
ccffcf171e
commit
24a00e706b
@ -230,11 +230,6 @@ class importexport_export_ui {
|
||||
}
|
||||
else
|
||||
{
|
||||
if($definition->filter)
|
||||
{
|
||||
$content['selection'] = 'filter';
|
||||
}
|
||||
|
||||
// Process relative dates into the current absolute date
|
||||
foreach($content['filter']['fields'] as $field => $settings)
|
||||
{
|
||||
@ -251,27 +246,25 @@ class importexport_export_ui {
|
||||
");
|
||||
}
|
||||
|
||||
// Disable / hide definition filter if not selected
|
||||
if($content['selection'] !== 'filter')
|
||||
{
|
||||
$this->js->set_onload("
|
||||
\$j('div.filters').hide();
|
||||
");
|
||||
}
|
||||
$preserv['old_definition'] = $content['definition'];
|
||||
|
||||
// If not set by plugin, pre-set selection to preference, or 'search'
|
||||
if (($prefs = $GLOBALS['egw_info']['user']['preferences']['importexport'][$definition->definition_id]) &&
|
||||
($prefs = unserialize($prefs)) && !$content['selection']['plugin_override'])
|
||||
// If not set by plugin, pre-set selection to filter if definition has one, or 'search'
|
||||
if (!$content['selection'] && $definition->filter)
|
||||
{
|
||||
$selection = $content['selection'];
|
||||
$content = array_merge_recursive($content,$prefs);
|
||||
$content['selection'] = $prefs['selection'] ? $prefs['selection'] : $selection;
|
||||
$content['selection'] = 'filter';
|
||||
}
|
||||
if(!$content['selection'])
|
||||
{
|
||||
$content['selection'] = 'search';
|
||||
}
|
||||
|
||||
// Disable / hide definition filter if not selected
|
||||
if($content['selection'] != 'filter')
|
||||
{
|
||||
$this->js->set_onload("
|
||||
\$j('div.filters').hide();
|
||||
");
|
||||
}
|
||||
unset ($plugin_object);
|
||||
$apps = importexport_helper_functions::get_apps('export');
|
||||
//error_log(__METHOD__.__LINE__.array2string($apps));
|
||||
@ -383,12 +376,6 @@ class importexport_export_ui {
|
||||
}
|
||||
}
|
||||
|
||||
// Keep settings
|
||||
$keep = array_diff_key($_content, array_flip(array('appname', 'definition', 'plugin', 'preview', 'export', $tabs)));
|
||||
$GLOBALS['egw']->preferences->add('importexport',$definition->definition_id,serialize($keep));
|
||||
// save prefs, but do NOT invalid the cache (unnecessary)
|
||||
$GLOBALS['egw']->preferences->save_repository(false,'user',false);
|
||||
|
||||
// Store charset to use in header
|
||||
egw_cache::setSession('importexport', $tmpfname, $charset, 100);
|
||||
|
||||
|
@ -22,8 +22,7 @@ class resources_egw_record implements importexport_iface_egw_record
|
||||
private $record = array();
|
||||
|
||||
static $types = array(
|
||||
'select-account'=> array('creator', 'modifier'),
|
||||
'date-time' => array('modified', 'created'),
|
||||
'date-time' => array(),
|
||||
'select-cat' => array('cat_id'),
|
||||
'select-bool' => array('bookable'),
|
||||
// Links is field name => app name
|
||||
|
@ -16,6 +16,13 @@
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -24,24 +31,49 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
||||
public function export( $_stream, importexport_definition $_definition) {
|
||||
$options = $_definition->plugin_options;
|
||||
|
||||
$bo = new resources_bo();
|
||||
$selection = array();
|
||||
if ($options['selection'] == 'selected') {
|
||||
if ($options['selection'] == 'search') {
|
||||
// ui selection with checkbox 'selected'
|
||||
$query = egw_cache::getSession('resources', 'get_rows');
|
||||
$query['num_rows'] = -1; // all
|
||||
unset($query['store_state']);
|
||||
$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(
|
||||
'num_rows' => -1,
|
||||
'filter2' => -3, // Accessories & resources
|
||||
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
|
||||
); // 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 {
|
||||
$selection = explode(',',$options['selection']);
|
||||
}
|
||||
@ -57,20 +89,18 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$types = resources_egw_record::$types;
|
||||
$types['select-bool'] = array('bookable');
|
||||
|
||||
foreach ($selection as $record) {
|
||||
if(!is_array($record) || !$record['res_id']) continue;
|
||||
|
||||
if($need_custom) {
|
||||
$record = $bo->read($record['res_id']);
|
||||
$record = $this->bo->read($record['res_id']);
|
||||
}
|
||||
$resource = new resources_egw_record();
|
||||
$resource->set_record($record);
|
||||
$resource->long_description = strip_tags($resource->long_description);
|
||||
if($options['convert']) {
|
||||
importexport_export_csv::convert($resource, $types, 'resources');
|
||||
importexport_export_csv::convert($resource, resources_egw_record::$types, 'resources', $this->selects);
|
||||
} else {
|
||||
// Implode arrays, so they don't say 'Array'
|
||||
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);
|
||||
unset($resource);
|
||||
}
|
||||
return $export_object;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,8 +159,39 @@ class resources_export_csv implements importexport_iface_export_plugin {
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return array(
|
||||
'name' => 'resources.export_csv_selectors',
|
||||
'content' => 'selected'
|
||||
'name' => 'importexport.export_csv_selectors',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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