patch from Achim Koenigs <achim-at-tratschtante.de> to shift alarms of recurring events to first future recurrent, so they get stored, modified to not doublicate code

This commit is contained in:
Ralf Becker 2012-07-18 06:45:09 +00:00
parent 99d11f58b3
commit 5bab15b433
2 changed files with 33 additions and 15 deletions

View File

@ -1443,6 +1443,10 @@ class calendar_ical extends calendar_boupdate
// if no edit rights, allow participants to set alarms directly (like status)
if ($event_info['stored_event'] && !$event_info['acl_edit'])
{
if ($alarm['time'] < time() && !calendar_so::shift_alarm($event, $alarm))
{
continue; //pgoerzen: don't add an alarm in the past
}
$this->save_alarm($event_info['stored_event']['id'], $alarm);
}

View File

@ -1263,22 +1263,9 @@ ORDER BY cal_user_type, cal_usre_id
$alarm['time'] = $event['cal_start'] - $alarm['offset'];
}
if ($alarm['time'] < time())
if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm))
{
//pgoerzen: don't add an alarm in the past
if ($event['recur_type'] == MCAL_RECUR_NONE) continue;
$start = (int)time() + $alarm['offset'];
$event['start'] = $event['cal_start'];
$event['end'] = $event['cal_end'];
$event['tzid'] = $event['cal_tzid'];
$rrule = calendar_rrule::event2rrule($event, false);
foreach ($rrule as $time)
{
if ($start < ($ts = egw_time::to($time,'server'))) break;
$ts = 0;
}
if (!$ts) continue;
$alarm['time'] = $ts - $alarm['offset'];
continue; // pgoerzen: don't add alarm in the past
}
$this->save_alarm($cal_id,$alarm);
}
@ -1290,6 +1277,33 @@ ORDER BY cal_user_type, cal_usre_id
return $cal_id;
}
/**
* Shift alarm on recurring events to next future recurrence
*
* @param array $event event with optional 'cal_' prefix in keys
* @param array &$alarm
* @return boolean true if alarm could be shifted, false if not
*/
public static function shift_alarm(array $event, array &$alarm)
{
if ($event['recur_type'] == MCAL_RECUR_NONE)
{
return false;
}
$start = (int)time() + $alarm['offset'];
egw_db::strip_array_keys($event, 'cal_');
$rrule = calendar_rrule::event2rrule($event, false);
foreach ($rrule as $time)
{
if ($start < ($ts = egw_time::to($time,'server')))
{
$alarm['time'] = $ts - $alarm['offset'];
return true;
}
}
return false;
}
/**
* moves an event to an other start- and end-time taken into account the evtl. recurrences of the event(!)
*