mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 01:58:47 +02:00
N°2847 - Quick create: Add config. parameter for max. history results ('quick_create.max_history_results')
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user