From 1bd9d35979986a80e169190943e7bb9a621b6f47 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 9 Oct 2020 09:21:37 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02847=20-=20Quick=20create:=20Add=20confi?= =?UTF-8?q?g.=20parameter=20for=20max.=20history=20results=20('quick=5Fcre?= =?UTF-8?q?ate.max=5Fhistory=5Fresults')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.class.inc.php | 8 ++++++++ .../UI/Component/QuickCreate/QuickCreate.php | 12 ++++++++++++ .../UI/Component/QuickCreate/QuickCreateHelper.php | 13 ++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 0b002db8c..67919c8e6 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1144,6 +1144,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ), + 'quick_create.max_history_results' => array( + 'type' => 'integer', + 'description' => 'Max. number of elements in the history.', + 'default' => 10, + 'value' => 10, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), 'global_search.enabled' => array( 'type' => 'bool', 'description' => 'Whether or not the global search is enabled', diff --git a/sources/application/UI/Component/QuickCreate/QuickCreate.php b/sources/application/UI/Component/QuickCreate/QuickCreate.php index e20c42f6b..20c8d3c5d 100644 --- a/sources/application/UI/Component/QuickCreate/QuickCreate.php +++ b/sources/application/UI/Component/QuickCreate/QuickCreate.php @@ -55,6 +55,8 @@ class QuickCreate extends UIBlock protected $aLastClasses; /** @var int $iMaxAutocompleteResults Max. number of elements returned by the autocomplete */ protected $iMaxAutocompleteResults; + /** @var int $iMaxHistoryResults Max. number of elements in the history */ + protected $iMaxHistoryResults; /** * QuickCreate constructor. @@ -71,6 +73,7 @@ class QuickCreate extends UIBlock $this->aAvailableClasses = UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true); $this->aLastClasses = $aLastClasses; $this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results'); + $this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); } /** @@ -115,4 +118,13 @@ class QuickCreate extends UIBlock { return $this->iMaxAutocompleteResults; } + + /** + * @see $iMaxHistoryResults + * @return int + */ + public function GetMaxHistoryResults(): int + { + return $this->iMaxHistoryResults; + } } \ No newline at end of file diff --git a/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php b/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php index 41635c6bc..c961d734e 100644 --- a/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php +++ b/sources/application/UI/Component/QuickCreate/QuickCreateHelper.php @@ -35,7 +35,7 @@ use utils; */ class QuickCreateHelper { - public const MAX_HISTORY_SIZE = 10; + /** @var string */ public const USER_PREF_CODE = 'quick_create_history'; /** @@ -49,7 +49,7 @@ class QuickCreateHelper * @throws \MySQLException * @throws \Exception */ - public static function AddClassToHistory($sClass) + public static function AddClassToHistory(string $sClass) { $aNewEntry = [ 'class' => $sClass, @@ -71,9 +71,10 @@ class QuickCreateHelper array_unshift($aHistoryEntries, $aNewEntry); // Truncate history - if(count($aHistoryEntries) > static::MAX_HISTORY_SIZE) + $iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); + if(count($aHistoryEntries) > $iMaxHistoryResults) { - $aHistoryEntries = array_slice($aHistoryEntries, 0, static::MAX_HISTORY_SIZE); + $aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults); } appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries); @@ -89,9 +90,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, []); - for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) + for($iIdx = 0; $iIdx < count($aHistoryEntries) && $iIdx < $iMaxHistoryResults; $iIdx++) { $sClass = $aHistoryEntries[$iIdx]['class'];