summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib/search.php
blob: cf0a5fe69974b59d8bc8bf4ce86f217f2b06e8ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
class OC_Search_Provider_Contacts implements OC_Search_Provider{
	static function search($query){
		$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser(), 1);
// 		if(count($calendars)==0 || !OC_App::isEnabled('contacts')){
// 			//return false;
// 		}
		// NOTE: Does the following do anything
		$results=array();
		$searchquery=array();
		if(substr_count($query, ' ') > 0){
			$searchquery = explode(' ', $query);
		}else{
			$searchquery[] = $query;
		}
		$l = new OC_l10n('contacts');
		foreach($addressbooks as $addressbook){
			$vcards = OC_Contacts_VCard::all($addressbook['id']);
			foreach($vcards as $vcard){
				if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0){
					$link = OC_Helper::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']);
					$results[]=new OC_Search_Result($vcard['fullname'],'', $link,$l->t('Contact'));//$name,$text,$link,$type
				}
			}
		}
		return $results;
	}
}