mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-26 20:18:52 +02:00
N°2847 - Global search: Add config. parameter for max. history results ('global_search.max_history_results')
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Component\GlobalSearch;
|
||||
|
||||
|
||||
use appUserPreferences;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ use utils;
|
||||
*/
|
||||
class GlobalSearchHelper
|
||||
{
|
||||
public const MAX_HISTORY_SIZE = 10;
|
||||
/** @var string */
|
||||
public const USER_PREF_CODE = 'global_search_history';
|
||||
|
||||
/**
|
||||
@@ -86,10 +87,7 @@ class GlobalSearchHelper
|
||||
array_unshift($aHistoryEntries, $aNewEntry);
|
||||
|
||||
// Truncate history
|
||||
if(count($aHistoryEntries) > static::MAX_HISTORY_SIZE)
|
||||
{
|
||||
$aHistoryEntries = array_slice($aHistoryEntries, 0, static::MAX_HISTORY_SIZE);
|
||||
}
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries);
|
||||
}
|
||||
@@ -107,6 +105,7 @@ class GlobalSearchHelper
|
||||
{
|
||||
/** @var array $aHistoryEntries */
|
||||
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
|
||||
{
|
||||
@@ -125,4 +124,18 @@ class GlobalSearchHelper
|
||||
|
||||
return $aHistoryEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate $aHistoryEntries to 'global_search.max_history_results' entries
|
||||
*
|
||||
* @param array $aHistoryEntries
|
||||
*/
|
||||
protected static function TruncateHistory(array &$aHistoryEntries): void
|
||||
{
|
||||
$iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('global_search.max_history_results');
|
||||
if(count($aHistoryEntries) > $iMaxHistoryResults)
|
||||
{
|
||||
$aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user