/** * @param int $iUserId * @param string $sSearch * @param int $iRequestLimit * @param int $iSharedTenantId = null * @return bool|array */ public function GetSuggestGroupItems($iUserId, $sSearch, $iRequestLimit, $iSharedTenantId = null) { $mGroupItems = false; if ($this->oConnection->Execute($this->oCommandCreator->GetSuggestGroupItems($iUserId, $sSearch, $iRequestLimit))) { $mGroupItems = array(); while (false !== ($oRow = $this->oConnection->GetNextRecord())) { $oItem = new CContactListItem(); $oItem->InitByDbRowWithType('group', $oRow); $oContactItems = $this->getContactItems($iUserId, EContactSortField::Frequency, ESortOrder::ASC, 0, 99, '', '', $oItem->Id, $iSharedTenantId); $aEmails = array(); foreach ($oContactItems as $oContactItem) { $aEmails[] = $oContactItem->UseFriendlyName && 0 < strlen(trim($oContactItem->Name)) ? '"' . trim($oContactItem->Name) . '" <' . trim($oContactItem->Email) . '>' : trim($oContactItem->Email); } $oItem->Email = implode(', ', $aEmails); if (!empty($oItem->Email)) { $mGroupItems[] = $oItem; } unset($oItem); } } return $mGroupItems; }
/** * @param int $iUserId * @param string $sSearch * @param int $iRequestLimit * @return bool|array */ public function GetSuggestContactItems($iUserId, $sSearch, $iRequestLimit) { $aResult = array(); $this->init($iUserId); $sDefaultAB = \afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME; $sCollectedAB = \afterlogic\DAV\Constants::ADDRESSBOOK_COLLECTED_NAME; $aCollectedContactItems = $this->Dav->GetVcards($this->AddressBookHomeSet . $sCollectedAB); $aDefaultContactItems = $this->Dav->GetVcards($this->AddressBookHomeSet . $sDefaultAB); $aContactItems = array_merge($aDefaultContactItems, $aCollectedContactItems); foreach ($aContactItems as $oItem) { $sItemId = $oItem['href']; $vCard = null; try { $vCard = \Sabre\VObject\Reader::read($oItem['data']); } catch (Exception $ex) { CApi::Log('SABREDAV: Invalid VCard with Id=' . $sItemId); } if (isset($vCard)) { $oContactItem = new CContactListItem(); $oContactItem->InitBySabreCardDAVCard($vCard); if (empty($sSearch) || stripos($oContactItem->Name, $sSearch) !== false || stripos($oContactItem->Email, $sSearch) !== false) { $aResult[] = $oContactItem; } unset($oContactItem); } unset($vCard); } $this->sortItems($aResult, EContactSortField::Frequency, ESortOrder::ASC); return array_slice($aResult, 0, $iRequestLimit); }