From ee6834ca54d81da4aeac876eebcf24dac9ff85ff Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 31 Dec 2012 20:38:00 +0000 Subject: [PATCH] Implement export filters --- infolog/inc/class.infolog_egw_record.inc.php | 6 +-- infolog/inc/class.infolog_export_csv.inc.php | 54 +++++++++++++++---- infolog/setup/etemplates.inc.php | 4 +- .../default/export_csv_selectors.xet | 22 ++++++++ 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 infolog/templates/default/export_csv_selectors.xet diff --git a/infolog/inc/class.infolog_egw_record.inc.php b/infolog/inc/class.infolog_egw_record.inc.php index 7ed15f1454..8910b5a21b 100644 --- a/infolog/inc/class.infolog_egw_record.inc.php +++ b/infolog/inc/class.infolog_egw_record.inc.php @@ -24,10 +24,10 @@ class infolog_egw_record implements importexport_iface_egw_record // Used in conversions static $types = array( + 'select' => array('info_type', 'info_status', 'info_priority', 'info_pricelist'), + 'select-cat' => array('info_cat'), 'select-account' => array('info_owner','info_responsible','modifier'), - 'select' => array('info_priority', 'info_type', 'info_status','info_pricelist'), - 'date-time' => array('info_startdate', 'info_enddate','info_datecompleted', 'info_datemodified','created','last_event','next_event'), - 'select-cat' => array('info_cat', 'cat_id'), + 'date-time' => array('info_startdate', 'info_enddate','info_datecompleted', 'info_datemodified','info_created'), 'links' => array('info_link_id'), ); diff --git a/infolog/inc/class.infolog_export_csv.inc.php b/infolog/inc/class.infolog_export_csv.inc.php index 8e42dd3ac8..1eb634c6a8 100644 --- a/infolog/inc/class.infolog_export_csv.inc.php +++ b/infolog/inc/class.infolog_export_csv.inc.php @@ -17,6 +17,12 @@ class infolog_export_csv implements importexport_iface_export_plugin { + public function __construct() { + translation::add_app('infolog'); + $this->bo = new infolog_bo(); + $this->get_selects(); + } + /** * Exports records as defined in $_definition * @@ -25,23 +31,15 @@ class infolog_export_csv implements importexport_iface_export_plugin { public function export( $_stream, importexport_definition $_definition) { $options = $_definition->plugin_options; - translation::add_app('infolog'); - $this->bo = new infolog_bo(); $selection = array(); $query = array(); $cf_links = array(); - if(!$this->selects) - { - $this->selects['info_type'] = $this->bo->enums['type']; - $this->selects['info_priority'] = $this->bo->enums['priority']; - } - $this->export_object = new importexport_export_csv($_stream, (array)$options); $this->export_object->set_mapping($options['mapping']); // do we need to query the cf's - foreach($options['mapping'] as $field => $map) { + foreach($options['mapping'] + (array)$_definition->filter as $field => $map) { if($field[0] == '#') { $query['custom_fields'][] = $field; @@ -56,9 +54,26 @@ class infolog_export_csv implements importexport_iface_export_plugin { switch($options['selection']) { case 'search': - $query = array_merge($GLOBALS['egw']->session->appsession('session_data','infolog'), $query); + $query = array_merge((array)$GLOBALS['egw']->session->appsession('session_data','infolog'), $query); // Fall through + case 'filter': case 'all': + if($options['selection'] == 'filter') + { + $fields = importexport_helper_functions::get_filter_fields($_definition->application, $this); + $query['col_filter'] = $_definition->filter; + + // Handle ranges + foreach($query['col_filter'] as $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]); + } + } $query['num_rows'] = 500; $query['start'] = 0; do { @@ -215,6 +230,25 @@ class infolog_export_csv implements importexport_iface_export_plugin { ); } + protected function get_selects() + { + $this->selects['info_type'] = $this->bo->enums['type']; + $this->selects['info_priority'] = $this->bo->enums['priority']; + $this->selects['info_pricelist'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist',false); + $this->selects['info_status'] = $this->bo->get_status(); + } + + public function get_filter_fields(Array &$filters) + { + foreach($filters as $field_name => &$settings) + { + if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; + + // Infolog can't handle ranges in custom fields due to the way searching is done. + if(strpos($field_name, '#') === 0 && strpos($settings['type'],'date') === 0) unset($filters[$field_name]); + } + } + /** * Convert some internal data to something with more meaning * diff --git a/infolog/setup/etemplates.inc.php b/infolog/setup/etemplates.inc.php index 1f1ee89699..5e90842799 100644 --- a/infolog/setup/etemplates.inc.php +++ b/infolog/setup/etemplates.inc.php @@ -2,7 +2,7 @@ /** * EGroupware - eTemplates for Application infolog * http://www.egroupware.org - * generated by soetemplate::dump4setup() 2012-11-14 12:38 + * generated by soetemplate::dump4setup() 2012-12-31 11:22 * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package infolog @@ -65,7 +65,7 @@ $templ_data[] = array('name' => 'infolog.edit.project','template' => '','lang' = $templ_data[] = array('name' => 'infolog.export_csv_options','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:4:{i:0;a:1:{s:1:"B";s:5:"180px";}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:3:"msg";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:14:"Fieldseperator";}s:1:"B";a:4:{s:4:"type";s:4:"text";s:7:"no_lang";s:1:"1";s:4:"name";s:9:"delimiter";s:4:"size";s:1:"1";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:14:"Include header";}s:1:"B";a:2:{s:4:"type";s:11:"select-bool";s:4:"name";s:21:"begin_with_fieldnames";}}}s:4:"rows";i:3;s:4:"cols";i:2;}}','size' => '','style' => '.width180 select { width:150px;}','modified' => '1289231885',); -$templ_data[] = array('name' => 'infolog.export_csv_selectors','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:7:"Use all";s:4:"size";s:3:"all";s:4:"name";s:9:"selection";}}i:2;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:18:"Use search results";s:4:"name";s:9:"selection";s:4:"size";s:6:"search";}}}s:4:"rows";i:2;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1289231918',); +$templ_data[] = array('name' => 'infolog.export_csv_selectors','template' => '','lang' => '','group' => '0','version' => '1.9.002','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:4:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:7:"Use all";s:4:"size";s:3:"all";s:4:"name";s:9:"selection";}}i:2;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:18:"Use search results";s:4:"name";s:9:"selection";s:4:"size";s:6:"search";}}i:3;a:1:{s:1:"A";a:5:{s:4:"type";s:5:"radio";s:5:"label";s:21:"Use definition filter";s:4:"name";s:9:"selection";s:4:"size";s:6:"filter";s:7:"onclick";s:26:"\\$j(\'div.filters\').show();";}}}s:4:"rows";i:3;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1356978125',); $templ_data[] = array('name' => 'infolog.importexport_wizard_chooseowner','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:6:{i:0;a:1:{s:2:"h2";s:14:",@no_owner_map";}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"checkbox";s:5:"label";s:30:"Use field from CSV if possible";s:4:"name";s:14:"owner_from_csv";}}i:3;a:1:{s:1:"A";a:2:{s:4:"type";s:14:"select-account";s:4:"name";s:12:"record_owner";}}i:4;a:1:{s:1:"A";a:1:{s:4:"type";s:5:"label";}}i:5;a:1:{s:1:"A";a:3:{s:4:"type";s:11:"select-bool";s:5:"label";s:26:"Change owner when updating";s:4:"name";s:12:"change_owner";}}}s:4:"rows";i:5;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1286389863',); diff --git a/infolog/templates/default/export_csv_selectors.xet b/infolog/templates/default/export_csv_selectors.xet new file mode 100644 index 0000000000..440e9ffab6 --- /dev/null +++ b/infolog/templates/default/export_csv_selectors.xet @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file