2007-03-08 12:22:57 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package timesheet
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Knut Moeller <k.moeller@metaways.de>
|
|
|
|
* @copyright Knut Moeller <k.moeller@metaways.de>
|
2011-01-26 00:55:57 +01:00
|
|
|
* @version $Id$
|
2007-03-08 12:22:57 +01:00
|
|
|
*/
|
|
|
|
|
2016-10-12 16:12:57 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
/**
|
|
|
|
* export plugin of addressbook
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
class timesheet_export_csv implements importexport_iface_export_plugin
|
|
|
|
{
|
2007-03-08 12:22:57 +01:00
|
|
|
|
2013-01-22 23:19:46 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->ui = new timesheet_ui();
|
|
|
|
$this->get_selects();
|
|
|
|
}
|
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function export( $_stream, importexport_definition $_definition)
|
|
|
|
{
|
2010-03-22 16:12:01 +01:00
|
|
|
$options = $_definition->plugin_options;
|
2007-03-08 12:22:57 +01:00
|
|
|
|
2013-01-22 23:19:46 +01:00
|
|
|
$this->ui = new timesheet_ui();
|
2007-03-08 12:22:57 +01:00
|
|
|
$selection = array();
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
if($options['selection'] == 'search')
|
|
|
|
{
|
2016-10-12 16:12:57 +02:00
|
|
|
$query = Api\Cache::getSession(TIMESHEET_APP, 'index');
|
2011-01-26 00:55:57 +01:00
|
|
|
$query['num_rows'] = -1; // all records
|
2012-03-29 14:06:10 +02:00
|
|
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
2013-01-22 23:19:46 +01:00
|
|
|
$this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's
|
2018-11-29 18:32:42 +01:00
|
|
|
}
|
|
|
|
elseif($options['selection'] == 'all')
|
|
|
|
{
|
2012-03-29 14:06:10 +02:00
|
|
|
$query = array(
|
|
|
|
'num_rows' => -1,
|
|
|
|
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
|
|
|
|
);
|
2013-01-22 23:19:46 +01:00
|
|
|
$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
|
2012-03-29 14:06:10 +02:00
|
|
|
}
|
2007-03-08 12:22:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
$options['begin_with_fieldnames'] = true;
|
2010-03-22 16:12:01 +01:00
|
|
|
$export_object = new importexport_export_csv($_stream, (array)$options);
|
2011-03-02 18:26:03 +01:00
|
|
|
$export_object->set_mapping($options['mapping']);
|
2007-03-08 12:22:57 +01:00
|
|
|
|
|
|
|
// $options['selection'] is array of identifiers as this plugin doesn't
|
|
|
|
// support other selectors atm.
|
2018-11-29 18:32:42 +01:00
|
|
|
foreach ($selection as $identifier)
|
|
|
|
{
|
2010-12-10 23:51:53 +01:00
|
|
|
$record = new timesheet_egw_record($identifier);
|
2018-11-29 18:32:42 +01:00
|
|
|
if($options['convert'])
|
|
|
|
{
|
2013-01-22 23:19:46 +01:00
|
|
|
importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects);
|
2018-11-29 18:32:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-10 23:51:53 +01:00
|
|
|
// Implode arrays, so they don't say 'Array'
|
2018-11-29 18:32:42 +01:00
|
|
|
foreach($record->get_record_array() as $key => $value)
|
|
|
|
{
|
2010-12-10 23:51:53 +01:00
|
|
|
if(is_array($value)) $record->$key = implode(',', $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$export_object->export_record($record);
|
|
|
|
unset($record);
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
2012-04-18 20:00:21 +02:00
|
|
|
return $export_object;
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_name()
|
|
|
|
{
|
2007-03-08 12:22:57 +01:00
|
|
|
return lang('Timesheet CSV export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_description()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return lang("Exports entries from your Timesheet into a CSV File. ");
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_filesuffix()
|
|
|
|
{
|
2007-03-08 12:22:57 +01:00
|
|
|
return 'csv';
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_mimetype()
|
|
|
|
{
|
|
|
|
return 'text/csv';
|
|
|
|
}
|
2010-10-13 00:52:32 +02:00
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
/**
|
2018-11-29 18:32:42 +01:00
|
|
|
* Return array of settings for export dialog
|
2007-03-08 12:22:57 +01:00
|
|
|
*
|
2018-11-29 18:32:42 +01:00
|
|
|
* @param $definition Specific definition
|
|
|
|
*
|
|
|
|
* @return array (
|
|
|
|
* name => string,
|
|
|
|
* content => array,
|
|
|
|
* sel_options => array,
|
|
|
|
* readonlys => array,
|
|
|
|
* preserv => array,
|
|
|
|
* )
|
2007-03-08 12:22:57 +01:00
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function get_options_etpl(importexport_definition &$definition = NULL)
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return false;
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns slectors of this plugin via xajax
|
|
|
|
*
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function get_selectors_etpl()
|
|
|
|
{
|
2011-03-29 00:12:42 +02:00
|
|
|
return array(
|
2013-01-22 23:19:46 +01:00
|
|
|
'name' => 'importexport.export_csv_selectors',
|
2011-03-29 00:12:42 +02:00
|
|
|
);
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
2013-01-22 23:19:46 +01:00
|
|
|
|
|
|
|
public function get_selects()
|
|
|
|
{
|
|
|
|
$this->selects = array(
|
|
|
|
'ts_status' => $this->ui->status_labels+array(lang('No status'))
|
|
|
|
);
|
2018-11-29 18:32:42 +01:00
|
|
|
foreach($this->selects['ts_status'] as &$status)
|
|
|
|
{
|
2013-01-22 23:19:46 +01:00
|
|
|
$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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 21:34:30 +02:00
|
|
|
/**
|
|
|
|
* Get the class name for the egw_record to use while exporting
|
|
|
|
*
|
|
|
|
* @return string;
|
|
|
|
*/
|
|
|
|
public static function get_egw_record_class()
|
|
|
|
{
|
|
|
|
return 'timesheet_egw_record';
|
|
|
|
}
|
2010-03-22 16:12:01 +01:00
|
|
|
}
|