diff --git a/inc/entityconfig.class.php b/inc/entityconfig.class.php index 902fbfc7b..7dabee69c 100644 --- a/inc/entityconfig.class.php +++ b/inc/entityconfig.class.php @@ -40,9 +40,14 @@ class PluginFormcreatorEntityconfig extends CommonDBTM { const CONFIG_PARENT = -2; + + const CONFIG_GLPI_HELPDSK = 0; const CONFIG_SIMPLIFIED_SERVICE_CATALOG = 1; const CONFIG_EXTENDED_SERVICE_CATALOG = 2; + const CONFIG_SORT_POPULARITY = 0; + const CONFIG_SORT_ALPHABETICAL = 1; + /** * @var bool $dohistory maintain history */ @@ -58,6 +63,23 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { return $tabNames; } + public static function getEnumHelpdeskMode() { + return [ + self::CONFIG_PARENT => __('Inheritance of the parent entity'), + self::CONFIG_GLPI_HELPDSK => __('GLPi\'s helpdesk', 'formcreator'), + self::CONFIG_SIMPLIFIED_SERVICE_CATALOG => __('Service catalog simplified', 'formcreator'), + self::CONFIG_EXTENDED_SERVICE_CATALOG => __('Service catalog extended', 'formcreator'), + ]; + } + + public static function getEnumSort() { + return [ + self::CONFIG_PARENT => __('Inheritance of the parent entity'), + self::CONFIG_SORT_POPULARITY => __('Popularity sort', 'formcreator'), + self::CONFIG_SORT_ALPHABETICAL => __('Alphabetic sort', 'formcreator'), + ]; + } + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Entity') { $config = new self(); @@ -88,16 +110,10 @@ public function showFormForEntity(Entity $entity) { echo ""; echo ""; - if ($ID != 0) { - $elements = [ - self::CONFIG_PARENT => __('Inheritance of the parent entity') - ]; - } else { - $elements = []; + $elements = self::getEnumHelpdeskMode(); + if ($ID == 0) { + unset($elements[self::CONFIG_PARENT]); } - $elements[0] = __('GLPi\'s helpdesk', 'formcreator'); - $elements[1] = __('Service catalog simplified', 'formcreator'); - $elements[2] = __('Service catalog extended', 'formcreator'); echo ""; echo ""; @@ -111,6 +127,23 @@ public function showFormForEntity(Entity $entity) { } echo ''; + $elements = self::getEnumSort(); + if ($ID == 0) { + unset($elements[self::CONFIG_PARENT]); + } + + echo ""; + echo ""; + echo "'; + if ($canedit) { echo ""; echo "
".__('Helpdesk', 'formcreator')."
".__('Helpdesk mode', 'formcreator')."
".__('Sort order', 'formcreator').""; + Dropdown::showFromArray('sort_order', $elements, ['value' => $this->fields['sort_order']]); + if ($this->fields['replace_helpdesk'] == self::CONFIG_PARENT) { + $tid = self::getUsedConfig('sort_order', $ID); + echo '
'; + echo $elements[$tid]; + echo '
'; + } + echo '
"; @@ -125,6 +158,32 @@ public function showFormForEntity(Entity $entity) { } echo ""; + + } + public function rawSearchOptions() { + $tab = []; + + $tab[] = [ + 'id' => '3', + 'table' => self::getTable(), + 'name' => __('Helpdesk mode', 'formcreator'), + 'field' => 'replace_helpdesk', + 'datatype' => 'integer', + 'nosearch' => true, + 'massiveaction' => false, + ]; + + $tab[] = [ + 'id' => '4', + 'table' => self::getTable(), + 'name' => __('Sort order', 'formcreator'), + 'field' => 'sort_order', + 'datatype' => 'integer', + 'nosearch' => true, + 'massiveaction' => false, + ]; + + return $tab; } /** diff --git a/inc/form.class.php b/inc/form.class.php index bd330937c..af95647fe 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -795,14 +795,18 @@ public function showWizard($service_catalog = false) { echo ''; + $sortSettings = PluginFormcreatorEntityConfig::getEnumSort(); echo '
'; echo ''; - echo ''; - echo ''; + $sortOrder = PluginFormcreatorEntityconfig::getUsedConfig('sort_order', $_SESSION['glpiactive_entity']); + $selected = $sortOrder == PluginFormcreatorEntityconfig::CONFIG_SORT_POPULARITY ? 'checked="checked"' : ''; + echo ''; + echo ''; echo ''; echo ''; - echo ''; - echo ''; + $selected = $sortOrder == PluginFormcreatorEntityconfig::CONFIG_SORT_ALPHABETICAL ? 'checked="checked"' : ''; + echo ''; + echo ''; echo ''; echo '
'; echo '
'; diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index ba6c8df1b..a0da276e5 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -30,6 +30,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` ( CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` ( `id` int(11) NOT NULL, `replace_helpdesk` int(11) NOT NULL DEFAULT '0', + `sort_order` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/install/upgrade_to_2.11.php b/install/upgrade_to_2.11.php index 5ec6c96d1..efe3868f4 100644 --- a/install/upgrade_to_2.11.php +++ b/install/upgrade_to_2.11.php @@ -132,6 +132,18 @@ public function upgrade(Migration $migration) { $table = 'glpi_plugin_formcreator_targettickets'; $migration->addPostQuery("ALTER TABLE `$table` MODIFY `uuid` varchar(255) DEFAULT NULL AFTER `ola_question_ttr`"); $migration->migrationOneTable($table); + + // sort setting in entityes + $table = 'glpi_plugin_formcreator_entityconfigs'; + if (!$DB->fieldExists($table, 'sort_order')) { + // Write default settigns only if the columns must be created + $migration->addPostQuery("UPDATE `$table` + INNER JOIN `glpi_entities` ON (`$table`.`id` = `glpi_entities`.`id`) + SET `sort_order` = '-2' + WHERE `level` > '1'" + ); + } + $migration->addField($table, 'sort_order', 'integer', ['after' => 'replace_helpdesk']); } /** diff --git a/js/scripts.js.php b/js/scripts.js.php index 4b61554bd..d9665e166 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -175,9 +175,6 @@ function (response) { ); } }); - - // Initialize sort controls - $('.plugin_formcreator_sort [value=mostPopularSort]')[0].checked = true; } // === Add better multi-select on form configuration validators === diff --git a/tests/suite-unit/PluginFormcreatorEntityConfig.php b/tests/suite-unit/PluginFormcreatorEntityConfig.php index cd132918d..744e5321d 100644 --- a/tests/suite-unit/PluginFormcreatorEntityConfig.php +++ b/tests/suite-unit/PluginFormcreatorEntityConfig.php @@ -92,4 +92,14 @@ public function testGetUsedConfig() { $output = $instance::getUsedConfig('replace_helpdesk', $entityId2); $this->integer((int) $output)->isEqualTo(\PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG); } + + public function testgetEnumHelpdeskMode() { + $output = \PluginFormcreatorEntityconfig::getEnumHelpdeskMode(); + $this->array($output)->isEqualTo([ + \PluginFormcreatorEntityconfig::CONFIG_PARENT => __('Inheritance of the parent entity'), + \PluginFormcreatorEntityconfig::CONFIG_GLPI_HELPDSK => __('GLPi\'s helpdesk', 'formcreator'), + \PluginFormcreatorEntityconfig::CONFIG_SIMPLIFIED_SERVICE_CATALOG => __('Service catalog simplified', 'formcreator'), + \PluginFormcreatorEntityconfig::CONFIG_EXTENDED_SERVICE_CATALOG => __('Service catalog extended', 'formcreator'), + ]); + } }