From 1e8e802acd9ab8b895c56de7a4ba5271194aacaf Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 26 May 2011 16:35:25 +0000 Subject: [PATCH] Try to pull 'search results' out of non-list views --- .../inc/class.calendar_export_csv.inc.php | 108 ++++++++++++++++-- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/calendar/inc/class.calendar_export_csv.inc.php b/calendar/inc/class.calendar_export_csv.inc.php index c8696c6c15..637c8da969 100644 --- a/calendar/inc/class.calendar_export_csv.inc.php +++ b/calendar/inc/class.calendar_export_csv.inc.php @@ -48,16 +48,51 @@ class calendar_export_csv implements importexport_iface_export_plugin { } $events =& $this->bo->search($query); } elseif ($options['select'] = 'search_results') { - $query = $GLOBALS['egw']->session->appsession('calendar_list','calendar'); - $query['num_rows'] = -1; // all - $query['start'] = 0; - $query['cfs'] = $cfs; + $states = $GLOBALS['egw']->session->appsession('session_data','calendar'); + if($states['view'] == 'listview') { + $query = $GLOBALS['egw']->session->appsession('calendar_list','calendar'); + $query['num_rows'] = -1; // all + $query['start'] = 0; + $query['cfs'] = $cfs; - if($config['export_limit']) { - $query['num_rows'] = (int)$config['export_limit']; + if($config['export_limit']) { + $query['num_rows'] = (int)$config['export_limit']; + } + $ui = new calendar_uilist(); + $ui->get_rows($query, $events); + } else { + $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); + $query['users'] = explode(',', $query['owner']); + $query['num_rows'] = -1; + if($config['export_limit']) { + $query['num_rows'] = (int)$config['export_limit']; + } + + $events = array(); + switch($states['view']) { + case 'month': + $query += $this->get_query_month($states); + break; + case 'week': + $query += $this->get_query_week($states); + break; + case 'day': + $query += $this->get_query_day($states); + break; + default: + $ui = new calendar_uiviews($query); + $query += array( + 'start' => is_array($ui->first) ? $this->bo->date2ts($ui->first) : $ui->first, + 'end' => is_array($ui->last) ? $this->bo->date2ts($ui->last) : $ui->last + ); + + } + $bo = new calendar_boupdate(); + $events = $bo->search($query + array( + 'offset' => 0, + 'order' => 'cal_start', + )); } - $ui = new calendar_uilist(); - $ui->get_rows($query, $events); } $export_object = new importexport_export_csv($_stream, (array)$options); @@ -169,4 +204,61 @@ class calendar_export_csv implements importexport_iface_export_plugin { ) ); } + + /** + * Get additional query parameters used when in various views + * This stuff copied out of calendar_uiviews + */ + private 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 function get_query_week($states) + { + $query = array(); + $days = $states['days']; + $ui = new calendar_uiviews($states); + if (!$days) + { + $days = isset($_GET['days']) ? $_GET['days'] : $this->cal_prefs['days_in_weekview']; + if ($days != 5) $days = 7; + } + if ($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("+$days days",$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; + } }