Implement export filters

This commit is contained in:
Nathan Gray 2012-12-31 20:38:00 +00:00
parent 0a91bc5aa9
commit ee6834ca54
4 changed files with 71 additions and 15 deletions

View File

@ -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'),
);

View File

@ -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
*

View File

@ -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',);

View File

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!-- $Id$ -->
<overlay>
<template id="infolog.export_csv_selectors" template="" lang="" group="0" version="1.9.002">
<grid>
<columns>
<column/>
</columns>
<rows>
<row>
<radio label="Use all" id="selection" options="all"/>
</row>
<row>
<radio label="Use search results" id="selection" options="search"/>
</row>
<row>
<radio label="Use definition filter" id="selection" onclick="\$j('div.filters').show();" options="filter"/>
</row>
</rows>
</grid>
</template>
</overlay>