Calendar export CSV cleanup

- Fix looking for query in wrong place broke 'Use search results'
- Remove uneeded code
- Hide criteria block when user chooses search results
This commit is contained in:
nathangray 2016-09-21 08:45:08 -06:00
parent 83de4986c8
commit d91ef451ed
2 changed files with 53 additions and 144 deletions

View File

@ -70,59 +70,27 @@ class calendar_export_csv implements importexport_iface_export_plugin {
$events =& $this->bo->search($query); $events =& $this->bo->search($query);
break; break;
case 'search_results': case 'search_results':
$states = Api\Cache::getSession('calendar', 'session_data'); $states = $this->bo->cal_prefs['saved_states'];
if($states['view'] == 'listview') {
$query = Api\Cache::getSession('calendar', 'calendar_list'); $query = Api\Cache::getSession('calendar', 'calendar_list');
$query['num_rows'] = -1; // all $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['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
$query['start'] = 0; $query['start'] = 0;
$query['cfs'] = $cfs; $query['cfs'] = $cfs;
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) { {
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
} }
$ui = new calendar_uilist(); $ui = new calendar_uilist();
$ui->get_rows($query, $events, $unused); if($states['view'] == 'listview')
} else {
$query = Api\Cache::getSession('calendar', 'session_data');
$query['users'] = explode(',', $query['owner']);
$query['num_rows'] = -1;
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) {
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
}
$events = array();
switch($states['view']) {
case 'month':
$query += $this->get_query_month($states);
break;
case 'week':
case 'weekN':
$query += $this->get_query_week($states);
break;
case 'day':
$query += $this->get_query_day($states);
break;
default:
// Let UI set the date ranges
$ui = new calendar_uiviews($query);
if(method_exists($ui, $states['view']))
{ {
ob_start(); $ui->get_rows($query, $events, $unused);
$ui->{$states['view']}();
ob_end_clean();
} }
$query += array( else
'start' => is_array($ui->first) ? $this->bo->date2ts($ui->first) : $ui->first, {
'end' => is_array($ui->last) ? $this->bo->date2ts($ui->last) : $ui->last $query['filter'] = 'custom';
); $events = array();
} $ui->get_rows($query, $events, $unused);
$boupdate = new calendar_boupdate();
$events = $boupdate->search($query + array(
'offset' => 0,
'order' => 'cal_start',
));
} }
break; break;
case 'filter': case 'filter':
@ -163,35 +131,45 @@ class calendar_export_csv implements importexport_iface_export_plugin {
} }
$export_object = new importexport_export_csv($_stream, (array)$options); $export_object = new importexport_export_csv($_stream, (array)$options);
if (!$limit_exception) $export_object->export_limit = $export_limit; if (!$limit_exception)
{
$export_object->export_limit = $export_limit;
}
$export_object->set_mapping($options['mapping']); $export_object->set_mapping($options['mapping']);
$convert_fields = calendar_egw_record::$types; $convert_fields = calendar_egw_record::$types;
$recurrence = $this->bo->recur_types; $recurrence = $this->bo->recur_types;
$record = new calendar_egw_record(); $record = new calendar_egw_record();
foreach ($events as $event) { 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 // 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 // Get rid of yearly recurring events that don't belong
//if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue; //if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue;
// Add in participants // Add in participants
if($options['mapping']['participants']) { if($options['mapping']['participants'])
{
$event['participants'] = implode(", ",$this->bo->participants($event,true)); $event['participants'] = implode(", ",$this->bo->participants($event,true));
} }
if (is_array($event)) if (is_array($event))
{ {
$record->set_record($event); $record->set_record($event);
if($options['mapping']['recurrence']) { if($options['mapping']['recurrence'] && is_array($recurrence))
{
$record->recurrence = $recurrence[$record->recur_type]; $record->recurrence = $recurrence[$record->recur_type];
if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval; if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval;
} }
// Standard stuff // Standard stuff
if($options['convert']) { if($options['convert'])
{
importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects); importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects);
} else { }
else
{
// Implode arrays, so they don't say 'Array' // Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value) { foreach($record->get_record_array() as $key => $value)
{
if(is_array($value)) $record->$key = implode(',', $value); if(is_array($value)) $record->$key = implode(',', $value);
} }
} }
@ -207,7 +185,8 @@ class calendar_export_csv implements importexport_iface_export_plugin {
* *
* @return string name * @return string name
*/ */
public static function get_name() { public static function get_name()
{
return lang('Calendar CSV export'); return lang('Calendar CSV export');
} }
@ -216,7 +195,8 @@ class calendar_export_csv implements importexport_iface_export_plugin {
* *
* @return string descriprion * @return string descriprion
*/ */
public static function get_description() { public static function get_description()
{
return lang("Exports events from your Calendar into a CSV File."); return lang("Exports events from your Calendar into a CSV File.");
} }
@ -225,11 +205,13 @@ class calendar_export_csv implements importexport_iface_export_plugin {
* *
* @return string suffix * @return string suffix
*/ */
public static function get_filesuffix() { public static function get_filesuffix()
{
return 'csv'; return 'csv';
} }
public static function get_mimetype() { public static function get_mimetype()
{
return 'text/csv'; return 'text/csv';
} }
@ -237,38 +219,22 @@ class calendar_export_csv implements importexport_iface_export_plugin {
* return html for options. * return html for options.
* *
*/ */
public function get_options_etpl($definition = null) { public function get_options_etpl($definition = null)
{
} }
/** /**
* returns selectors of this plugin * returns selectors of this plugin
* *
*/ */
public function get_selectors_etpl($definition = null) { public function get_selectors_etpl($definition = null)
{
$states = $this->bo->cal_prefs['saved_states']; $states = $this->bo->cal_prefs['saved_states'];
$list = Api\Cache::getSession('calendar', 'calendar_list'); $list = Api\Cache::getSession('calendar', 'calendar_list');
if(!$list['startdate'])
{
switch($states['view']) {
case 'month':
$query = $this->get_query_month($states);
break;
case 'week':
case 'weekN':
$query = $this->get_query_week($states);
break;
case 'day':
$query = $this->get_query_day($states);
break;
}
$start= new Api\DateTime($query['start']);
$end = new Api\DateTime($query['end']);
}
else
{
$start= new Api\DateTime($list['startdate']); $start= new Api\DateTime($list['startdate']);
$end = new Api\DateTime($list['enddate']); $end = new Api\DateTime($list['enddate']);
}
if ($states['view'] == 'listview') if ($states['view'] == 'listview')
{ {
$list = Api\Cache::getSession('calendar', 'calendar_list'); $list = Api\Cache::getSession('calendar', 'calendar_list');
@ -289,7 +255,7 @@ class calendar_export_csv implements importexport_iface_export_plugin {
} }
$ui = null; $ui = null;
} }
elseif(!$end) else if(!$end)
{ {
$end = '+1 ' . $states['view']; $end = '+1 ' . $states['view'];
$end = strtotime($end, $start->format('ts'))-1; $end = strtotime($end, $start->format('ts'))-1;
@ -310,63 +276,6 @@ class calendar_export_csv implements importexport_iface_export_plugin {
return $data; return $data;
} }
/**
* Get additional query parameters used when in various views
* This stuff copied out of calendar_uiviews
*/
public static function get_query_month($states)
{
$timespan = array(
'start' => mktime(0,0,0,$states['month'],1,$states['year']),
'end' => mktime(0,0,0,$states['month']+1,1,$states['year'])-1
);
return $timespan;
}
public static function get_query_week($states)
{
$query = array();
$days = $states['days'];
$ui = new calendar_uiviews($states);
if (!$days)
{
$days = isset($_GET['days']) ? $_GET['days'] : $ui->cal_prefs['days_in_weekview'];
if ($days != 5) $days = 7;
}
if ($states['view'] == 'week' && $days == 4) // next 4 days view
{
$query['start'] = $this->bo->date2ts($states['date']);
$query['end'] = strtotime("+$days days",$query['start']) - 1;
}
else
{
$query['start'] = $ui->datetime->get_weekday_start($states['year'],$states['month'],$states['day']);
if ($days == 5) // no weekend-days
{
switch($ui->cal_prefs['weekdaystarts'])
{
case 'Saturday':
$query['start'] = strtotime("+2 days",$query['start']);
break;
case 'Sunday':
$query['start'] = strtotime("+1 day",$query['start']);
break;
}
}
$query['end'] = strtotime($states['view'] == 'week' ? "+$days days" : "+{$ui->cal_prefs['multiple_weeks']} weeks",$query['start']) - 1;
}
return $query;
}
public static function get_query_day($states)
{
$query = array();
$bo = new calendar_bo();
$query['start'] = $bo->date2ts((string)$states['date']);
$query['end'] = $query['start']+DAY_s-1;
return $query;
}
/** /**
* Get select options for use in filter * Get select options for use in filter
*/ */

View File

@ -14,7 +14,7 @@
<description/> <description/>
</row> </row>
<row> <row>
<radio label="Use search results" id="selection" options="search_results" span="all"/> <radio label="Use search results" id="selection" onclick="jQuery('.criteria').hide();jQuery('div.filters').hide();" options="search_results" span="all"/>
</row> </row>
<row> <row>
<radio label="Use definition filter" id="selection" onclick="jQuery('div.filters').show();jQuery('.criteria').hide();" options="filter" span="all"/> <radio label="Use definition filter" id="selection" onclick="jQuery('div.filters').show();jQuery('.criteria').hide();" options="filter" span="all"/>