Contacts suggestions example plugin

This commit is contained in:
RainLoop Team 2015-08-19 21:58:34 +03:00
parent 86d763420d
commit 436e54891e
9 changed files with 106 additions and 16 deletions

View file

@ -0,0 +1,21 @@
<?php
class ContactsExampleSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
{
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process($oAccount, $sQuery, $iLimit = 20)
{
$aResult = array(
array($oAccount->Email(), ''),
array('email@domain.com', 'name')
);
return $aResult;
}
}

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2015 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
1.0

View file

@ -0,0 +1,30 @@
<?php
class ContactsSuggestionsExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $mResult
*/
public function MainFabrica($sName, &$mResult)
{
switch ($sName)
{
case 'suggestions':
if (!\is_array($mResult))
{
$mResult = array();
}
include_once __DIR__.'/ContactsExampleSuggestions.php';
$mResult[] = new ContactsExampleSuggestions();
break;
}
}
}

View file

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2014 RainLoop Team
Copyright (c) 2015 RainLoop Team, @zaffkea
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View file

@ -1 +1 @@
1.1
1.2

View file

@ -305,11 +305,9 @@ class Actions
$mResult = array();
}
// \RainLoop\Providers\Suggestions\ISuggestions
// $mResult[] = new \RainLoop\Providers\Suggestions\TestSuggestions();
if (\is_array($mResult) && \RainLoop\Utils::IsOwnCloud())
{
// \RainLoop\Providers\Suggestions\ISuggestions
$mResult[] = new \RainLoop\Providers\Suggestions\OwnCloudSuggestions();
}
@ -7011,8 +7009,10 @@ class Actions
$aResult = \array_merge($aResult, $aSuggestionsProviderResult);
}
}
}
$aResult = \RainLoop\Utils::RemoveSuggestionsdDuplicates($aResult);
if ($iLimit < \count($aResult))
{
$aResult = \array_slice($aResult, 0, $iLimit);
@ -7020,6 +7020,7 @@ class Actions
$this->Plugins()->RunHook('ajax.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit));
$aResult = \RainLoop\Utils::RemoveSuggestionsdDuplicates($aResult);
if ($iLimit < \count($aResult))
{
$aResult = \array_slice($aResult, 0, $iLimit);

View file

@ -35,7 +35,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
*/
public function Process($oAccount, $sQuery, $iLimit = 20)
{
$aResult = array();
$aSuggestions = array();
if ($oAccount instanceof \RainLoop\Model\Account &&
$this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
@ -54,16 +54,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
}
}
$aCache = array();
foreach ($aSuggestions as $aItem) // remove duplicates
{
$sLine = \implode('~~', $aItem);
if (!isset($aCache[$sLine]))
{
$aCache[$sLine] = true;
$aResult[] = $aItem;
}
}
$aResult = \RainLoop\Utils::RemoveSuggestionsdDuplicates($aSuggestions);
if ($iLimit < \count($aResult))
{

View file

@ -608,6 +608,32 @@ class Utils
return self::WebVersionPath().'static/';
}
/**
* @param array $aSuggestions
*
* @return array
*/
public static function RemoveSuggestionsdDuplicates($aSuggestions)
{
$aResult = array();
if (is_array($aSuggestions))
{
$aCache = array();
foreach ($aSuggestions as $aItem)
{
$sLine = \implode('~~', $aItem);
if (!isset($aCache[$sLine]))
{
$aCache[$sLine] = true;
$aResult[] = $aItem;
}
}
}
return $aResult;
}
/**
* @param string $sFileName
* @param bool $bProcessSections = false