Branch 'roundcubemail-plugins-kolab-format2-horde5' - 4 commits - plugins/calendar
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Tue Jan 29 17:11:39 CET 2013
plugins/calendar/calendar.php | 26 ++---
plugins/calendar/drivers/calendar_driver.php | 12 +-
plugins/calendar/drivers/database/database_driver.php | 49 ++++++++-
plugins/calendar/drivers/kolab/kolab_calendar.php | 1
plugins/calendar/drivers/kolab/kolab_driver.php | 91 ++++++++++++------
5 files changed, 126 insertions(+), 53 deletions(-)
New commits:
commit ec6bb9bb42bce307ae301dfce4e0bc259d0ca530
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 23 09:56:22 2013 +0100
Update last-modifcation-date in updated events to make iTip requests contain the latest date
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index 513087e..468bfa8 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -321,6 +321,7 @@ class kolab_calendar
}
else {
$updated = true;
+ $object['last-modification-date'] = time(); // set last-modification timestamp
$this->events[$event['id']] = $this->_to_rcube_event($object);
}
commit 0b5c3dd9c5cb98bfca2a9d890fef5d3b4ad8d089
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 23 09:55:07 2013 +0100
Search for existing events in personal namespace only (#1406)
diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index 24d929a..5780c95 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -1806,7 +1806,7 @@ class calendar extends rcube_plugin
$event['calendar'] = $calendar['id'];
// check for existing event with the same UID
- $existing = $this->driver->get_event($event['uid'], true);
+ $existing = $this->driver->get_event($event['uid'], true, false, true);
if ($existing) {
// only update attendee status
commit d5bc28b5e3a57ddc6f43f849f908a2786db436f2
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Jan 17 09:37:48 2013 +0100
Fix typo in calendar selection; fixes bug #140
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index fc8a555..58c7e8a 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -133,13 +133,13 @@ class kolab_driver extends calendar_driver
/**
* Get list of calendars according to specified filters
*
- * @param bool $writable Return only writeable calendars
+ * @param bool $writeable Return only writeable calendars
* @param bool $active Return only active calendars
* @param bool $personal Return only personal calendars
*
* @return array List of calendars
*/
- protected function filter_calendars($writable = false, $active = false, $personal = false)
+ protected function filter_calendars($writeable = false, $active = false, $personal = false)
{
$calendars = array();
foreach ($this->calendars as $cal) {
commit 18dcf2da4c4d6fe4c3b89c72e2b246fd11c3a2a0
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Tue Dec 4 20:10:04 2012 +0100
Fix Invitations can not be accepted when calendars are shared with certain rights (#1406)
diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index e344c40..24d929a 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -234,7 +234,7 @@ class calendar extends rcube_plugin
public function get_default_calendar($writeable = false)
{
$default_id = $this->rc->config->get('calendar_default_calendar');
- $calendars = $this->driver->list_calendars();
+ $calendars = $this->driver->list_calendars(false, true);
$calendar = $calendars[$default_id] ?: null;
if (!$calendar || ($writeable && $calendar['readonly'])) {
foreach ($calendars as $cal) {
@@ -402,9 +402,8 @@ class calendar extends rcube_plugin
// default calendar selection
$field_id = 'rcmfd_default_calendar';
$select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
- foreach ((array)$this->driver->list_calendars() as $id => $prop) {
- if (!$prop['readonly'])
- $select_cal->add($prop['name'], strval($id));
+ foreach ((array)$this->driver->list_calendars(false, true) as $id => $prop) {
+ $select_cal->add($prop['name'], strval($id));
if ($prop['default'])
$default_calendar = $id;
}
@@ -705,7 +704,7 @@ class calendar extends rcube_plugin
$status = $event['fallback'];
$html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : '');
$this->load_driver();
- if ($existing = $this->driver->get_event($event, true)) {
+ if ($existing = $this->driver->get_event($event, true, false, true)) {
$emails = $this->get_user_emails();
foreach ($existing['attendees'] as $i => $attendee) {
if ($attendee['email'] && in_array($attendee['email'], $emails)) {
@@ -716,7 +715,7 @@ class calendar extends rcube_plugin
}
else {
// get a list of writeable calendars
- $calendars = $this->driver->list_calendars();
+ $calendars = $this->driver->list_calendars(false, true);
$calendar_select = new html_select(array('name' => 'calendar', 'id' => 'calendar-saveto', 'is_escaped' => true));
$numcals = 0;
foreach ($calendars as $calendar) {
@@ -949,7 +948,7 @@ class calendar extends rcube_plugin
if (!$start) $start = mktime(0, 0, 0, 1, date('n'), date('Y')-1);
if (!$end) $end = mktime(0, 0, 0, 31, 12, date('Y')+10);
$calid = $calname = get_input_value('source', RCUBE_INPUT_GET);
- $calendars = $this->driver->list_calendars();
+ $calendars = $this->driver->list_calendars(true);
if ($calendars[$calid]) {
$calname = $calendars[$calid]['name'] ? $calendars[$calid]['name'] : $calid;
@@ -1163,12 +1162,8 @@ class calendar extends rcube_plugin
{
$num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
$cats = array_keys($this->driver->list_categories());
- $cals = array();
- foreach ($this->driver->list_calendars() as $cid => $cal) {
- if ($cal['active'])
- $cals[$cid] = $cal;
- }
-
+ $cals = $this->driver->list_calendars(true);
+
while ($count++ < $num) {
$start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
$duration = round(rand(30, 360) / 30) * 30 * 60;
@@ -1789,7 +1784,7 @@ class calendar extends rcube_plugin
if (!empty($events) && ($event = $events[$index])) {
// find writeable calendar to store event
$cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : null;
- $calendars = $this->driver->list_calendars();
+ $calendars = $this->driver->list_calendars(false, true);
$calendar = $calendars[$cal_id] ?: $this->get_default_calendar(true);
// update my attendee status according to submitted method
@@ -1852,6 +1847,7 @@ class calendar extends rcube_plugin
// import the (newer) event
else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
$event['id'] = $existing['id'];
+ $event['calendar'] = $existing['calendar'];
$success = $this->driver->edit_event($event);
}
else if (!empty($status)) {
diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index 88c7f45..47f7fb8 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -91,8 +91,13 @@ abstract class calendar_driver
/**
* Get a list of available calendars from this source
+ *
+ * @param bool $active Return only active calendars
+ * @param bool $personal Return only personal calendars
+ *
+ * @return array List of calendars
*/
- abstract function list_calendars();
+ abstract function list_calendars($active = false, $personal = false);
/**
* Create a new calendar assigned to the current user
@@ -207,9 +212,12 @@ abstract class calendar_driver
* id: Event identifier
* calendar: Calendar identifier (optional)
* @param boolean If true, only writeable calendars shall be searched
+ * @param boolean If true, only active calendars shall be searched
+ * @param boolean If true, only personal calendars shall be searched
+ *
* @return array Event object as hash array
*/
- abstract function get_event($event, $writeable = null);
+ abstract function get_event($event, $writeable = false, $active = false, $personal = false);
/**
* Get events from source.
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 5aac2dd..ad725a8 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -103,18 +103,36 @@ class database_driver extends calendar_driver
/**
* Get a list of available calendars from this source
+ *
+ * @param bool $active Return only active calendars
+ * @param bool $personal Return only personal calendars
+ *
+ * @return array List of calendars
*/
- public function list_calendars()
+ public function list_calendars($active = false, $personal = false)
{
// attempt to create a default calendar for this user
if (empty($this->calendars)) {
if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
$this->_read_calendars();
}
-
- return $this->calendars;
+
+ $calendars = $this->calendars;
+
+ // filter active calendars
+ if ($active) {
+ foreach ($calendars as $idx => $cal) {
+ if (!$cal['active']) {
+ unset($calendars[$idx]);
+ }
+ }
+ }
+
+ // 'personal' is unsupported in this driver
+
+ return $calendars;
}
-
+
/**
* Create a new calendar assigned to the current user
*
@@ -648,23 +666,38 @@ class database_driver extends calendar_driver
/**
* Return data of a specific event
* @param mixed Hash array with event properties or event UID
- * @param boolean Only search in writeable calendars (currently ignored)
+ * @param boolean Only search in writeable calendars (ignored)
+ * @param boolean Only search in active calendars
+ * @param boolean Only search in personal calendars (ignored)
* @return array Hash array with event properties
*/
- public function get_event($event, $writeable = null)
+ public function get_event($event, $writeable = false, $active = false, $personal = false)
{
$id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event;
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
if ($this->cache[$id])
return $this->cache[$id];
-
+
+ if ($active) {
+ $calendars = $this->calendars;
+ foreach ($calendars as $idx => $cal) {
+ if (!$cal['active']) {
+ unset($calendars[$idx]);
+ }
+ }
+ $cals = join(',', $calendars);
+ }
+ else {
+ $cals = $this->calendar_ids;
+ }
+
$result = $this->rc->db->query(sprintf(
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id OR a.event_id = e.recurrence_id)
WHERE e.calendar_id IN (%s)
AND e.$col=?",
- $this->calendar_ids
+ $cals
),
$id);
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index a5e2345..fc8a555 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -91,8 +91,13 @@ class kolab_driver extends calendar_driver
/**
* Get a list of available calendars from this source
+ *
+ * @param bool $active Return only active calendars
+ * @param bool $personal Return only personal calendars
+ *
+ * @return array List of calendars
*/
- public function list_calendars()
+ public function list_calendars($active = false, $personal = false)
{
// attempt to create a default calendar for this user
if (!$this->has_writeable) {
@@ -102,24 +107,23 @@ class kolab_driver extends calendar_driver
}
}
- $calendars = $names = array();
-
- foreach ($this->calendars as $id => $cal) {
- if ($cal->ready) {
- $name = kolab_storage::folder_displayname($cal->get_name(), $names);
-
- $calendars[$cal->id] = array(
- 'id' => $cal->id,
- 'name' => $name,
- 'editname' => $cal->get_foldername(),
- 'color' => $cal->get_color(),
- 'readonly' => $cal->readonly,
- 'showalarms' => $cal->alarms,
- 'class_name' => $cal->get_namespace(),
- 'default' => $cal->storage->default,
- 'active' => $cal->storage->is_subscribed(kolab_storage::SERVERSIDE_SUBSCRIPTION),
- );
- }
+ $calendars = $this->filter_calendars(false, $active, $personal);
+ $names = array();
+
+ foreach ($calendars as $id => $cal) {
+ $name = kolab_storage::folder_displayname($cal->get_name(), $names);
+
+ $calendars[$id] = array(
+ 'id' => $cal->id,
+ 'name' => $name,
+ 'editname' => $cal->get_foldername(),
+ 'color' => $cal->get_color(),
+ 'readonly' => $cal->readonly,
+ 'showalarms' => $cal->alarms,
+ 'class_name' => $cal->get_namespace(),
+ 'default' => $cal->storage->default,
+ 'active' => $cal->storage->is_subscribed(),
+ );
}
return $calendars;
@@ -127,6 +131,37 @@ class kolab_driver extends calendar_driver
/**
+ * Get list of calendars according to specified filters
+ *
+ * @param bool $writable Return only writeable calendars
+ * @param bool $active Return only active calendars
+ * @param bool $personal Return only personal calendars
+ *
+ * @return array List of calendars
+ */
+ protected function filter_calendars($writable = false, $active = false, $personal = false)
+ {
+ $calendars = array();
+ foreach ($this->calendars as $cal) {
+ if (!$cal->ready) {
+ continue;
+ }
+ if ($writeable && $cal->readonly) {
+ continue;
+ }
+ if ($active && !$cal->storage->is_subscribed()) {
+ continue;
+ }
+ if ($personal && $cal->get_namespace() != 'personal') {
+ continue;
+ }
+ $calendars[$cal->id] = $cal;
+ }
+
+ return $calendars;
+ }
+
+ /**
* Create a new calendar assigned to the current user
*
* @param array Hash array with calendar properties
@@ -247,7 +282,7 @@ class kolab_driver extends calendar_driver
* @see calendar_driver::get_event()
* @return array Hash array with event properties, false if not found
*/
- public function get_event($event, $writeable = null)
+ public function get_event($event, $writeable = false, $active = false, $personal = false)
{
if (is_array($event)) {
$id = $event['id'] ? $event['id'] : $event['uid'];
@@ -256,16 +291,16 @@ class kolab_driver extends calendar_driver
else {
$id = $event;
}
-
- if ($cal && ($storage = $this->calendars[$cal])) {
- return $storage->get_event($id);
+
+ if ($cal) {
+ if ($storage = $this->calendars[$cal]) {
+ return $storage->get_event($id);
+ }
}
// iterate over all calendar folders and search for the event ID
- else if (!$cal) {
- foreach ($this->calendars as $storage) {
- if ($writeable && $storage->readonly)
- continue;
- if ($result = $storage->get_event($id)) {
+ else {
+ foreach ($this->filter_calendars($writeable, $active, $personal) as $calendar) {
+ if ($result = $calendar->get_event($id)) {
return $result;
}
}
More information about the commits
mailing list