mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Suggestion Provider
OwnCloud Suggestion Driver
This commit is contained in:
parent
d30292d500
commit
000711086a
15 changed files with 194 additions and 190 deletions
|
|
@ -22,12 +22,14 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
|||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process(\RainLoop\Account $oAccount, $sQuery)
|
||||
public function Process(\RainLoop\Account $oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
return $this->oDriver && $this->IsActive() && 0 < \strlen($sQuery) ? $this->oDriver->Process($oAccount, $sQuery) : array();
|
||||
return $this->oDriver && $this->IsActive() && 0 < \strlen($sQuery) ?
|
||||
$this->oDriver->Process($oAccount, $sQuery, $iLimit = 20) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Suggestions;
|
||||
|
||||
class OwnCloudSuggestions implements \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
$aResult = array();
|
||||
|
||||
try
|
||||
{
|
||||
if (!$oAccount || !\RainLoop\Utils::IsOwnCloud() ||
|
||||
!\class_exists('\\OCP\\Contacts') || !\OCP\Contacts::isEnabled())
|
||||
{
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
$aSearchResult = \OCP\Contacts::search($sQuery, array('FN', 'EMAIL'));
|
||||
|
||||
foreach ($aSearchResult as $aContact)
|
||||
{
|
||||
if (0 >= $iLimit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
|
||||
if (!empty($sUid))
|
||||
{
|
||||
$sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
|
||||
$mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
|
||||
|
||||
if (!\is_array($mEmails))
|
||||
{
|
||||
$mEmails = array($mEmails);
|
||||
}
|
||||
|
||||
foreach ($mEmails as $sEmail)
|
||||
{
|
||||
$sEmail = \trim($sEmail);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
$iLimit--;
|
||||
$aResult[$sUid] = array($sEmail, $sFullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($aSearchResult);
|
||||
|
||||
$aResult = \array_values($aResult);
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*/
|
||||
public function SetLogger($oLogger)
|
||||
{
|
||||
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,9 @@ interface SuggestionsInterface
|
|||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process(\RainLoop\Model\Account $oAccount, $sQuery);
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Suggestions;
|
||||
|
||||
class TestSuggestions implements \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||
{
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
return array(
|
||||
array($oAccount->Email(), ''),
|
||||
array('xxx@xxx', 'xxx')
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue