diff --git a/timesheet/inc/class.timesheet_export_csv.inc.php b/timesheet/inc/class.timesheet_export_csv.inc.php index 54517fe1c2..5086f497c1 100644 --- a/timesheet/inc/class.timesheet_export_csv.inc.php +++ b/timesheet/inc/class.timesheet_export_csv.inc.php @@ -16,6 +16,12 @@ */ class timesheet_export_csv implements importexport_iface_export_plugin { + public function __construct() + { + $this->ui = new timesheet_ui(); + $this->get_selects(); + } + /** * Exports records as defined in $_definition * @@ -24,20 +30,48 @@ class timesheet_export_csv implements importexport_iface_export_plugin { public function export( $_stream, importexport_definition $_definition) { $options = $_definition->plugin_options; - $uitimesheet = new timesheet_ui(); + $this->ui = new timesheet_ui(); $selection = array(); if($options['selection'] == 'selected') { $query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP); $query['num_rows'] = -1; // all records $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session - $uitimesheet->get_rows($query,$selection,$readonlys,true); // true = only return the id's + $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's } elseif($options['selection'] == 'all') { $query = array( 'num_rows' => -1, 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session ); - $uitimesheet->get_rows($query,$selection,$readonlys,true); // true = only return the id's + $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's + } + else if($options['selection'] == 'filter') + { + $fields = importexport_helper_functions::get_filter_fields($_definition->application, $this); + $filter = $_definition->filter; + $query = array( + 'num_rows' => -1, + 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session + 'col_filter' => array() + ); + + // Handle ranges + foreach($filter as $field => $value) + { + if($field == 'cat_id') + { + $query['cat_id'] = $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->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's } @@ -45,19 +79,12 @@ class timesheet_export_csv implements importexport_iface_export_plugin { $export_object = new importexport_export_csv($_stream, (array)$options); $export_object->set_mapping($options['mapping']); - $lookups = array( - 'ts_status' => $uitimesheet->status_labels+array(lang('No status')) - ); - foreach($lookups['ts_status'] as &$status) { - $status = str_replace(' ','',$status); // Remove   - } - // $options['selection'] is array of identifiers as this plugin doesn't // support other selectors atm. foreach ($selection as $identifier) { $record = new timesheet_egw_record($identifier); if($options['convert']) { - importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $lookups); + importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects); } else { // Implode arrays, so they don't say 'Array' foreach($record->get_record_array() as $key => $value) { @@ -117,8 +144,30 @@ class timesheet_export_csv implements importexport_iface_export_plugin { */ public function get_selectors_etpl() { return array( - 'name' => 'timesheet.export_csv_selectors', + 'name' => 'importexport.export_csv_selectors', 'content' => 'selected' ); } + + public function get_selects() + { + $this->selects = array( + 'ts_status' => $this->ui->status_labels+array(lang('No status')) + ); + foreach($this->selects['ts_status'] as &$status) { + $status = str_replace(' ','',$status); // Remove   + } + + } + /** + * Adjust the automatically generated filter fields + */ + public function get_filter_fields(Array &$filters) + { + foreach($filters as $field_name => &$settings) + { + if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; + } + } + } diff --git a/timesheet/inc/class.timesheet_wizard_export_csv.inc.php b/timesheet/inc/class.timesheet_wizard_export_csv.inc.php index 8ae75fea0e..d712e69786 100644 --- a/timesheet/inc/class.timesheet_wizard_export_csv.inc.php +++ b/timesheet/inc/class.timesheet_wizard_export_csv.inc.php @@ -17,7 +17,7 @@ class timesheet_wizard_export_csv extends importexport_wizard_basic_export_csv // Field mapping $bo = new timesheet_bo(); - $this->export_fields = array('ts_id' => 'Timesheet ID') + $bo->field2label; + $this->export_fields = array('ts_id' => 'Timesheet ID') + $bo->field2label + array('ts_modified'=> 'Modified'); // Custom fields unset($this->export_fields['customfields']);