* Calendar: automatic cancel alarms from removed or rejected participants

This commit is contained in:
Ralf Becker 2013-08-29 14:39:01 +00:00
parent b94b6dfc15
commit aef984c7fa
3 changed files with 56 additions and 7 deletions

View File

@ -1067,6 +1067,18 @@ class calendar_boupdate extends calendar_bo
{
// recalculate alarms to also cope with moved events (beside server time adjustment)
$event['alarm'][$id]['time'] = $event['start'] - $alarm['offset'];
// remove alarms belonging to not longer existing or rejected participants
if ($alarm['owner'] && isset($event['participants']))
{
$status = $event['participants'][$alarm['owner']];
if (!isset($status) || calendar_so::split_status($status) === 'R')
{
unset($event['alarm'][$id]);
$this->so->delete_alarm($id);
error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
}
}
}
}
// update all existing alarm times, in case alarm got moved and alarms are not include in $event
@ -1077,7 +1089,19 @@ class calendar_boupdate extends calendar_bo
if (!isset($event['alarm'][$id]))
{
$alarm['time'] = $event['start'] - $alarm['offset'];
$this->so->save_alarm($event['id'],$alarm, $this->now);
// remove (not store) alarms belonging to not longer existing or rejected participants
$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
$old_event['participants'][$alarm['owner']];
if (!$alarm['owner'] || isset($status) && calendar_so::split_status($status) !== 'R')
{
$this->so->save_alarm($event['id'], $alarm, $this->now);
error_log(__LINE__.': '.__METHOD__."() so->save_alarm($event[id], ".array2string($alarm).", $this->now)");
}
else
{
$this->so->delete_alarm($id);
error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
}
}
}
}
@ -1303,6 +1327,17 @@ class calendar_boupdate extends calendar_bo
is_numeric($uid)?$uid:substr($uid,1),$status,
$recur_date?$this->date2ts($recur_date,true):0,$role)))
{
if ($status == 'R') // remove alarms belonging to rejected participants
{
foreach(isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
{
if ((string)$alarm['owner'] === (string)$uid)
{
$this->so->delete_alarm($id);
error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
}
}
}
if ($updateTS)
{
$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now);

View File

@ -1020,7 +1020,7 @@ ORDER BY cal_user_type, cal_usre_id
$old_min = $old_duration = 0;
//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag)");
//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace());
$cal_id = (int) $event['id'];
unset($event['id']);
@ -1435,10 +1435,11 @@ ORDER BY cal_user_type, cal_usre_id
* splits the combined status, quantity and role
*
* @param string &$status I: combined value, O: status letter: U, T, A, R
* @param int &$quantity only O: quantity
* @param string &$role only O: role
* @param int &$quantity=null only O: quantity
* @param string &$role=null only O: role
* @return string status U, T, A or R, same as $status parameter on return
*/
static function split_status(&$status,&$quantity,&$role)
static function split_status(&$status,&$quantity=null,&$role=null)
{
$quantity = 1;
$role = 'REQ-PARTICIPANT';
@ -1453,6 +1454,7 @@ ORDER BY cal_user_type, cal_usre_id
{
$status = 'U';
}
return $status;
}
/**
@ -1888,8 +1890,7 @@ ORDER BY cal_user_type, cal_usre_id
*/
function save_alarm($cal_id, $alarm, $update_modified=true)
{
//echo "<p>save_alarm(cal_id=$cal_id, alarm="; print_r($alarm); echo ")</p>\n";
//error_log(__METHOD__."(.$cal_id,$now,".array2string($alarm).')');
//error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
if (!($id = $alarm['id']))
{
$alarms = $this->read_alarms($cal_id); // find a free alarm#
@ -1932,6 +1933,7 @@ ORDER BY cal_user_type, cal_usre_id
*/
private function delete_alarms($cal_id)
{
//error_log(__METHOD__."($cal_id) ".function_backtrace());
$alarms = $this->read_alarms($cal_id);
foreach($alarms as $id => $alarm)
@ -1952,6 +1954,7 @@ ORDER BY cal_user_type, cal_usre_id
*/
function delete_alarm($id)
{
//error_log(__METHOD__."('$id') ".function_backtrace());
// update the modification information of the related event
list(,$cal_id) = explode(':',$id);
if ($cal_id)

View File

@ -405,6 +405,17 @@ class calendar_uiforms extends calendar_ui
{
$msg = lang('Status changed');
}
if ($status == 'R' && $event['alarm'])
{
// remove from bo->set_status deleted alarms of rejected users from UI too
foreach($event['alarm'] as $alarm_id => $alarm)
{
if ((string)$alarm['owner'] === (string)$uid)
{
unset($event['alarm'][$alarm_id]);
}
}
}
}
if (!$preserv['no_popup'])
{