1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-12 23:09:15 +01:00
OwncloudContactsOfficial/lib/searchprovider.php

42 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2014-01-26 00:40:22 +01:00
/**
* @author Thomas Tanghus
* @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net)
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
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-04-19 14:42:28 +02:00
$unescape = function($value) {
return strtr($value, array('\,' => ',', '\;' => ';'));
};
$searchresults = array();
2013-01-29 20:14:39 +01:00
$results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG'));
$l = new \OC_l10n('contacts');
2013-01-29 20:14:39 +01:00
foreach($results as $result) {
2013-10-23 02:56:17 +02:00
$link = \OCP\Util::linkToRoute('contacts_index').'#' . $result['id'];
2013-01-30 00:47:17 +01:00
$props = array();
2014-02-26 12:30:38 +01:00
$display = (isset($result['FN']) && $result['FN']) ? $result['FN'] : null;
2013-01-30 00:47:17 +01:00
foreach(array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
2014-02-26 12:30:38 +01:00
if(isset($result[$searchvar]) && $result[$searchvar]) {
if(is_array($result[$searchvar])) {
$result[$searchvar] = array_filter($result[$searchvar]);
}
$prop = is_array($result[$searchvar]) ? implode(',', $result[$searchvar]) : $result[$searchvar];
$props[] = $prop;
$display = $display ?: $result[$searchvar];
2013-01-30 00:47:17 +01:00
}
}
2013-04-19 14:42:28 +02:00
$props = array_map($unescape, $props);
2014-02-26 12:30:38 +01:00
$searchresults[]=new \OC_Search_Result($display, implode(', ', $props), $link, (string)$l->t('Contact'), null);//$name,$text,$link,$type
}
2013-01-30 00:47:17 +01:00
return $searchresults;
}
}