Calendar: update share backend using contacts backend as template

This commit is contained in:
Bart Visscher 2012-08-10 14:36:41 +02:00
parent 6a95e4288e
commit fb493c45dd
1 changed files with 58 additions and 11 deletions

View File

@ -4,6 +4,7 @@
* *
* @author Michael Gapczynski * @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com * @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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 { class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
const FORMAT_CALENDAR = 1;
const FORMAT_CALENDAR = 0; /**
* @brief Get the source of the item to be stored in the database
private static $calendar; * @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) { public function isValidSource($itemSource, $uidOwner) {
if (self::$calendar = OC_Calendar_App::getCalendar($itemSource)) { $calendar = OC_Calendar_App::getCalendar( $itemSource );
return true; 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) { public function generateTarget($itemSource, $shareWith, $exclude = null) {
if (isset(self::$calendar)) { $calendar = OC_Calendar_App::getCalendar( $itemSource );
return self::$calendar['displayname']; $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) { public function formatItems($items, $format, $parameters = null) {
$calendars = array(); $calendars = array();
if ($format == self::FORMAT_CALENDAR) { if ($format == self::FORMAT_CALENDAR) {
@ -58,7 +99,13 @@ class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
} }
public function getChildren($itemSource) { 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;
} }
} }