Automatically make adjustments to merge range to try to match the selected template

This commit is contained in:
Nathan Gray 2015-12-09 23:12:12 +00:00
parent e7fd0ff52a
commit b4cfde8c35
2 changed files with 48 additions and 9 deletions

View File

@ -117,10 +117,11 @@ class calendar_merge extends bo_merge
*/
function merge_string($content,$ids,$err,$mimetype,$fix)
{
error_log(__METHOD__ . ' IDs: ' . array2string($ids));
//error_log(__METHOD__ . ' IDs: ' . array2string($ids));
// Handle merging a list of events into a document with range instead of pagerepeat
if(strpos($content, '$$pagerepeat') === false && strpos($content, '{{pagerepeat') === false && count($ids) > 1)
if((strpos($content, '$$range') !== false || strpos($content, '{{range') !== false) && is_array($ids))
{
//error_log(__METHOD__ . ' Got list of events(?), no pagerepeat tag');
// Merging more than one something will fail without pagerepeat
if (is_array($ids) && $ids[0]['id'])
{
@ -138,8 +139,11 @@ class calendar_merge extends bo_merge
}
}
// Handle merging a range of events into a document with pagerepeat instead of range
else if ((strpos($content, '$$pagerepeat') !== false || strpos($content, '{{pagerepeat') !== false) && is_array($ids) && $ids[0] && !$ids[0]['id'])
else if ((strpos($content, '$$pagerepeat') !== false || strpos($content, '{{pagerepeat') !== false)
&& ((strpos($content, '$$range') === false && strpos($content, '{{range') === false))
&& is_array($ids) && $ids[0] && !$ids[0]['id'])
{
//error_log(__METHOD__ . ' Got range(?), but pagerepeat instead of range tag');
// Passed a range, needs to be expanded
$events = $this->bo->search($this->query + $ids[0] + array(
'offset' => 0,

View File

@ -836,13 +836,48 @@ class calendar_ui
{
if(!$timespan)
{
$timespan = array(array(
'start' => is_array($this->first) ? $this->bo->date2ts($this->first) : $this->first,
'end' => is_array($this->last) ? $this->bo->date2ts($this->last) : $this->last
));
// Try to make time span into appropriate ranges to match
if(stripos($_GET['merge'],'month') !== false || stripos($_GET['merge'],lang('month')) !== false) $template = 'month';
if(stripos($_GET['merge'],'week') !== false || stripos($_GET['merge'],lang('week')) !== false) $template = 'week';
//error_log("Detected template $template");
switch ($template)
{
case 'month':
// Trim to _only_ the month, do not pad to week start / end
$time = new egw_time($this->date);
$timespan = array(array(
'start' => egw_time::to($time->format('Y-m-01 00:00:00'),'ts'),
'end' => egw_time::to($time->format('Y-m-t 23:59:59'),'ts')
));
break;
case 'week':
$timespan = array();
$start = new egw_time($this->first);
$t = clone $start;
$t->modify('+1 week')->modify('-1 second');
if($t->format('ts') < egw_time::to($this->last,'ts'))
{
do
{
$timespan[] = array(
'start' => $start->format('ts'),
'end' => $t->format('ts')
);
$start->modify('+1 week');
$t->modify('+1 week');
} while( $start->format('ts') < $this->last);
break;
}
// Fall through
default:
$timespan = array(array(
'start' => is_array($this->first) ? $this->bo->date2ts($this->first) : $this->first,
'end' => is_array($this->last) ? $this->bo->date2ts($this->last) : $this->last
));
}
}
$merge = new calendar_merge();
//error_log('Timespan: ' . egw_time::to($timespan[0]['start']) . ' - ' . egw_time::to($timespan[0]['end']));
//error_log('Timespan: ');foreach($timespan as $t) error_log(egw_time::to($t['start']) . ' - ' . egw_time::to($t['end']));
$error = $merge->download($_GET['merge'], $timespan, '', $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']);
// Here? Doesn't actually give the message
egw_framework::refresh_opener($error, 'calendar');