Suggestion Provider

OwnCloud Suggestion Driver
This commit is contained in:
RainLoop Team 2015-02-12 10:35:31 +04:00
parent d30292d500
commit 000711086a
15 changed files with 194 additions and 190 deletions

View file

@ -278,31 +278,37 @@ class Actions
$oResult = new \RainLoop\Providers\Filters\SieveStorage(
$this->Plugins(), $this->Config()
);
$oResult->SetLogger($this->Logger());
break;
case 'address-book':
// \RainLoop\Providers\AddressBook\AddressBookInterface
$sDsn = \trim($this->Config()->Get('contacts', 'pdo_dsn', ''));
$sUser = \trim($this->Config()->Get('contacts', 'pdo_user', ''));
$sPassword = (string) $this->Config()->Get('contacts', 'pdo_password', '');
$sDsnType = $this->ValidateContactPdoType(\trim($this->Config()->Get('contacts', 'type', 'sqlite')));
if ('sqlite' === $sDsnType)
if (!\RainLoop\Utils::IsOwnCloud()) // disabled for ownCloud
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook(
'sqlite:'.APP_PRIVATE_DATA.'AddressBook.sqlite', '', '', 'sqlite');
}
else
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
}
$sDsn = \trim($this->Config()->Get('contacts', 'pdo_dsn', ''));
$sUser = \trim($this->Config()->Get('contacts', 'pdo_user', ''));
$sPassword = (string) $this->Config()->Get('contacts', 'pdo_password', '');
$oResult->SetLogger($this->Logger());
$sDsnType = $this->ValidateContactPdoType(\trim($this->Config()->Get('contacts', 'type', 'sqlite')));
if ('sqlite' === $sDsnType)
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook(
'sqlite:'.APP_PRIVATE_DATA.'AddressBook.sqlite', '', '', 'sqlite');
}
else
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
}
}
break;
case 'suggestions':
// \RainLoop\Providers\Suggestions\SuggestionsInterface
// $oResult = new \RainLoop\Providers\Suggestions\TestSuggestions();
if (\RainLoop\Utils::IsOwnCloud())
{
$oResult = new \RainLoop\Providers\Suggestions\OwnCloudSuggestions();
}
break;
case 'change-password':
// \RainLoop\Providers\ChangePassword\ChangePasswordInterface
@ -314,6 +320,11 @@ class Actions
}
}
if ($oResult && \method_exists($oResult, 'SetLogger'))
{
$oResult->SetLogger($this->Logger());
}
$this->Plugins()->RunHook('filter.fabrica', array($sName, &$oResult, $oAccount), false);
return $oResult;
@ -2085,6 +2096,7 @@ class Actions
'accounts'
);
$aAccounts = array();
if ('' !== $sAccounts && '{' === \substr($sAccounts, 0, 1))
{
$aAccounts = @\json_decode($sAccounts, true);
@ -6589,6 +6601,20 @@ class Actions
}
}
if ($iLimit > \count($aResult) && 0 < \strlen($sQuery))
{
$oSuggestionsProvider = $this->SuggestionsProvider();
if ($oSuggestionsProvider && $oSuggestionsProvider->IsActive())
{
$iSuggestionLimit = $iLimit - \count($aResult);
$aSuggestionsProviderResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iSuggestionLimit);
if (\is_array($aSuggestionsProviderResult) && 0 < \count($aSuggestionsProviderResult))
{
$aResult = \array_merge($aResult, $aSuggestionsProviderResult);
}
}
}
if ($iLimit < \count($aResult))
{
$aResult = \array_slice($aResult, 0, $iLimit);