mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
Contacts: Reenabled search. Currently only for own, local contacts.
This commit is contained in:
parent
b11e76efc1
commit
e7d52c5437
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -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), '?')) . ')';
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user