summaryrefslogtreecommitdiffstats
path: root/apps/calendar/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-08-19 22:29:01 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-08-19 22:29:01 -0400
commit82d81e8d39ce69211ec6b29fe3f803c57714b8dd (patch)
tree09dbd675480a02fd626f6634e083f3d6a01b4404 /apps/calendar/lib
parentf893d21660695d1d1cd594c102e2bcba6919dee3 (diff)
parent5eca531f99f9615d1a09bbb0b03dda2063901aa7 (diff)
downloadnextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.tar.gz
nextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.zip
Merge branch 'share_api'
Conflicts: apps/contacts/lib/vcard.php apps/files/index.php lib/files.php
Diffstat (limited to 'apps/calendar/lib')
-rw-r--r--apps/calendar/lib/share.php21
-rw-r--r--apps/calendar/lib/share/calendar.php111
-rw-r--r--apps/calendar/lib/share/event.php40
-rw-r--r--apps/calendar/lib/share_backend.php44
4 files changed, 204 insertions, 12 deletions
diff --git a/apps/calendar/lib/share.php b/apps/calendar/lib/share.php
index 4fe88171403..e5ffc04143a 100644
--- a/apps/calendar/lib/share.php
+++ b/apps/calendar/lib/share.php
@@ -18,19 +18,16 @@ class OC_Calendar_Share{
* @return: array $return - information about calendars
*/
public static function allSharedwithuser($userid, $type, $active=null, $permission=null){
- $group_where = self::group_sql(OC_Group::getUserGroups($userid));
- $permission_where = self::permission_sql($permission);
- if($type == self::CALENDAR){
- $active_where = self::active_sql($active);
- }else{
- $active_where = '';
- }
- $stmt = OCP\DB::prepare("SELECT * FROM *PREFIX*calendar_share_" . $type . " WHERE ((share = ? AND sharetype = 'user') " . $group_where . ") AND owner <> ? " . $permission_where . " " . $active_where);
- $result = $stmt->execute(array($userid, $userid));
- $return = array();
- while( $row = $result->fetchRow()){
- $return[] = $row;
+ $format = OC_Share_Backend_Calendar::FORMAT_CALENDAR;
+ if ($type == self::EVENT) {
+ $format = OC_Share_Backend_Event::FORMAT_EVENT;
}
+ $return = OCP\Share::getItemsSharedWith($type,
+ $format,
+ array(
+ 'active' => $active,
+ 'permissions' => $permission,
+ ));
return $return;
}
/**
diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php
new file mode 100644
index 00000000000..7f498292419
--- /dev/null
+++ b/apps/calendar/lib/share/calendar.php
@@ -0,0 +1,111 @@
+<?php
+/**
+* ownCloud
+*
+* @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
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
+ const FORMAT_CALENDAR = 1;
+
+ /**
+ * @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) {
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ if ($calendar || $calendar['userid'] != $uidOwner) {
+ 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) {
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ $user_calendars = array();
+ foreach(OC_Contacts_Addressbook::all($uid) as $user_calendar) {
+ $user_calendars[] = $user_calendar['displayname'];
+ }
+ $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) {
+ foreach ($items as $item) {
+ $calendar = OC_Calendar_App::getCalendar($item['item_source'], false);
+ // TODO: really check $parameters['permissions'] == 'rw'/'r'
+ if ($parameters['permissions'] == 'rw') {
+ continue; // TODO
+ }
+ $calendar['displaynamename'] = $item['item_target'];
+ $calendar['calendarid'] = $calendar['id'];
+ $calendar['owner'] = $calendar['userid'];
+ $calendars[] = $calendar;
+ }
+ }
+ return $calendars;
+ }
+
+ public function getChildren($itemSource) {
+ $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
diff --git a/apps/calendar/lib/share/event.php b/apps/calendar/lib/share/event.php
new file mode 100644
index 00000000000..5bb72ee6c98
--- /dev/null
+++ b/apps/calendar/lib/share/event.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Share_Backend_Event implements OCP\Share_Backend {
+
+ const FORMAT_EVENT = 0;
+
+ private static $event;
+
+ public function isValidSource($itemSource, $uidOwner) {
+ self::$event = OC_Calendar_Object::find($itemSource);
+ if (self::$event) {
+ return true;
+ }
+ return false;
+ }
+
+ public function generateTarget($itemSource, $shareWith, $exclude = null) {
+ // TODO Get default calendar and check for conflicts
+ return self::$event['summary'];
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ $events = array();
+ if ($format == self::FORMAT_EVENT) {
+ foreach ($items as $item) {
+ $event = OC_Calendar_Object::find($item['item_source']);
+ $event['summary'] = $item['item_target'];
+ $events[] = $event;
+ }
+ }
+ return $events;
+ }
+
+}
diff --git a/apps/calendar/lib/share_backend.php b/apps/calendar/lib/share_backend.php
new file mode 100644
index 00000000000..f937c0d1c34
--- /dev/null
+++ b/apps/calendar/lib/share_backend.php
@@ -0,0 +1,44 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Calendar extends OCP\Share_Backend {
+
+ public function getSource($item, $uid) {
+ $query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_calendars WHERE userid = ? AND displayname = ? LIMIT 1');
+ return $query->execute(array($uid, $item))->fetchAll();
+ }
+
+ public function generateTarget($item, $uid) {
+
+ }
+
+ public function getItems($sources) {
+
+ }
+
+}
+
+class OC_Share_Backend_Event extends OCP\Share_Backend {
+
+}
+
+
+?> \ No newline at end of file