Esempio n. 1
0
 /**
  * @brief Get a unique name of the item for the specified user
  * @param string Item
  * @param string|false User the item is being shared with
  * @param array|null List of similar item names already existing as shared items
  * @return string Target name
  *
  * This function needs to verify that the user does not already have an item with this name.
  * If it does generate a new name e.g. name_#
  */
 public function generateTarget($itemSource, $shareWith, $exclude = null)
 {
     $addressbook = Addressbook::find($itemSource);
     $user_addressbooks = array();
     foreach (Addressbook::all($shareWith) as $user_addressbook) {
         $user_addressbooks[] = $user_addressbook['displayname'];
     }
     $name = $addressbook['displayname'];
     $suffix = '';
     while (in_array($name . $suffix, $user_addressbooks)) {
         $suffix++;
     }
     return $name . $suffix;
 }
Esempio n. 2
0
 function search($query)
 {
     $addressbooks = Addressbook::all(\OCP\USER::getUser(), 1);
     if (count($addressbooks) == 0 || !\OCP\App::isEnabled('contacts')) {
         return array();
     }
     $results = array();
     $l = new \OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 //$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']);
                 $link = 'javascript:openContact(' . $vcard['id'] . ')';
                 $results[] = new \OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }