2010-10-13 00:45:02 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package calendar
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* export CSV plugin of calendar
|
|
|
|
*/
|
|
|
|
class calendar_export_csv implements importexport_iface_export_plugin {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
|
|
|
public function export( $_stream, importexport_definition $_definition) {
|
|
|
|
$options = $_definition->plugin_options;
|
|
|
|
$this->bo = new calendar_bo();
|
2011-02-23 21:48:57 +01:00
|
|
|
|
|
|
|
// Custom fields need to be specifically requested
|
|
|
|
$cfs = array();
|
|
|
|
foreach($options['mapping'] as $key => $label) {
|
|
|
|
if($key[0] == '#') $cfs[] = substr($key,1);
|
|
|
|
}
|
|
|
|
$query = array(
|
2010-10-13 00:45:02 +02:00
|
|
|
'start' => $options['selection']['start'],
|
|
|
|
'end' => $options['selection']['end'],
|
|
|
|
'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'],
|
|
|
|
'enum_recuring' => false,
|
|
|
|
'daywise' => false,
|
|
|
|
'owner' => $options['owner'],
|
2011-02-23 21:48:57 +01:00
|
|
|
'cfs' => $cfs // Otherwise we shouldn't get any custom fields
|
|
|
|
);
|
|
|
|
$config = config::read('phpgwapi');
|
|
|
|
if($config['export_limit']) {
|
|
|
|
$query['offset'] = 0;
|
|
|
|
$query['num_rows'] = (int)$config['export_limit'];
|
|
|
|
}
|
|
|
|
$events =& $this->bo->search($query);
|
2010-10-13 00:45:02 +02:00
|
|
|
|
|
|
|
$export_object = new importexport_export_csv($_stream, (array)$options);
|
|
|
|
$export_object->set_mapping($options['mapping']);
|
2010-11-04 18:27:08 +01:00
|
|
|
$convert_fields = importexport_export_csv::$types;
|
2010-11-09 20:05:40 +01:00
|
|
|
$convert_fields['select-account'][] = 'owner';
|
2010-11-04 18:27:08 +01:00
|
|
|
$convert_fields['date-time'][] = 'start';
|
|
|
|
$convert_fields['date-time'][] = 'end';
|
|
|
|
|
2010-11-09 20:26:25 +01:00
|
|
|
$recurrence = $this->bo->recur_types;
|
2010-10-13 00:45:02 +02:00
|
|
|
|
|
|
|
// $options['selection'] is array of identifiers as this plugin doesn't
|
|
|
|
// support other selectors atm.
|
|
|
|
$record = new calendar_egw_record();
|
|
|
|
foreach ($events as $event) {
|
2010-11-04 18:27:08 +01:00
|
|
|
// Add in participants
|
|
|
|
if($options['mapping']['participants']) {
|
|
|
|
$event['participants'] = implode(", ",$this->bo->participants($event,true));
|
|
|
|
}
|
|
|
|
|
2010-10-13 00:45:02 +02:00
|
|
|
$record->set_record($event);
|
2010-11-09 20:26:25 +01:00
|
|
|
if($options['mapping']['recurrence']) {
|
|
|
|
$record->recurrence = $recurrence[$record->recur_type];
|
|
|
|
if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval;
|
|
|
|
}
|
|
|
|
|
2010-11-04 18:27:08 +01:00
|
|
|
// Standard stuff
|
2010-11-23 00:44:31 +01:00
|
|
|
if($options['convert']) {
|
|
|
|
importexport_export_csv::convert($record, $convert_fields, 'calendar');
|
2010-12-10 23:54:27 +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);
|
|
|
|
}
|
|
|
|
}
|
2010-11-09 20:26:25 +01:00
|
|
|
|
2010-10-13 00:45:02 +02:00
|
|
|
$export_object->export_record($record);
|
|
|
|
}
|
|
|
|
unset($record);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
|
|
|
public static function get_name() {
|
|
|
|
return lang('Calendar CSV export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
|
|
|
public static function get_description() {
|
|
|
|
return lang("Exports events from your Calendar into a CSV File.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retruns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
|
|
|
public static function get_filesuffix() {
|
|
|
|
return 'csv';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_mimetype() {
|
|
|
|
return 'text/csv';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return html for options.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_options_etpl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns selectors of this plugin
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_selectors_etpl() {
|
2011-03-14 21:39:59 +01:00
|
|
|
$states = $GLOBALS['egw']->session->appsession('session_data','calendar');
|
2010-10-13 00:45:02 +02:00
|
|
|
return array(
|
|
|
|
'name' => 'calendar.export_csv_select',
|
|
|
|
'content' => array(
|
|
|
|
'start' => time(),
|
2011-03-14 21:39:59 +01:00
|
|
|
'end' => time(),
|
|
|
|
'owner' => $states['owner']
|
2010-10-13 00:45:02 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|