From 56299511f2d3b5a604768dd9dc7f59da388fa7d0 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 27 Jun 2012 15:44:42 +0200 Subject: [PATCH] Something like this should do it for sharing contacts --- index.php | 1 + lib/share.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/index.php b/index.php index 0b4f89b3..e72d2917 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,7 @@ if($contacts === false) { } $addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser()); +$addressbooks = array_merge($addressbooks, OCP\Share::getItemsSharedWith('addressbook', OC_Contacts_Share::FORMAT_ADDRESSBOOKS)); // Load the files we need OCP\App::setActiveNavigationEntry( 'contacts_index' ); diff --git a/lib/share.php b/lib/share.php index d304042e..3198d226 100644 --- a/lib/share.php +++ b/lib/share.php @@ -7,6 +7,7 @@ */ class OC_Contacts_Share extends OCP\Share_Backend { + const FORMAT_ADDRESSBOOKS = 1; /** * @brief Get the source of the item to be stored in the database * @param string Item @@ -37,6 +38,18 @@ class OC_Contacts_Share extends OCP\Share_Backend { * If it does generate a new name e.g. name_# */ public function generateTarget($item, $uid, $exclude = null) { + $addressbook = OC_Contacts_Addressbook::find( $item ); + $user_addressbooks = array(); + foreach(OC_Contacts_Addressbook::all($uid) as $user_addressbook) { + $user_addressbooks[] = $user_addressbooks['displayname']; + } + $name = $addressbook['uid']."'s ".$addressbook['displayname']; + $suffix = ''; + while (in_array($name.$suffix, $user_addressbooks)) { + $suffix++; + } + + return $name.$suffix; } /** @@ -50,5 +63,12 @@ class OC_Contacts_Share extends OCP\Share_Backend { * It is only called through calls to the public getItem(s)SharedWith functions. */ public function formatItems($items, $format) { + $addressbooks = array(); + foreach($items as $source => $info) { + $addressbook = OC_Contacts_Addressbook::find( $source ); + $addressbook['displayname'] = $info['item_target']; + $addressbooks[] = $addressbook; + } + return $addressbooks; } }