From 740a5085a0d37af10c1bd9ee9f39c8c9bc3b83dd Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 13 Oct 2015 16:41:52 +0000 Subject: [PATCH] Handle merging from listview into a template designed for the other views (range tag, no pagerepeat) --- calendar/inc/class.calendar_merge.inc.php | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/calendar/inc/class.calendar_merge.inc.php b/calendar/inc/class.calendar_merge.inc.php index 2f88c94215..6accfc0b1d 100644 --- a/calendar/inc/class.calendar_merge.inc.php +++ b/calendar/inc/class.calendar_merge.inc.php @@ -97,6 +97,46 @@ class calendar_merge extends bo_merge $this->query['num_rows'] = -1; } + /** + * Merges a given document with contact data + * + * Overridden from parent to be able to change a list of events into a range, + * if the target document has no pagerepeat tag. Otherwise, parent::merge_string() + * would fail because we're trying to merge multiple records with no pagerepeat tag. + * + * + * @param string $content + * @param array $ids array with contact id(s) + * @param string &$err error-message on error + * @param string $mimetype mimetype of complete document, eg. text/*, application/vnd.oasis.opendocument.text, application/rtf + * @param array $fix=null regular expression => replacement pairs eg. to fix garbled placeholders + * @param string $charset=null charset to override default set by mimetype or export charset + * @return string|boolean merged document or false on error + */ + function merge_string($content,$ids,$err,$mimetype,$fix) + { + // Handle merging a list of events into a document with range instead of pagerepeat + if(strpos($content, '$$pagerepeat') === false && count($ids) > 1) + { + // Merging more than one something will fail without pagerepeat + if (is_array($ids) && $ids[0]['id']) + { + // Passed an array of events, to be handled like a date range + $events = $ids; + $ids = array('start' => PHP_INT_MAX, 'end' => 0); + $this->ids = array(); + foreach($events as $event) { + if($event['start'] && egw_time::to($event['start'],'ts') < $ids['start']) $ids['start'] = egw_time::to($event['start'],'ts'); + if($event['end'] && egw_time::to($event['end'],'ts') > $ids['end']) $ids['end'] = egw_time::to($event['end'],'ts'); + // Keep ids for future use + $this->ids[] = $event['id']; + } + $ids = array($ids); + } + } + return parent::merge_string($content, $ids, $err, $mimetype,$fix); + } + /** * Get replacements * @@ -133,6 +173,7 @@ class calendar_merge extends bo_merge // Keep ids for future use $this->ids[] = $event['id']; } + $id = array($id); } else {