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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* export plugin of addressbook
|
|
|
|
*/
|
2010-03-22 16:12:01 +01:00
|
|
|
class timesheet_export_csv implements importexport_iface_export_plugin {
|
2007-03-08 12:22:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
2010-03-22 16:12:01 +01:00
|
|
|
public function export( $_stream, importexport_definition $_definition) {
|
|
|
|
$options = $_definition->plugin_options;
|
2007-03-08 12:22:57 +01:00
|
|
|
|
2010-03-22 16:12:01 +01:00
|
|
|
$uitimesheet = new timesheet_ui();
|
2007-03-08 12:22:57 +01:00
|
|
|
$selection = array();
|
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
if($options['selection'] == 'selected') {
|
|
|
|
$query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP);
|
|
|
|
$query['num_rows'] = -1; // all records
|
2012-03-29 14:08:42 +02:00
|
|
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
2011-01-26 00:55:57 +01:00
|
|
|
$uitimesheet->get_rows($query,$selection,$readonlys,true); // true = only return the id's
|
|
|
|
} elseif($options['selection'] == 'all') {
|
2012-03-29 14:08:42 +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
|
|
|
|
);
|
2011-01-26 00:55:57 +01:00
|
|
|
$uitimesheet->get_rows($query,$selection,$readonlys,true); // true = only return the id's
|
2012-03-29 14:08:42 +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
|
|
|
|
2011-03-28 19:53:53 +02:00
|
|
|
$lookups = array(
|
|
|
|
'ts_status' => $uitimesheet->status_labels+array(lang('No status'))
|
|
|
|
);
|
2011-03-30 01:38:22 +02:00
|
|
|
foreach($lookups['ts_status'] as &$status) {
|
2011-03-31 17:19:22 +02:00
|
|
|
$status = str_replace(' ','',$status); // Remove
|
2011-03-30 01:38:22 +02:00
|
|
|
}
|
2011-03-28 19:53:53 +02:00
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
// $options['selection'] is array of identifiers as this plugin doesn't
|
|
|
|
// support other selectors atm.
|
|
|
|
foreach ($selection as $identifier) {
|
2010-12-10 23:51:53 +01:00
|
|
|
$record = new timesheet_egw_record($identifier);
|
|
|
|
if($options['convert']) {
|
2011-04-04 19:01:17 +02:00
|
|
|
importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $lookups);
|
2010-12-10 23:51:53 +01:00
|
|
|
} else {
|
|
|
|
// Implode arrays, so they don't say 'Array'
|
|
|
|
foreach($record->get_record_array() as $key => $value) {
|
|
|
|
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-24 18:06:31 +02:00
|
|
|
return $export_object;
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
|
|
|
public static function get_name() {
|
|
|
|
return lang('Timesheet CSV export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function get_filesuffix() {
|
|
|
|
return 'csv';
|
|
|
|
}
|
|
|
|
|
2010-10-13 00:52:32 +02:00
|
|
|
public static function get_mimetype() {
|
|
|
|
return 'text/csv';
|
|
|
|
}
|
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
/**
|
|
|
|
* return html for options.
|
|
|
|
* this way the plugin has all opportunities for options tab
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
2010-03-22 16:12:01 +01:00
|
|
|
public function get_options_etpl() {
|
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
|
|
|
|
*
|
|
|
|
*/
|
2010-03-22 16:12:01 +01:00
|
|
|
public function get_selectors_etpl() {
|
2011-03-29 00:12:42 +02:00
|
|
|
return array(
|
|
|
|
'name' => 'timesheet.export_csv_selectors',
|
|
|
|
'content' => 'selected'
|
|
|
|
);
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
2010-03-22 16:12:01 +01:00
|
|
|
}
|