Skip to content

Commit

Permalink
feat(wizard): selectable home page in service catalog
Browse files Browse the repository at this point in the history
admin can choose between forms / kb search or list of assistance requests for the user
  • Loading branch information
btry committed Dec 14, 2022
1 parent 5339b79 commit 95103fe
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 1 deletion.
74 changes: 74 additions & 0 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
const CONFIG_UI_FORM_MASONRY = 0;
const CONFIG_UI_FORM_UNIFORM_HEIGHT = 1;

const CONFIG_SERVICE_CATALOG_HOME_SEARCH = 0;
const CONFIG_SERVICE_CATALOG_HOME_ISSUE = 1;

/**
* @var bool $dohistory maintain history
Expand Down Expand Up @@ -157,6 +159,12 @@ public static function getEnumUIForm() : array {
self::CONFIG_UI_FORM_UNIFORM_HEIGHT => __('Uniform height', 'formcreator'),
];
}
public static function getEnumServiceCatalogHome() : array {
return [
self::CONFIG_SERVICE_CATALOG_HOME_SEARCH => __('Search for assistance', 'formcreator'),
self::CONFIG_SERVICE_CATALOG_HOME_ISSUE => __('User\'s assistance requests', 'formcreator'),
];
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Entity') {
Expand Down Expand Up @@ -376,6 +384,22 @@ public function showFormForEntity(Entity $entity) {
}
echo '</td></tr>';

// Service catalog home page
$elements = self::getEnumServiceCatalogHome();
if ($entityId == 0) {
unset($elements[self::CONFIG_PARENT]);
}
echo "<tr class='tab_bg_1'>";
echo "<td>".__('Service catalog home page', 'formcreator')."</td>";
echo "<td>";
Dropdown::showFromArray('service_catalog_home', $elements, ['value' => $this->fields['service_catalog_home']]);
if ($this->fields['service_catalog_home'] == self::CONFIG_PARENT) {
$tid = self::getUsedConfig('service_catalog_home', $entityId);
echo '<br>';
Entity::inheritedValue($elements[$tid], true);
}
echo '</td></tr>';

// Tiles Design
$elements = self::getEnumUIForm();
if ($entityId == 0) {
Expand Down Expand Up @@ -479,6 +503,56 @@ public function rawSearchOptions() {
'massiveaction' => true,
];

$tab[] = [
'id' => '9',
'table' => self::getTable(),
'name' => __('Service catalog home page', 'formcreator'),
'field' => 'service_catalog_home',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '10',
'table' => self::getTable(),
'name' => __('Default Form list mode', 'formcreator'),
'field' => 'default_form_list_mode',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '11',
'table' => self::getTable(),
'name' => __('Counters dashboard', 'formcreator'),
'field' => 'is_dashboard_visible',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '12',
'table' => self::getTable(),
'name' => __('Search issue', 'formcreator'),
'field' => 'is_search_issue_visible',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

$tab[] = [
'id' => '13',
'table' => self::getTable(),
'name' => __('Tile design', 'formcreator'),
'field' => 'tile_design',
'datatype' => 'integer',
'nosearch' => true,
'massiveaction' => false,
];

return $tab;
}

Expand Down
1 change: 1 addition & 0 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PluginFormcreatorInstall {
'2.12.5' => '2.13',
'2.13' => '2.13.1',
'2.13.1' => '2.13.3',
'2.13.3' => '2.13.4',
];

protected bool $resyncIssues = false;
Expand Down
1 change: 1 addition & 0 deletions install/mysql/plugin_formcreator_2.13.4_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
`is_search_issue_visible` int(11) NOT NULL DEFAULT '-2',
`tile_design` int(11) NOT NULL DEFAULT '-2',
`header` text,
`service_catalog_home` int(11) NOT NULL DEFAULT '-2',
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`entities_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
Expand Down
56 changes: 56 additions & 0 deletions install/upgrade_to_2.13.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/
class PluginFormcreatorUpgradeTo2_13_4 {
/** @var Migration */
protected $migration;

public function isResyncIssuesRequired() {
return true;
}

/**
* @param Migration $migration
*/
public function upgrade(Migration $migration) {
$this->migration = $migration;
$this->addServiceCatalogHopepage();
}

public function addServiceCatalogHopepage() {
$table = 'glpi_plugin_formcreator_entityconfigs';
$this->migration->addField($table, 'service_catalog_home', 'integer', [
'value' => -2,
'after' => 'header',
'update' => '0',
'condition' => 'WHERE `entities_id` = 0'
]);
}
}
11 changes: 10 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,16 @@ function plugin_formcreator_redirect() {
&& isset($_SESSION['glpiactive_entity'])) {
// Interface and active entity are set in session
if (plugin_formcreator_replaceHelpdesk()) {
Html::redirect(FORMCREATOR_ROOTDOC."/front/wizard.php");
switch (PluginFormcreatorEntityConfig::getUsedConfig('service_catalog_home', $_SESSION['glpiactive_entity'])) {
case PluginFormcreatorEntityConfig::CONFIG_SERVICE_CATALOG_HOME_SEARCH:
$homepage = '/front/wizard.php';
break;

case PluginFormcreatorEntityConfig::CONFIG_SERVICE_CATALOG_HOME_ISSUE:
$homepage = '/front/issue.php';
break;
}
Html::redirect(Plugin::getWebDir('formcreator') . $homepage);
}
}
}
Expand Down

0 comments on commit 95103fe

Please sign in to comment.