* Calendar: automatic cancel alarms from removed or rejected participants

This commit is contained in:
Ralf Becker 2013-08-29 14:31:45 +00:00
parent 18838ef606
commit 3fa98b8209
5 changed files with 58 additions and 7 deletions

View File

@ -1134,6 +1134,18 @@ class calendar_boupdate extends calendar_bo
{ {
// recalculate alarms to also cope with moved events (beside server time adjustment) // recalculate alarms to also cope with moved events (beside server time adjustment)
$event['alarm'][$id]['time'] = $event['start'] - $alarm['offset']; $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 // update all existing alarm times, in case alarm got moved and alarms are not include in $event
@ -1144,7 +1156,19 @@ class calendar_boupdate extends calendar_bo
if (!isset($event['alarm'][$id])) if (!isset($event['alarm'][$id]))
{ {
$alarm['time'] = $event['start'] - $alarm['offset']; $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));
}
} }
} }
} }
@ -1388,6 +1412,17 @@ class calendar_boupdate extends calendar_bo
is_numeric($uid)?$uid:substr($uid,1),$status, is_numeric($uid)?$uid:substr($uid,1),$status,
$recur_date?$this->date2ts($recur_date,true):0,$role))) $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) if ($updateTS)
{ {
$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now); $GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now);

View File

@ -1029,7 +1029,7 @@ ORDER BY cal_user_type, cal_usre_id
$old_min = $old_duration = 0; $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']; $cal_id = (int) $event['id'];
unset($event['id']); unset($event['id']);
@ -1466,10 +1466,11 @@ ORDER BY cal_user_type, cal_usre_id
* splits the combined status, quantity and role * splits the combined status, quantity and role
* *
* @param string &$status I: combined value, O: status letter: U, T, A, R * @param string &$status I: combined value, O: status letter: U, T, A, R
* @param int &$quantity only O: quantity * @param int &$quantity=null only O: quantity
* @param string &$role only O: role * @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; $quantity = 1;
$role = 'REQ-PARTICIPANT'; $role = 'REQ-PARTICIPANT';
@ -1484,6 +1485,7 @@ ORDER BY cal_user_type, cal_usre_id
{ {
$status = 'U'; $status = 'U';
} }
return $status;
} }
/** /**
@ -1913,8 +1915,7 @@ ORDER BY cal_user_type, cal_usre_id
*/ */
function save_alarm($cal_id, $alarm, $update_modified=true) 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, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
//error_log(__METHOD__."(.$cal_id,$now,".array2string($alarm).')');
if (!($id = $alarm['id'])) if (!($id = $alarm['id']))
{ {
$alarms = $this->read_alarms($cal_id); // find a free alarm# $alarms = $this->read_alarms($cal_id); // find a free alarm#
@ -1957,6 +1958,7 @@ ORDER BY cal_user_type, cal_usre_id
*/ */
private function delete_alarms($cal_id) private function delete_alarms($cal_id)
{ {
//error_log(__METHOD__."($cal_id) ".function_backtrace());
$alarms = $this->read_alarms($cal_id); $alarms = $this->read_alarms($cal_id);
foreach($alarms as $id => $alarm) foreach($alarms as $id => $alarm)
@ -1977,6 +1979,7 @@ ORDER BY cal_user_type, cal_usre_id
*/ */
function delete_alarm($id) function delete_alarm($id)
{ {
//error_log(__METHOD__."('$id') ".function_backtrace());
// update the modification information of the related event // update the modification information of the related event
list(,$cal_id) = explode(':',$id); list(,$cal_id) = explode(':',$id);
if ($cal_id) if ($cal_id)

View File

@ -425,6 +425,17 @@ class calendar_uiforms extends calendar_ui
$js = "opener.location.search += (opener.location.search?'&msg=':'?msg=')+'". $js = "opener.location.search += (opener.location.search?'&msg=':'?msg=')+'".
addslashes($msg)."';"; addslashes($msg)."';";
} }
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 ($uid && $status != 'G') if ($uid && $status != 'G')

View File

@ -5,6 +5,7 @@
%1 records imported calendar de %1 Datensätze importiert %1 records imported calendar de %1 Datensätze importiert
%1 records read (not yet imported, you may go back and uncheck test import) calendar de %1 Datensätze gelesen (noch nicht importiert, Sie können zurück gehen und Test Import ausschalten) %1 records read (not yet imported, you may go back and uncheck test import) calendar de %1 Datensätze gelesen (noch nicht importiert, Sie können zurück gehen und Test Import ausschalten)
%1 weeks calendar de %1 Wochen %1 weeks calendar de %1 Wochen
%s the event calendar de %s dem Termin
(%1 events in %2 seconds) calendar de (%1 Termine in %2 Sekunden (%1 events in %2 seconds) calendar de (%1 Termine in %2 Sekunden
, exceptions preserved calendar de und Ausnahmen erhalten , exceptions preserved calendar de und Ausnahmen erhalten
, stati of participants reset calendar de , Status der Teilnehmer zurückgesetzt , stati of participants reset calendar de , Status der Teilnehmer zurückgesetzt

View File

@ -5,6 +5,7 @@
%1 records imported calendar en %1 records imported. %1 records imported calendar en %1 records imported.
%1 records read (not yet imported, you may go back and uncheck test import) calendar en %1 records read. Not yet imported, go back and uncheck Test import. %1 records read (not yet imported, you may go back and uncheck test import) calendar en %1 records read. Not yet imported, go back and uncheck Test import.
%1 weeks calendar en %1 weeks %1 weeks calendar en %1 weeks
%s the event calendar en %s the event
(%1 events in %2 seconds) calendar en (%1 events in %2 seconds) (%1 events in %2 seconds) calendar en (%1 events in %2 seconds)
, exceptions preserved calendar en , exceptions preserved , exceptions preserved calendar en , exceptions preserved
, stati of participants reset calendar en , status of participants reset , stati of participants reset calendar en , status of participants reset