N°2847 - Quick create: Add config. parameter for max. history results ('quick_create.max_history_results')

This commit is contained in:
Molkobain
2020-10-09 09:21:37 +02:00
parent 1dd4d1479c
commit 1bd9d35979
3 changed files with 28 additions and 5 deletions

View File

@@ -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'];