diff --git a/appinfo/app.php b/appinfo/app.php index 9eb250d4..f998d90d 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -40,16 +40,20 @@ if(\OCP\App::isEnabled('appframework')) { $api->connectHook('\OC_Calendar', 'getEvents', '\OCA\Contacts\Hooks', 'getBirthdayEvents'); $api->connectHook('\OC_Calendar', 'getSources', '\OCA\Contacts\Hooks', 'getCalenderSources'); -} -\OCP\Util::addscript('contacts', 'loader'); + \OCP\Util::addscript('contacts', 'loader'); -\OC_Search::registerProvider('OCA\Contacts\SearchProvider'); -//\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact'); -\OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share\Addressbook', 'contact'); + \OC_Search::registerProvider('OCA\Contacts\SearchProvider'); + //\OCP\Share::registerBackend('contact', 'OCA\Contacts\Share_Backend_Contact'); + \OCP\Share::registerBackend('addressbook', 'OCA\Contacts\Share\Addressbook', 'contact'); -/* -if(OCP\User::isLoggedIn()) { - foreach(OCA\Contacts\Addressbook::all(OCP\USER::getUser()) as $addressbook) { - OCP\Contacts::registerAddressBook(new OCA\Contacts\AddressbookProvider($addressbook['id'])); + + if(\OCP\User::isLoggedIn()) { + $app = new App($api->getUserId()); + $addressBooks = $app->getAddressBooksForUser(); + foreach($addressBooks as $addressBook) { + if($addressBook->getBackend()->name === 'local') { + \OCP\Contacts::registerAddressBook(new AddressbookProvider($addressBook)); + } + } } -}*/ +} diff --git a/lib/addressbookprovider.php b/lib/addressbookprovider.php index 06e54649..2a782eff 100644 --- a/lib/addressbookprovider.php +++ b/lib/addressbookprovider.php @@ -21,6 +21,7 @@ */ namespace OCA\Contacts; +use OCA\Contacts\Utils\Properties; /** * This class manages our addressbooks. @@ -39,31 +40,28 @@ class AddressbookProvider implements \OCP\IAddressBook { /** * Addressbook info array - * @var array + * @var AddressBook */ - public $addressbook; + public $addressBook; /** * Constructor * @param integer $id */ - public function __construct($id) { - $this->id = $id; + public function __construct($addressBook) { + $this->addressBook = $addressBook; } public function getAddressbook() { - if(!$this->addressbook) { - $this->addressbook = Addressbook::find($this->id); - } - return $this->addressbook; + return $this->addressBook; } /** * @return string defining the technical unique key */ public function getKey() { - $book = $this->getAddressbook(); - return $book['uri'].':'.$book['userid']; + $metaData = $this->addressBook->getMetaData(); + return $metaData['backend'].':'.$metaData['id']; } /** @@ -71,16 +69,14 @@ class AddressbookProvider implements \OCP\IAddressBook { * @return mixed */ public function getDisplayName() { - $book = $this->getAddressbook(); - return $book['displayname']; + return $this->addressBook->getDisplayName(); } /** * @return mixed */ public function getPermissions() { - $book = $this->getAddressbook(); - return $book['permissions']; + return $this->addressBook->getPermissions(); } private function getProperty(&$results, $row) { @@ -107,7 +103,7 @@ class AddressbookProvider implements \OCP\IAddressBook { break; } - if(in_array($row['name'], App::$multi_properties)) { + if(in_array($row['name'], Properties::$multi_properties)) { if(!isset($results[$row['contactid']])) { $results[$row['contactid']] = array('id' => $row['contactid'], $row['name'] => array($value)); } elseif(!isset($results[$row['contactid']][$row['name']])) { @@ -159,7 +155,7 @@ class AddressbookProvider implements \OCP\IAddressBook { $query = 'SELECT `' . self::CONTACT_TABLE . '`.`addressbookid`, `' . self::PROPERTY_TABLE . '`.`contactid`, `' . self::PROPERTY_TABLE . '`.`name`, `' . self::PROPERTY_TABLE . '`.`value` FROM `' . self::PROPERTY_TABLE . '`,`' . self::CONTACT_TABLE . '` WHERE `' - . self::CONTACT_TABLE . '`.`addressbookid` = \'' . $this->id . '\' AND `' + . self::CONTACT_TABLE . '`.`addressbookid` = \'' . $this->addressBook->getId() . '\' AND `' . self::PROPERTY_TABLE . '`.`contactid` = `' . self::CONTACT_TABLE . '`.`id` AND `' . self::PROPERTY_TABLE . '`.`contactid` IN (' . join(',', array_fill(0, count($ids), '?')) . ')'; diff --git a/lib/app.php b/lib/app.php index c6012d8e..eb6507e1 100644 --- a/lib/app.php +++ b/lib/app.php @@ -117,7 +117,7 @@ class App { public function getAddressBook($backendName, $addressbookid) { \OCP\Util::writeLog('contacts', __METHOD__ . ': '. $backendName . ', ' . $addressbookid, \OCP\Util::DEBUG); foreach(self::$addressBooks as $addressBook) { - if($addressBook->backend->name === $backendName + if($addressBook->getBackend()->name === $backendName && $addressBook->getId() === $addressbookid ) { \OCP\Util::writeLog('contacts', __METHOD__ . ' returning: '. print_r($addressBook, true), \OCP\Util::DEBUG); diff --git a/lib/searchprovider.php b/lib/searchprovider.php index e86f9281..c3c30f1a 100644 --- a/lib/searchprovider.php +++ b/lib/searchprovider.php @@ -8,12 +8,12 @@ class SearchProvider extends \OC_Search_Provider{ return strtr($value, array('\,' => ',', '\;' => ';')); }; + $app = new App(); $searchresults = array( ); $results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG')); $l = new \OC_l10n('contacts'); foreach($results as $result) { - $vcard = VCard::find($result['id']); - $link = \OCP\Util::linkTo('contacts', 'index.php').'#' . $vcard['id']; + $link = \OCP\Util::linkTo('contacts', 'index.php').'/#' . $result['id']; $props = array(); foreach(array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) { if(isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) { @@ -21,7 +21,7 @@ class SearchProvider extends \OC_Search_Provider{ } } $props = array_map($unescape, $props); - $searchresults[]=new \OC_Search_Result($vcard['fullname'], implode(', ', $props), $link, (string)$l->t('Contact'));//$name,$text,$link,$type + $searchresults[]=new \OC_Search_Result($result['FN'], implode(', ', $props), $link, (string)$l->t('Contact'));//$name,$text,$link,$type } return $searchresults; }