2010-10-13 19:25:40 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2015-06-22 11:17:00 +02:00
|
|
|
* EGroupware: iCal export plugin of calendar
|
2010-10-13 19:25:40 +02:00
|
|
|
*
|
|
|
|
* @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$
|
|
|
|
*/
|
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2010-10-13 19:25:40 +02:00
|
|
|
/**
|
2015-06-22 11:17:00 +02:00
|
|
|
* iCal export plugin of calendar
|
2010-10-13 19:25:40 +02:00
|
|
|
*/
|
|
|
|
class calendar_export_ical extends calendar_export_csv {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
$boical = new calendar_ical();
|
2011-05-30 19:23:46 +02:00
|
|
|
|
|
|
|
// Custom fields need to be specifically requested
|
|
|
|
$cfs = array();
|
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
|
|
|
|
if (!$limit_exception) $export_limit = Api\Storage\Merge::getExportLimit('calendar');
|
2011-08-17 17:38:56 +02:00
|
|
|
|
2018-12-05 19:13:29 +01:00
|
|
|
switch($options['selection'])
|
2013-01-23 17:10:17 +01:00
|
|
|
{
|
2018-12-05 19:13:29 +01:00
|
|
|
case 'criteria':
|
|
|
|
$query = array(
|
|
|
|
'start' => $options['criteria']['start'],
|
|
|
|
'end' => $options['criteria']['end'] ? strtotime('+1 day',$options['criteria']['end'])-1 : null,
|
|
|
|
'categories' => $options['categories'],
|
|
|
|
'daywise' => false,
|
|
|
|
'users' => $options['criteria']['owner'],
|
|
|
|
'cfs' => $cfs // Otherwise we shouldn't get any custom fields
|
|
|
|
);
|
|
|
|
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) {
|
|
|
|
$query['offset'] = 0;
|
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
|
|
|
}
|
|
|
|
$events =& $this->bo->search($query);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'search_results':
|
|
|
|
$states = $this->bo->cal_prefs['saved_states'];
|
|
|
|
$query = Api\Cache::getSession('calendar', 'calendar_list');
|
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
|
|
|
$query['start'] = 0;
|
|
|
|
$query['cfs'] = $cfs;
|
|
|
|
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
|
|
|
|
{
|
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
|
|
|
}
|
|
|
|
$ui = new calendar_uilist();
|
|
|
|
if($states['view'] == 'listview')
|
|
|
|
{
|
|
|
|
$ui->get_rows($query, $events, $unused);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query['filter'] = 'custom';
|
|
|
|
$events = array();
|
|
|
|
|
|
|
|
$ui->get_rows($query, $events, $unused);
|
|
|
|
}
|
|
|
|
// Filter out extra things like sel_options
|
|
|
|
unset($events['sel_options']);
|
|
|
|
break;
|
|
|
|
case 'filter':
|
|
|
|
$fields = importexport_helper_functions::get_filter_fields($_definition->application, $this);
|
|
|
|
$filter = $_definition->filter;
|
|
|
|
|
|
|
|
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
|
|
|
|
{
|
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle ranges
|
|
|
|
foreach($filter as $field => $value)
|
|
|
|
{
|
|
|
|
if($field == 'filter' && $value)
|
|
|
|
{
|
|
|
|
$query['filter'] = $value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!is_array($value) || (!$value['from'] && !$value['to']))
|
|
|
|
{
|
|
|
|
$query['query']["cal_$field"] = $value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
|
|
|
|
if($value['from']) $query['sql_filter'][] = "cal_$field >= " . (int)$value['from'];
|
|
|
|
if($value['to']) $query['sql_filter'][] = "cal_$field <= " . (int)$value['to'];
|
|
|
|
|
|
|
|
}
|
|
|
|
if($query['sql_filter'] && is_array($query['sql_filter']))
|
|
|
|
{
|
|
|
|
// Set as an extra parameter
|
|
|
|
$sql_filter = implode(' AND ',$query['sql_filter']);
|
|
|
|
}
|
|
|
|
// Fall through
|
|
|
|
|
|
|
|
case 'all':
|
|
|
|
$events = $this->bo->search($query + array(
|
|
|
|
'offset' => 0,
|
|
|
|
'order' => 'cal_start',
|
|
|
|
),$sql_filter);
|
|
|
|
break;
|
2011-05-30 19:23:46 +02:00
|
|
|
}
|
2015-06-22 11:17:00 +02:00
|
|
|
// compile list of unique cal_id's, as iCal should contain whole series, not recurrences
|
|
|
|
// calendar_ical->exportVCal needs to read events again, to get them in server-time
|
|
|
|
$ids = array();
|
|
|
|
foreach($events as $event)
|
|
|
|
{
|
|
|
|
$id = is_array($event) ? $event['id'] : $event;
|
|
|
|
if (($id = (int)$id)) $ids[$id] = $id;
|
|
|
|
}
|
2011-05-30 19:23:46 +02:00
|
|
|
|
2015-06-22 11:17:00 +02:00
|
|
|
$ical =& $boical->exportVCal($ids,'2.0','PUBLISH',false);
|
2010-10-13 19:25:40 +02:00
|
|
|
fwrite($_stream, $ical);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
|
|
|
public static function get_name() {
|
|
|
|
return lang('Calendar iCal export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
|
|
|
public static function get_description() {
|
|
|
|
return lang("Exports events from your Calendar in iCal format.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retruns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
|
|
|
public static function get_filesuffix() {
|
|
|
|
return 'ics';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_mimetype() {
|
|
|
|
return 'text/calendar';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-29 18:32:42 +01:00
|
|
|
* Return array of settings for export dialog
|
2010-10-13 19:25:40 +02: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,
|
|
|
|
* )
|
2010-10-13 19:25:40 +02:00
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function get_options_etpl(importexport_definition &$definition = NULL)
|
|
|
|
{
|
|
|
|
return false;
|
2010-10-13 19:25:40 +02:00
|
|
|
}
|
2018-12-05 19:13:29 +01:00
|
|
|
|
2010-10-13 19:25:40 +02:00
|
|
|
/**
|
|
|
|
* returns selectors of this plugin
|
|
|
|
*
|
|
|
|
*/
|
2013-01-21 19:59:33 +01:00
|
|
|
public function get_selectors_etpl($definition = null) {
|
|
|
|
$data = parent::get_selectors_etpl($definition);
|
|
|
|
return $data;
|
2010-10-13 19:25:40 +02:00
|
|
|
}
|
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 'calendar_egw_record';
|
|
|
|
}
|
2010-10-13 19:25:40 +02:00
|
|
|
}
|