From ecf678f39f1ae12aa3b0069e8afc5542ae0e99b7 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 9 Oct 2020 09:47:29 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02847=20-=20Quick=20create:=20Refactor=20?= =?UTF-8?q?history=20truncation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QuickCreate/QuickCreateHelper.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php b/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php index c961d734e..bc6c35cec 100644 --- a/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php +++ b/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php @@ -71,11 +71,7 @@ class QuickCreateHelper array_unshift($aHistoryEntries, $aNewEntry); // Truncate history - $iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); - if(count($aHistoryEntries) > $iMaxHistoryResults) - { - $aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults); - } + static::TruncateHistory($aHistoryEntries); appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries); } @@ -90,11 +86,11 @@ class QuickCreateHelper */ public static function GetLastClasses() { - $iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); /** @var array $aHistoryEntries */ $aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []); + static::TruncateHistory($aHistoryEntries); - for($iIdx = 0; $iIdx < count($aHistoryEntries) && $iIdx < $iMaxHistoryResults; $iIdx++) + for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) { $sClass = $aHistoryEntries[$iIdx]['class']; @@ -124,4 +120,18 @@ class QuickCreateHelper 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('quick_create.max_history_results'); + if(count($aHistoryEntries) > $iMaxHistoryResults) + { + $aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults); + } + } } \ No newline at end of file