Exemple #1
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = \OC::$server->getURLGenerator()->linkToRoute(ContactsApp::$appname . '.page.index') . '#' . urlencode($vcard['id']);
         $props = array();
         foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
             if (isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) {
                 $props = array_merge($props, $result[$searchvar]);
             }
         }
         $props = array_map($unescape, $props);
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . implode(', ', $props);
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }
Exemple #2
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = '#' . intval($vcard['id']);
         $props = '';
         foreach (array('EMAIL', 'NICKNAME', 'ORG', 'TEL') as $searchvar) {
             if (isset($result['name']) && $searchvar == $result['name']) {
                 //\OCP\Util::writeLog(ContactsApp::$appname,'FOUND id: ' . $result['value'], \OCP\Util::DEBUG);
                 $props .= $searchvar . ':' . $result['value'] . ' ';
             }
         }
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . $props;
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }