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) {
|
2013-01-30 00:47:17 +01:00
|
|
|
$searchresults = array( );
|
2013-01-29 20:14:39 +01:00
|
|
|
$results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
|
2012-11-01 02:01:00 +01:00
|
|
|
$l = new \OC_l10n('contacts');
|
2013-01-29 20:14:39 +01:00
|
|
|
foreach($results as $result) {
|
|
|
|
$vcard = VCard::find($result['id']);
|
|
|
|
$link = \OCP\Util::linkTo('contacts', 'index.php').'#' . $vcard['id'];
|
2013-01-30 00:47:17 +01:00
|
|
|
$props = array();
|
|
|
|
foreach(array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
|
2013-02-24 02:20:19 +01:00
|
|
|
if(isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) {
|
2013-01-30 00:47:17 +01:00
|
|
|
$props = array_merge($props, $result[$searchvar]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$searchresults[]=new \OC_Search_Result($vcard['fullname'], implode(', ', $props), $link, (string)$l->t('Contact'));//$name,$text,$link,$type
|
2012-01-12 16:06:27 +01:00
|
|
|
}
|
2013-01-30 00:47:17 +01:00
|
|
|
return $searchresults;
|
2012-01-12 16:06:27 +01:00
|
|
|
}
|
|
|
|
}
|