summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-07-09 12:51:57 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2014-07-09 12:51:57 (GMT)
commit6ad5a347b6d3ff77ac7f378db99462504f1bda45 (patch)
tree3dcd8fec4d3bfbec9b558d824c517378411d7ebe
parentdfe4052692b05ed8672cd856b3baa8e95fb90d7c (diff)
downloadiRony-6ad5a347b6d3ff77ac7f378db99462504f1bda45.tar.gz
Add filter to hide declined invitations from CalDAV output
-rw-r--r--lib/Kolab/CalDAV/CalendarBackend.php72
1 files changed, 67 insertions, 5 deletions
diff --git a/lib/Kolab/CalDAV/CalendarBackend.php b/lib/Kolab/CalDAV/CalendarBackend.php
index fdef6ca..d1a5e94 100644
--- a/lib/Kolab/CalDAV/CalendarBackend.php
+++ b/lib/Kolab/CalDAV/CalendarBackend.php
@@ -285,11 +285,16 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
{
console(__METHOD__, $calendarId);
- $query = array();
$events = array();
+ $query = $this->_event_filter_query(); console($query);
$storage = $this->get_storage_folder($calendarId);
if ($storage) {
foreach ($storage->select($query) as $event) {
+ // post-filter events to suppress declined invitations
+ if (!$this->_event_filter_compare($event)) {
+ continue;
+ }
+
$events[] = array(
'id' => $event['uid'],
'uri' => VObjectUtils::uid2uri($event['uid'], '.ics'),
@@ -304,7 +309,6 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
return $events;
}
-
/**
* Returns information from a single calendar object, based on it's object
* uri.
@@ -563,7 +567,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
console(__METHOD__, $calendarId, $filters);
// build kolab storage query from $filters
- $query = array();
+ $query = $this->_event_filter_query();
foreach ((array)$filters['comp-filters'] as $filter) {
if ($filter['name'] != 'VEVENT')
continue;
@@ -580,8 +584,10 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
$results = array();
if ($storage = $this->get_storage_folder($calendarId)) {
foreach ($storage->select($query) as $event) {
- // TODO: cache the already fetched events in memory (really?)
- $results[] = $event['uid'] . '.ics';
+ // post-filter events to suppress declined invitations
+ if ($this->_event_filter_compare($event)) {
+ $results[] = $event['uid'] . '.ics';
+ }
}
}
@@ -676,6 +682,62 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
}
/**
+ * Wrapper for libcalendaring::get_user_emails()
+ */
+ private function get_user_emails()
+ {
+ $emails = libcalendaring::get_instance()->get_user_emails();
+
+ if (empty($emails)) {
+ $emails = array(HTTPBasic::$current_user);
+ }
+
+ return $emails;
+ }
+
+ /**
+ * Provide basic query for kolab_storage_folder::select()
+ */
+ private function _event_filter_query()
+ {
+ // get email addresses of the current user
+ $user_emails = $this->get_user_emails();
+ $query = array();
+
+ // add query to exclude declined invitations
+ foreach ($user_emails as $email) {
+ $query[] = array('tags', '!=', 'x-partstat:' . $email . ':declined');
+ // $query[] = array('tags', '!=', 'x-partstat:' . $email . ':needs-action');
+ }
+
+ return $query;
+ }
+
+ /**
+ * Check the given event if it matches the filter
+ *
+ * @return boolean True if matches, false if not
+ */
+ private function _event_filter_compare($event)
+ {
+ static $user_emails;
+
+ if (!is_array($user_emails)) {
+ $user_emails = $this->get_user_emails();
+ }
+
+ if (is_array($event['attendees'])) {
+ foreach ($event['attendees'] as $attendee) {
+ if (in_array($attendee['email'], $user_emails) && $attendee['status'] == 'DECLINED') {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Generate an Etag string from the given event data
*
* @param array Hash array with event properties from libkolab