forked from extern/egroupware
Add filter to calendar_so::get_recurrence_exceptions() method
This commit is contained in:
parent
83b53cadbe
commit
14e7c0cd87
@ -1513,4 +1513,122 @@ class calendar_boupdate extends calendar_bo
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* classifies an incoming event from the eGW point-of-view
|
||||
*
|
||||
* exceptions: unlike other calendar apps eGW does not create an event exception
|
||||
* if just the participant state changes - therefore we have to distinguish between
|
||||
* real exceptions and status only exceptions
|
||||
*
|
||||
* @param array $event the event to check
|
||||
*
|
||||
* @return array
|
||||
* type =>
|
||||
* SINGLE a single event
|
||||
* SERIES-MASTER the series master
|
||||
* SERIES-EXCEPTION event is a real exception
|
||||
* SERIES-EXCEPTION-STATUS event is a status only exception
|
||||
* SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
|
||||
* stored_event => if event already exists in the database array with event data or false
|
||||
* master_event => for event type SERIES-EXCEPTION, SERIES-EXCEPTION-STATUS or SERIES-EXCEPTION-PROPAGATE
|
||||
* the corresponding series master event array
|
||||
* NOTE: this param is false if event is of type SERIES-MASTER
|
||||
*/
|
||||
function get_event_info($event)
|
||||
{
|
||||
$type = 'SINGLE'; // default
|
||||
$return_master = false; //default
|
||||
|
||||
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
||||
{
|
||||
$type = 'SERIES-MASTER';
|
||||
}
|
||||
else
|
||||
{
|
||||
// SINGLE, SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
||||
if (empty($event['uid']) && $event['id'] > 0 && ($stored_event = $this->read($event['id'])))
|
||||
{
|
||||
$event['uid'] = $stored_event['uid']; // restore the UID if it was not delivered
|
||||
}
|
||||
|
||||
if (isset($event['uid'])
|
||||
&& $event['recurrence']
|
||||
&& ($master_event = $this->read($event['uid']))
|
||||
&& isset($master_event['recur_type'])
|
||||
&& $master_event['recur_type'] != MCAL_RECUR_NONE)
|
||||
{
|
||||
// SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
||||
$return_master = true; // we have a valid master and can return it
|
||||
|
||||
if (isset($event['id']) && $master_event['id'] != $event['id'])
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION'; // this is an existing exception
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION-STATUS'; // default if we cannot find a proof for a fundamental change
|
||||
// the recurrence_event is the master event with start and end adjusted to the recurrence
|
||||
$recurrence_event = $master_event;
|
||||
$recurrence_event['start'] = $event['recurrence'];
|
||||
$recurrence_event['end'] = $event['recurrence'] + ($master_event['end'] - $master_event['start']);
|
||||
// check for changed data
|
||||
foreach (array('start','end','uid','title','location',
|
||||
'priority','public','special','non_blocking') as $key)
|
||||
{
|
||||
if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
|
||||
{
|
||||
if (isset($event['id']))
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION-PROPAGATE';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION'; // this is a new exception
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// the event id here is always the id of the master event
|
||||
// unset it to prevent confusion of stored event and master event
|
||||
unset($event['id']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// SINGLE
|
||||
$type = 'SINGLE';
|
||||
}
|
||||
}
|
||||
|
||||
// read existing event
|
||||
if (isset($event['id']))
|
||||
{
|
||||
$stored_event = $this->read($event['id']);
|
||||
}
|
||||
|
||||
// check ACL
|
||||
if ($return_master)
|
||||
{
|
||||
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $master_event['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($stored_event))
|
||||
{
|
||||
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $stored_event['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$acl_edit = true; // new event
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'type' => $type,
|
||||
'acl_edit' => $acl_edit,
|
||||
'stored_event' => is_array($stored_event) ? $stored_event : false,
|
||||
'master_event' => $return_master ? $master_event : false,
|
||||
);
|
||||
}
|
||||
}
|
@ -942,6 +942,7 @@ class calendar_ical extends calendar_boupdate
|
||||
$event['participants'][$uid] = $event['participant_types']['r'][substr($uid,1)] = $status;
|
||||
}
|
||||
}
|
||||
$event['tzid'] = $storedEvent['tzid'];
|
||||
// avoid that iCal changes the organizer, which is not allowed
|
||||
$event['owner'] = $event_info['stored_event']['owner'];
|
||||
}
|
||||
@ -1727,6 +1728,7 @@ class calendar_ical extends calendar_boupdate
|
||||
break;
|
||||
case 'RRULE':
|
||||
$recurence = $attributes['value'];
|
||||
$vcardData['recur_interval'] = 1;
|
||||
$type = preg_match('/FREQ=([^;: ]+)/i',$recurence,$matches) ? $matches[1] : $recurence[0];
|
||||
// vCard 2.0 values for all types
|
||||
if (preg_match('/UNTIL=([0-9TZ]+)/',$recurence,$matches))
|
||||
@ -1739,8 +1741,7 @@ class calendar_ical extends calendar_boupdate
|
||||
}
|
||||
if (preg_match('/INTERVAL=([0-9]+)/',$recurence,$matches))
|
||||
{
|
||||
// 1 is invalid,, egw uses 0 for interval
|
||||
$vcardData['recur_interval'] = (int) $matches[1] != 0 ? (int) $matches[1] : 0;
|
||||
$vcardData['recur_interval'] = (int) $matches[1] ? (int) $matches[1] : 1;
|
||||
}
|
||||
$vcardData['recur_data'] = 0;
|
||||
switch($type)
|
||||
@ -2402,122 +2403,4 @@ class calendar_ical extends calendar_boupdate
|
||||
$this->set_status($old_event, $userid, $status, $recur_date, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* classifies an incoming event from the eGW point-of-view
|
||||
*
|
||||
* exceptions: unlike other calendar apps eGW does not create an event exception
|
||||
* if just the participant state changes - therefore we have to distinguish between
|
||||
* real exceptions and status only exceptions
|
||||
*
|
||||
* @param array $event the event to check
|
||||
*
|
||||
* @return array
|
||||
* type =>
|
||||
* SINGLE a single event
|
||||
* SERIES-MASTER the series master
|
||||
* SERIES-EXCEPTION event is a real exception
|
||||
* SERIES-EXCEPTION-STATUS event is a status only exception
|
||||
* SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
|
||||
* stored_event => if event already exists in the database array with event data or false
|
||||
* master_event => for event type SERIES-EXCEPTION, SERIES-EXCEPTION-STATUS or SERIES-EXCEPTION-PROPAGATE
|
||||
* the corresponding series master event array
|
||||
* NOTE: this param is false if event is of type SERIES-MASTER
|
||||
*/
|
||||
private function get_event_info($event)
|
||||
{
|
||||
$type = 'SINGLE'; // default
|
||||
$return_master = false; //default
|
||||
|
||||
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
||||
{
|
||||
$type = 'SERIES-MASTER';
|
||||
}
|
||||
else
|
||||
{
|
||||
// SINGLE, SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
||||
if (empty($event['uid']) && $event['id'] > 0 && ($stored_event = $this->read($event['id'])))
|
||||
{
|
||||
$event['uid'] = $stored_event['uid']; // restore the UID if it was not delivered
|
||||
}
|
||||
|
||||
if (isset($event['uid'])
|
||||
&& $event['recurrence']
|
||||
&& ($master_event = $this->read($event['uid']))
|
||||
&& isset($master_event['recur_type'])
|
||||
&& $master_event['recur_type'] != MCAL_RECUR_NONE)
|
||||
{
|
||||
// SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
||||
$return_master = true; // we have a valid master and can return it
|
||||
|
||||
if (isset($event['id']) && $master_event['id'] != $event['id'])
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION'; // this is an existing exception
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION-STATUS'; // default if we cannot find a proof for a fundamental change
|
||||
// the recurrence_event is the master event with start and end adjusted to the recurrence
|
||||
$recurrence_event = $master_event;
|
||||
$recurrence_event['start'] = $event['recurrence'];
|
||||
$recurrence_event['end'] = $event['recurrence'] + ($master_event['end'] - $master_event['start']);
|
||||
// check for changed data
|
||||
foreach (array('start','end','uid','title','location',
|
||||
'priority','public','special','non_blocking') as $key)
|
||||
{
|
||||
if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
|
||||
{
|
||||
if (isset($event['id']))
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION-PROPAGATE';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'SERIES-EXCEPTION'; // this is a new exception
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// the event id here is always the id of the master event
|
||||
// unset it to prevent confusion of stored event and master event
|
||||
unset($event['id']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// SINGLE
|
||||
$type = 'SINGLE';
|
||||
}
|
||||
}
|
||||
|
||||
// read existing event
|
||||
if (isset($event['id']))
|
||||
{
|
||||
$stored_event = $this->read($event['id']);
|
||||
}
|
||||
|
||||
// check ACL
|
||||
if ($return_master)
|
||||
{
|
||||
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $master_event['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($stored_event))
|
||||
{
|
||||
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $stored_event['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$acl_edit = true; // new event
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'type' => $type,
|
||||
'acl_edit' => $acl_edit,
|
||||
'stored_event' => is_array($stored_event) ? $stored_event : false,
|
||||
'master_event' => $return_master ? $master_event : false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -238,12 +238,12 @@ class calendar_so
|
||||
//echo "<p>socal::read(".print_r($ids,true).")=<pre>".print_r($events,true)."</pre>\n";
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get maximum modification time of participant data of given event(s)
|
||||
*
|
||||
*
|
||||
* This includes ALL recurences of an event series
|
||||
*
|
||||
*
|
||||
* @param int|array $ids one or multiple cal_id's
|
||||
* @return int|array (array of) modification timestamp(s)
|
||||
*/
|
||||
@ -1489,16 +1489,18 @@ ORDER BY cal_user_type, cal_usre_id
|
||||
|
||||
/**
|
||||
* Gets the exception days of a given recurring event caused by
|
||||
* irregular participant stati
|
||||
* irregular participant stati or timezone transitions
|
||||
*
|
||||
* @param array $event Recurring Event.
|
||||
* @param string tz_id=null timezone for exports (null for event's timezone)
|
||||
* @param int $start=0 if != 0: startdate of the search/list (servertime)
|
||||
* @param int $end=0 if != 0: enddate of the search/list (servertime)
|
||||
* @param string $filter='all' string filter-name: all (not rejected), accepted, unknown, tentative,
|
||||
* rejected, tz_transitions (return only by timezone transition affected entries)
|
||||
*
|
||||
* @return array Array of exception days (false for non-recurring events).
|
||||
*/
|
||||
function get_recurrence_exceptions(&$event, $tz_id=null, $start=0, $end=0)
|
||||
function get_recurrence_exceptions(&$event, $tz_id=null, $start=0, $end=0, $filter='all')
|
||||
{
|
||||
$cal_id = (int) $event['id'];
|
||||
if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
|
||||
@ -1538,8 +1540,35 @@ ORDER BY cal_user_type, cal_usre_id
|
||||
$time = new egw_time($recur_date, egw_time::$server_timezone);
|
||||
$time->setTimezone(self::$tz_cache[$tz_id]);
|
||||
$recur_start = $time->format('His');
|
||||
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
||||
// "() first=$first_start <> current=$recur_start");
|
||||
}
|
||||
if ($recur_status != $recurrences[0]
|
||||
if ($attendee['type'] = 'u' &&
|
||||
$attendee['id'] == $GLOBALS['egw_info']['user']['account_id'])
|
||||
{
|
||||
// handle filter for current user
|
||||
switch ($filter)
|
||||
{
|
||||
case 'unknown':
|
||||
if ($recur_status != 'U') continue;
|
||||
break;
|
||||
case 'accepted':
|
||||
if ($recur_status != 'A') continue;
|
||||
break;
|
||||
case 'tentative':
|
||||
if ($recur_status != 'T') continue;
|
||||
break;
|
||||
case 'rejected':
|
||||
if ($recur_status != 'R') continue;
|
||||
break;
|
||||
case 'default':
|
||||
if ($recur_status == 'R') continue;
|
||||
break;
|
||||
default:
|
||||
// All entries
|
||||
}
|
||||
}
|
||||
if (($filter != 'tz_transitions' && $recur_status != $recurrences[0])
|
||||
|| !empty($tz_id) && $first_start != $recur_start)
|
||||
{
|
||||
// Every distinct status or starttime results in an exception
|
||||
|
Loading…
Reference in New Issue
Block a user