Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-08-10 16:36:41 +0400
committerBart Visscher <bartv@thisnet.nl>2012-08-10 16:40:48 +0400
commitfb493c45dd4ecadeaa5b1b112a156054318af0a2 (patch)
tree178a1061b275f5167f4f157e2d3e5d12a7801658 /apps/calendar
parent6a95e4288ed4987453719c1bb87056ae822a4b73 (diff)
Calendar: update share backend using contacts backend as template
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/lib/share/calendar.php69
1 files changed, 58 insertions, 11 deletions
diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php
index 0ddca2400a9..7f498292419 100644
--- a/apps/calendar/lib/share/calendar.php
+++ b/apps/calendar/lib/share/calendar.php
@@ -4,6 +4,7 @@
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -20,25 +21,65 @@
*/
class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
+ const FORMAT_CALENDAR = 1;
- const FORMAT_CALENDAR = 0;
-
- private static $calendar;
-
+ /**
+ * @brief Get the source of the item to be stored in the database
+ * @param string Item
+ * @param string Owner of the item
+ * @return mixed|array|false Source
+ *
+ * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
+ * Return false if the item does not exist for the user
+ *
+ * The formatItems() function will translate the source returned back into the item
+ */
public function isValidSource($itemSource, $uidOwner) {
- if (self::$calendar = OC_Calendar_App::getCalendar($itemSource)) {
- return true;
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ if ($calendar || $calendar['userid'] != $uidOwner) {
+ return false;
}
- return false;
+ return true;
}
+ /**
+ * @brief Get a unique name of the item for the specified user
+ * @param string Item
+ * @param string|false User the item is being shared with
+ * @param array|null List of similar item names already existing as shared items
+ * @return string Target name
+ *
+ * This function needs to verify that the user does not already have an item with this name.
+ * If it does generate a new name e.g. name_#
+ */
public function generateTarget($itemSource, $shareWith, $exclude = null) {
- if (isset(self::$calendar)) {
- return self::$calendar['displayname'];
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ $user_calendars = array();
+ foreach(OC_Contacts_Addressbook::all($uid) as $user_calendar) {
+ $user_calendars[] = $user_calendar['displayname'];
}
- return false;
+ $name = $calendar['userid']."'s ".$calendar['displayname'];
+ $suffix = '';
+ while (in_array($name.$suffix, $user_calendars)) {
+ $suffix++;
+ }
+
+ return $name.$suffix;
}
+ /**
+ * @brief Converts the shared item sources back into the item in the specified format
+ * @param array Shared items
+ * @param int Format
+ * @return ?
+ *
+ * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
+ * The key/value pairs included in the share info depend on the function originally called:
+ * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
+ * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
+ * This function allows the backend to control the output of shared items with custom formats.
+ * It is only called through calls to the public getItem(s)Shared(With) functions.
+ */
public function formatItems($items, $format, $parameters = null) {
$calendars = array();
if ($format == self::FORMAT_CALENDAR) {
@@ -58,7 +99,13 @@ class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
}
public function getChildren($itemSource) {
- // TODO
+ $query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_objects WHERE calendarid = ?');
+ $result = $query->execute(array($itemSource));
+ $sources = array();
+ while ($object = $result->fetchRow()) {
+ $sources[] = $object['id'];
+ }
+ return $sources;
}
} \ No newline at end of file