2012-01-12 16:06:27 +01:00
|
|
|
<?php
|
2012-10-25 03:34:12 +02:00
|
|
|
|
|
|
|
namespace OCA\Contacts;
|
|
|
|
|
|
|
|
class SearchProvider extends \OC_Search_Provider{
|
2012-09-07 15:21:03 +02:00
|
|
|
function search($query) {
|
2012-10-30 07:19:56 +01:00
|
|
|
$addressbooks = Addressbook::all(\OCP\USER::getUser(), 1);
|
2012-10-25 03:34:12 +02:00
|
|
|
if(count($addressbooks)==0 || !\OCP\App::isEnabled('contacts')) {
|
2012-06-14 22:44:54 +02:00
|
|
|
return array();
|
2012-01-12 16:06:27 +01:00
|
|
|
}
|
2012-06-14 22:44:54 +02:00
|
|
|
$results=array();
|
2012-11-01 02:01:00 +01:00
|
|
|
$l = new \OC_l10n('contacts');
|
2012-09-07 15:21:03 +02:00
|
|
|
foreach($addressbooks as $addressbook) {
|
2012-10-30 07:19:56 +01:00
|
|
|
$vcards = VCard::all($addressbook['id']);
|
2012-09-07 15:21:03 +02:00
|
|
|
foreach($vcards as $vcard) {
|
2012-07-20 00:17:59 +02:00
|
|
|
if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
|
2012-11-01 02:01:00 +01:00
|
|
|
//$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']);
|
|
|
|
$link = 'javascript:openContact(' . $vcard['id'] . ')';
|
2012-10-25 03:34:12 +02:00
|
|
|
$results[]=new \OC_Search_Result($vcard['fullname'], '', $link, (string)$l->t('Contact'));//$name,$text,$link,$type
|
2012-01-12 16:06:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|