diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 3534f7588..aa9d2dddf 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1436,6 +1436,14 @@ class Config 'quick_create.max_history_results' => [ 'type' => 'integer', 'description' => 'Max. number of elements in the history', + 'default' => 5, + 'value' => 5, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ], + 'quick_create.max_popular_results' => [ + 'type' => 'integer', + 'description' => 'Max. number of elements in the popular', 'default' => 10, 'value' => 10, 'source_of_value' => '', diff --git a/dictionaries/ui/components/quick-create/cs.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/cs.dictionary.itop.quick-create.php index d11e78fea..2b04cd3d3 100644 --- a/dictionaries/ui/components/quick-create/cs.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/cs.dictionary.itop.quick-create.php @@ -15,5 +15,6 @@ Dict::Add('CS CZ', 'Czech', 'Čeština', [ 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create~~', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet~~', 'UI:Component:QuickCreate:Recents:Title' => 'Recents~~', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Populární', 'UI:Component:QuickCreate:Tooltip' => 'Quickly create any type of object~~', ]); diff --git a/dictionaries/ui/components/quick-create/da.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/da.dictionary.itop.quick-create.php index 56cea8bae..b699a62f1 100644 --- a/dictionaries/ui/components/quick-create/da.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/da.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('DA DA', 'Danish', 'Dansk', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...~~', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create~~', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet~~', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular~~', 'UI:Component:QuickCreate:Recents:Title' => 'Recents~~', 'UI:Component:QuickCreate:Tooltip' => 'Quickly create any type of object~~', ]); diff --git a/dictionaries/ui/components/quick-create/de.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/de.dictionary.itop.quick-create.php index bd645fdbd..a63759816 100644 --- a/dictionaries/ui/components/quick-create/de.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/de.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('DE DE', 'German', 'Deutsch', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Wählen Sie einen Objekttyp aus...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Quick-Create-Menu öffnen', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Sie haben noch keine Objekte erstellt', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Am beliebtesten', 'UI:Component:QuickCreate:Recents:Title' => 'Letzte', 'UI:Component:QuickCreate:Tooltip' => 'Erstellen Sie schnell jeden Typ von Objekt', ]); diff --git a/dictionaries/ui/components/quick-create/en.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/en.dictionary.itop.quick-create.php index 58f9d2a9a..523395277 100644 --- a/dictionaries/ui/components/quick-create/en.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/en.dictionary.itop.quick-create.php @@ -23,6 +23,7 @@ Dict::Add('EN US', 'English', 'English', array( 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...', 'UI:Component:QuickCreate:Recents:Title' => 'Recents', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular', 'UI:Component:QuickCreate:HistoryDisabled' => 'History is disabled', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create', )); \ No newline at end of file diff --git a/dictionaries/ui/components/quick-create/en_gb.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/en_gb.dictionary.itop.quick-create.php index 331e8337e..f4fd1adad 100644 --- a/dictionaries/ui/components/quick-create/en_gb.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/en_gb.dictionary.itop.quick-create.php @@ -10,6 +10,7 @@ Dict::Add('EN GB', 'British English', 'British English', array( 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...', 'UI:Component:QuickCreate:Recents:Title' => 'Recents', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular', 'UI:Component:QuickCreate:HistoryDisabled' => 'History is disabled', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create', )); \ No newline at end of file diff --git a/dictionaries/ui/components/quick-create/es_cr.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/es_cr.dictionary.itop.quick-create.php index 799bebbed..8059c0508 100644 --- a/dictionaries/ui/components/quick-create/es_cr.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/es_cr.dictionary.itop.quick-create.php @@ -12,6 +12,7 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellano', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Seleccionar tipo de objeto...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Abrir creación rápida', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Aún no has creado ningún objeto.', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Más popular', 'UI:Component:QuickCreate:Recents:Title' => 'Recientes', 'UI:Component:QuickCreate:Tooltip' => 'Crear rápidamente cualquier tipo de objeto', ]); diff --git a/dictionaries/ui/components/quick-create/fr.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/fr.dictionary.itop.quick-create.php index c401948a1..01662ea7b 100644 --- a/dictionaries/ui/components/quick-create/fr.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/fr.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('FR FR', 'French', 'Français', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Type d\'objet...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Ouvrir la création rapide', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Vous n\'avez pas encore créé d\'objet', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Populaires', 'UI:Component:QuickCreate:Recents:Title' => 'Types récents', 'UI:Component:QuickCreate:Tooltip' => 'Création rapide de n\'importe quel objet', ]); diff --git a/dictionaries/ui/components/quick-create/hu.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/hu.dictionary.itop.quick-create.php index d34aa000d..4cfe344c4 100644 --- a/dictionaries/ui/components/quick-create/hu.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/hu.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('HU HU', 'Hungarian', 'Magyar', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Objektumtípus kiválasztása...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Gyors létrehozás megnyitása', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Még nem hozott létre objektumot', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Legnépszerűbb', 'UI:Component:QuickCreate:Recents:Title' => 'Legutóbbiak', 'UI:Component:QuickCreate:Tooltip' => 'Bármilyen típusú objektum gyors létrehozása', ]); diff --git a/dictionaries/ui/components/quick-create/it.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/it.dictionary.itop.quick-create.php index 7b5a79253..60798b551 100644 --- a/dictionaries/ui/components/quick-create/it.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/it.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('IT IT', 'Italian', 'Italiano', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Seleziona il tipo di oggetto...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Apri la creazione rapida', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Non hai ancora creato alcun oggetto', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Più popolari', 'UI:Component:QuickCreate:Recents:Title' => 'Recenti', 'UI:Component:QuickCreate:Tooltip' => 'Crea rapidamente qualsiasi tipo di oggetto', ]); diff --git a/dictionaries/ui/components/quick-create/ja.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/ja.dictionary.itop.quick-create.php index 97f47d3ab..4581d44cb 100644 --- a/dictionaries/ui/components/quick-create/ja.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/ja.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('JA JP', 'Japanese', '日本語', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...~~', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create~~', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet~~', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular~~', 'UI:Component:QuickCreate:Recents:Title' => 'Recents~~', 'UI:Component:QuickCreate:Tooltip' => 'Quickly create any type of object~~', ]); diff --git a/dictionaries/ui/components/quick-create/nl.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/nl.dictionary.itop.quick-create.php index 32725079b..05186947a 100644 --- a/dictionaries/ui/components/quick-create/nl.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/nl.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('NL NL', 'Dutch', 'Nederlands', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Selecteer een objectsoort…', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open snel object aanmaken', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Je hebt nog geen objecten gemaakt', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Meest populair', 'UI:Component:QuickCreate:Recents:Title' => 'Recente', 'UI:Component:QuickCreate:Tooltip' => 'Snel een object aanmaken', ]); diff --git a/dictionaries/ui/components/quick-create/pl.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/pl.dictionary.itop.quick-create.php index eab616904..bf34c7511 100644 --- a/dictionaries/ui/components/quick-create/pl.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/pl.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('PL PL', 'Polish', 'Polski', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Wybierz typ obiektu...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Otwórz szybkie tworzenie', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Nie utworzyłeś jeszcze żadnego obiektu', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Najbardziej popularne', 'UI:Component:QuickCreate:Recents:Title' => 'Ostatnie', 'UI:Component:QuickCreate:Tooltip' => 'Szybko utwórz dowolny rodzaj obiektu', ]); diff --git a/dictionaries/ui/components/quick-create/pt_br.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/pt_br.dictionary.itop.quick-create.php index 4df567fec..7709924ec 100644 --- a/dictionaries/ui/components/quick-create/pt_br.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/pt_br.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('PT BR', 'Brazilian', 'Brazilian', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Selecione o tipo de objeto...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Abrir criação rápida', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Você ainda não criou nenhum objeto', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Mais popular', 'UI:Component:QuickCreate:Recents:Title' => 'Recentes', 'UI:Component:QuickCreate:Tooltip' => 'Crie rapidamente qualquer tipo de objeto', ]); diff --git a/dictionaries/ui/components/quick-create/ru.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/ru.dictionary.itop.quick-create.php index 7f6d9179e..b6d3dad55 100755 --- a/dictionaries/ui/components/quick-create/ru.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/ru.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('RU RU', 'Russian', 'Русский', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Выбрать тип объекта...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Открыть быстрое создание объекта', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'Вы ещё не создавали объекты', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Популярные', 'UI:Component:QuickCreate:Recents:Title' => 'Недавние', 'UI:Component:QuickCreate:Tooltip' => 'Быстрое создание объекта любого типа', ]); diff --git a/dictionaries/ui/components/quick-create/sk.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/sk.dictionary.itop.quick-create.php index 448b02f35..32415e0bd 100644 --- a/dictionaries/ui/components/quick-create/sk.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/sk.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('SK SK', 'Slovak', 'Slovenčina', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...~~', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create~~', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet~~', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular~~', 'UI:Component:QuickCreate:Recents:Title' => 'Recents~~', 'UI:Component:QuickCreate:Tooltip' => 'Quickly create any type of object~~', ]); diff --git a/dictionaries/ui/components/quick-create/tr.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/tr.dictionary.itop.quick-create.php index 2636da717..9f20f9b01 100644 --- a/dictionaries/ui/components/quick-create/tr.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/tr.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('TR TR', 'Turkish', 'Türkçe', [ 'UI:Component:QuickCreate:Input:Placeholder' => 'Select object type...~~', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => 'Open quick create~~', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => 'You haven\'t create any object yet~~', + 'UI:Component:QuickCreate:MostPopular:Title' => 'Most popular~~', 'UI:Component:QuickCreate:Recents:Title' => 'Recents~~', 'UI:Component:QuickCreate:Tooltip' => 'Quickly create any type of object~~', ]); diff --git a/dictionaries/ui/components/quick-create/zh_cn.dictionary.itop.quick-create.php b/dictionaries/ui/components/quick-create/zh_cn.dictionary.itop.quick-create.php index 194a63a8b..e501648f9 100644 --- a/dictionaries/ui/components/quick-create/zh_cn.dictionary.itop.quick-create.php +++ b/dictionaries/ui/components/quick-create/zh_cn.dictionary.itop.quick-create.php @@ -14,6 +14,7 @@ Dict::Add('ZH CN', 'Chinese', '简体中文', [ 'UI:Component:QuickCreate:Input:Placeholder' => '请选择对象类型...', 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer' => '打开快速创建', 'UI:Component:QuickCreate:LastClasses:NoClass:Placeholder' => '您尚未创建任何对象', + 'UI:Component:QuickCreate:MostPopular:Title' => '最常用', 'UI:Component:QuickCreate:Recents:Title' => '最近', 'UI:Component:QuickCreate:Tooltip' => '快速创建任意类型的对象', ]); diff --git a/sources/Application/UI/Base/Component/QuickCreate/QuickCreate.php b/sources/Application/UI/Base/Component/QuickCreate/QuickCreate.php index b7ae9ee76..a4dcc0a31 100644 --- a/sources/Application/UI/Base/Component/QuickCreate/QuickCreate.php +++ b/sources/Application/UI/Base/Component/QuickCreate/QuickCreate.php @@ -59,10 +59,14 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut protected $aLastClasses; /** @var int $iMaxAutocompleteResults Max. number of elements returned by the autocomplete */ protected $iMaxAutocompleteResults; - /** @var bool $bShowHistory Whether or not to display the elements in the history */ + /** @var bool $bShowHistory Whether to display the elements in the history */ protected $bShowHistory; /** @var int $iMaxHistoryResults Max. number of elements in the history */ protected $iMaxHistoryResults; + /** @var int $iMaxPopularResults Max. number of elements in popular */ + protected $iMaxPopularResults; + /** @var array $aPopularClasses */ + protected $aPopularClasses; /** * QuickCreate constructor. @@ -82,6 +86,8 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut $this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results'); $this->bShowHistory = (bool) MetaModel::GetConfig()->Get('quick_create.show_history'); $this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); + $this->iMaxPopularResults = (int) MetaModel::GetConfig()->Get('quick_create.max_popular_results'); + $this->aPopularClasses = QuickCreateHelper::GetPopularClasses(); } /** @@ -89,7 +95,7 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut * If $bRelativeUrl is true, then $sEndpoint will be complete with the app_root_url * * @param string $sEndpoint URL to the endpoint - * @param bool $bRelativeUrl Whether or not the $sEndpoint parameter is a relative URL + * @param bool $bRelativeUrl Whether the $sEndpoint parameter is a relative URL * * @return $this * @throws \Exception @@ -203,6 +209,24 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut return $this->iMaxHistoryResults; } + /** + * @see $aMaxPopularClasses + * @return array + */ + public function GetPopularClasses(): array + { + return $this->aPopularClasses; + } + + /** + * @see $iMaxPopularResults + * @return int + */ + public function GetMaxPopularResults(): int + { + return $this->iMaxPopularResults; + } + public static function GetShortcutKeys(): array { return [['id' => 'ibo-open-quick-create', 'label' => 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer', 'key' => 'c', 'event' => 'open_drawer']]; diff --git a/sources/Application/UI/Base/Component/QuickCreate/QuickCreateHelper.php b/sources/Application/UI/Base/Component/QuickCreate/QuickCreateHelper.php index 63c066fca..e2c5e3404 100644 --- a/sources/Application/UI/Base/Component/QuickCreate/QuickCreateHelper.php +++ b/sources/Application/UI/Base/Component/QuickCreate/QuickCreateHelper.php @@ -24,6 +24,7 @@ use appUserPreferences; use DBObject; use MetaModel; use utils; +use UserRights; /** * Class QuickCreateHelper @@ -71,7 +72,7 @@ class QuickCreateHelper array_unshift($aHistoryEntries, $aNewEntry); // Truncate history - static::TruncateHistory($aHistoryEntries); + static::Truncate($aHistoryEntries, 'quick_create.max_history_results'); appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries); } @@ -88,7 +89,8 @@ class QuickCreateHelper { /** @var array $aHistoryEntries */ $aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []); - static::TruncateHistory($aHistoryEntries); + + static::Truncate($aHistoryEntries, 'quick_create.max_history_results'); for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) { @@ -125,16 +127,70 @@ class QuickCreateHelper } /** - * Truncate $aHistoryEntries to 'global_search.max_history_results' entries + * Return an array of popular object classes * - * @param array $aHistoryEntries + * @return array + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException */ - protected static function TruncateHistory(array &$aHistoryEntries): void + public static function GetPopularClasses(): array { - $iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results'); - if(count($aHistoryEntries) > $iMaxHistoryResults) + $aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []); + static::Truncate($aHistoryEntries, 'quick_create.max_history_results'); + $aPopularClassesNames = UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('popular'), false); + + // Prevent classes in both Popular and Recent to appear twice + for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) { - $aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults); + if (($key = array_search($aHistoryEntries[$iIdx]['class'], $aPopularClassesNames)) !== false) { + unset($aPopularClassesNames[$key]); + } + } + //die(var_dump($aPopularClassesNames)); + static::Truncate($aPopularClassesNames, 'quick_create.max_popular_results'); + $aPopularClasses = array(); + foreach($aPopularClassesNames as $sClass) + { + if (!MetaModel::IsValidClass($sClass)) { + continue; + } + + // Add class icon + $sClassIconUrl = MetaModel::GetClassIcon($sClass, false); + // Mind that some classes don't have an icon + $sClassIconUrl = !empty($sClassIconUrl) ? $sClassIconUrl : null; + + // Add class label + $sLabelHtml = utils::EscapeHtml(MetaModel::GetName($sClass)); + + // Add URL + $sTargetUrl = DBObject::ComputeStandardUIPage($sClass).'?operation=new&class='.$sClass; + + $aPopularClasses[] = array( + 'class' => $sClass, + 'icon_url' => $sClassIconUrl, + 'label_html' => $sLabelHtml, + 'target_url' => $sTargetUrl + ); + } + return $aPopularClasses; + } + + /** + * Truncate $aHistoryEntries to 'global_search.max_history_results' entries OR $aPopularClasses to 'global_search.max_popular_results' + * + * @param array $aEntries + * @param string $sMaxEntriesParam + */ + protected static function Truncate(array &$aEntries, string $sMaxEntriesParam = 'global_search.max_history_results'): void + { + $iMaxResults = (int) MetaModel::GetConfig()->Get($sMaxEntriesParam); + if(count($aEntries) > $iMaxResults) + { + $aEntries = array_slice($aEntries, 0, $iMaxResults); } } + + } \ No newline at end of file diff --git a/templates/base/components/quick-create/layout.html.twig b/templates/base/components/quick-create/layout.html.twig index ad17277b5..bf66f9de1 100644 --- a/templates/base/components/quick-create/layout.html.twig +++ b/templates/base/components/quick-create/layout.html.twig @@ -48,6 +48,22 @@ {% endif %} +
+ {{ 'UI:Component:QuickCreate:MostPopular:Title'|dict_s }} +
+
+ {% if oUIBlock.GetPopularClasses()|length > 0 %} + {% for aClass in oUIBlock.GetPopularClasses() %} + + {% if aClass.icon_url is defined and aClass.icon_url is not null%} + {# Mind the empty "alt" attribute https://www.w3.org/WAI/tutorials/images/decorative/ #} + + {% endif %} + {{ aClass.label_html|raw }} + + {% endfor %} + {% endif %} +
\ No newline at end of file diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/UI/Base/Components/QuickCreate/QuickCreateHelperTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/UI/Base/Components/QuickCreate/QuickCreateHelperTest.php new file mode 100644 index 000000000..4bdb966f0 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/sources/Application/UI/Base/Components/QuickCreate/QuickCreateHelperTest.php @@ -0,0 +1,44 @@ +assertNotEquals($aPopularClassNoParam[$iIdx]['class'], $sPopularClass); + } + + return [$aClasses, $aPopularClassesInitial]; + } + + /** + * Test class addition in popular after being removed from recent classes + * @depends testNoDuplicateInPopularAndLast + */ + public function testPopularClassBackAfterRecent(array $aNoDuplicateResult){ + [$aClasses, $aPopularClassesInitial] = $aNoDuplicateResult; + + foreach($aClasses as $sClass) + { + QuickCreateHelper::AddClassToHistory($sClass); + } + $aPopularClassesFinal = QuickCreateHelper::GetPopularClasses(); + $this->assertEquals($aPopularClassesInitial, $aPopularClassesFinal); + } +} \ No newline at end of file