mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-24 15:49:06 +01:00
- Add participant filter
- Change event status filter to one only, since multiple doesn't work - Allow overriding of label, tag & multiple in filter
This commit is contained in:
parent
a26e0717b5
commit
15c94135bc
@ -32,11 +32,72 @@ class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
public function export( $_stream, importexport_definition $_definition) {
|
||||
$options = $_definition->plugin_options;
|
||||
|
||||
$events = $this->get_events($_definition, $options);
|
||||
|
||||
$export_object = new importexport_export_csv($_stream, (array)$options);
|
||||
if (!$limit_exception)
|
||||
{
|
||||
$export_object->export_limit = $export_limit;
|
||||
}
|
||||
$export_object->set_mapping($options['mapping']);
|
||||
$convert_fields = calendar_egw_record::$types;
|
||||
|
||||
$record = new calendar_egw_record();
|
||||
foreach ($events as $event)
|
||||
{
|
||||
// the condition below (2 lines) may only work on enum_recuring=false and using the iterator to test an recurring event on the given timerange
|
||||
// Get rid of yearly recurring events that don't belong
|
||||
//if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue;
|
||||
// Add in participants
|
||||
if($options['mapping']['participants'])
|
||||
{
|
||||
if(is_array($event['participants']))
|
||||
{
|
||||
$event['participants'] = implode(", ",$this->bo->participants($event,true));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Getting results from list already has participants formatted
|
||||
$event['participants'] = str_replace("\n", ' ', $event['participants']);
|
||||
}
|
||||
}
|
||||
if (is_array($event))
|
||||
{
|
||||
$record->set_record($event);
|
||||
if($options['mapping']['recurrence'])
|
||||
{
|
||||
$rrule = calendar_rrule::event2rrule($event);
|
||||
$record->recurrence = $rrule->__toString();
|
||||
}
|
||||
|
||||
// Standard stuff
|
||||
if($options['convert'])
|
||||
{
|
||||
importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects);
|
||||
}
|
||||
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);
|
||||
return $export_object;
|
||||
}
|
||||
|
||||
protected function get_events(importexport_definition $_definition, $options = array())
|
||||
{
|
||||
$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
|
||||
if (!$limit_exception) $export_limit = Api\Storage\Merge::getExportLimit('calendar');
|
||||
|
||||
// Custom fields need to be specifically requested
|
||||
$cfs = array();
|
||||
foreach($options['mapping'] + (array)$_definition->filter as $key => $label) {
|
||||
foreach((array)$options['mapping'] + (array)$_definition->filter as $key => $label) {
|
||||
if($key[0] == '#') $cfs[] = substr($key,1);
|
||||
}
|
||||
|
||||
@ -102,12 +163,17 @@ class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
// Handle ranges
|
||||
foreach($filter as $field => $value)
|
||||
{
|
||||
if($field == 'filter' && $value)
|
||||
if($field == 'status_filter' && $value)
|
||||
{
|
||||
$query['filter'] = $value;
|
||||
continue;
|
||||
}
|
||||
if(!is_array($value) || (!$value['from'] && !$value['to']))
|
||||
else if($field == 'users' && $value)
|
||||
{
|
||||
// No cal_ prefix here
|
||||
$query['users'] = $value;
|
||||
}
|
||||
else if(!is_array($value) || (!$value['from'] && !$value['to']))
|
||||
{
|
||||
$query['query']["cal_$field"] = $value;
|
||||
continue;
|
||||
@ -131,61 +197,7 @@ class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
),$sql_filter);
|
||||
break;
|
||||
}
|
||||
|
||||
$export_object = new importexport_export_csv($_stream, (array)$options);
|
||||
if (!$limit_exception)
|
||||
{
|
||||
$export_object->export_limit = $export_limit;
|
||||
}
|
||||
$export_object->set_mapping($options['mapping']);
|
||||
$convert_fields = calendar_egw_record::$types;
|
||||
|
||||
$record = new calendar_egw_record();
|
||||
foreach ($events as $event)
|
||||
{
|
||||
// the condition below (2 lines) may only work on enum_recuring=false and using the iterator to test an recurring event on the given timerange
|
||||
// Get rid of yearly recurring events that don't belong
|
||||
//if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue;
|
||||
// Add in participants
|
||||
if($options['mapping']['participants'])
|
||||
{
|
||||
if(is_array($event['participants']))
|
||||
{
|
||||
$event['participants'] = implode(", ",$this->bo->participants($event,true));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Getting results from list already has participants formatted
|
||||
$event['participants'] = str_replace("\n", ' ', $event['participants']);
|
||||
}
|
||||
}
|
||||
if (is_array($event))
|
||||
{
|
||||
$record->set_record($event);
|
||||
if($options['mapping']['recurrence'])
|
||||
{
|
||||
$rrule = calendar_rrule::event2rrule($event);
|
||||
$record->recurrence = $rrule->__toString();
|
||||
}
|
||||
|
||||
// Standard stuff
|
||||
if($options['convert'])
|
||||
{
|
||||
importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects);
|
||||
}
|
||||
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);
|
||||
return $export_object;
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,7 +317,7 @@ class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
2 => lang('Normal'),
|
||||
3 => lang('High')
|
||||
);
|
||||
$this->selects['filter'] = array(
|
||||
$this->selects['status_filter'] = array(
|
||||
'default' => lang('Not rejected'),
|
||||
'accepted' => lang('Accepted'),
|
||||
'unknown' => lang('Invitations'),
|
||||
@ -333,13 +345,19 @@ class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
// Calendar SO doesn't support filtering by column, so we have to remove pretty much everything
|
||||
unset($filters['recur_date']);
|
||||
|
||||
// Add in the status filter at the beginning
|
||||
// Add in the participant & status filters at the beginning
|
||||
$filters = array_reverse($filters, true);
|
||||
$filters['filter'] = array(
|
||||
$filters['status_filter'] = array(
|
||||
'type' => 'select',
|
||||
'name' => 'filter',
|
||||
'name' => 'status_filter',
|
||||
'label' => lang('Filter'),
|
||||
'multiple' => false
|
||||
);
|
||||
$filters['users'] = array(
|
||||
'name' => 'users',
|
||||
'label' => lang('Participant'),
|
||||
'type' => 'calendar-owner',
|
||||
) + $filters['owner'];
|
||||
$filters = array_reverse($filters, true);
|
||||
|
||||
foreach($filters as $field_name => &$settings)
|
||||
|
@ -28,98 +28,8 @@ class calendar_export_ical extends calendar_export_csv {
|
||||
$this->bo = new calendar_bo();
|
||||
$boical = new calendar_ical();
|
||||
|
||||
// Custom fields need to be specifically requested
|
||||
$cfs = array();
|
||||
$events = $this->get_events($_definition, $options);
|
||||
|
||||
$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
|
||||
if (!$limit_exception) $export_limit = Api\Storage\Merge::getExportLimit('calendar');
|
||||
|
||||
switch($options['selection'])
|
||||
{
|
||||
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;
|
||||
}
|
||||
// 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();
|
||||
|
@ -134,9 +134,9 @@ class importexport_widget_filter extends Etemplate\Widget\Transformer
|
||||
{
|
||||
unset($field['values']['']);
|
||||
}
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'empty_label', '');
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'tags', TRUE);
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'multiple', TRUE);
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'empty_label', array_key_exists('empty_label', $field ) ? $field['empty_label'] : '');
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'tags', array_key_exists('tags', $field ) ? $field['tags'] : TRUE);
|
||||
$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'multiple', array_key_exists('multiple', $field ) ? $field['multiple'] : TRUE);
|
||||
}
|
||||
else if( $GLOBALS['egw_info']['apps'][$field['type']])
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user