Skip to content

Commit 95103fe

Browse files
committed
feat(wizard): selectable home page in service catalog
admin can choose between forms / kb search or list of assistance requests for the user
1 parent 5339b79 commit 95103fe

File tree

5 files changed

+142
-1
lines changed

5 files changed

+142
-1
lines changed

inc/entityconfig.class.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
6969
const CONFIG_UI_FORM_MASONRY = 0;
7070
const CONFIG_UI_FORM_UNIFORM_HEIGHT = 1;
7171

72+
const CONFIG_SERVICE_CATALOG_HOME_SEARCH = 0;
73+
const CONFIG_SERVICE_CATALOG_HOME_ISSUE = 1;
7274

7375
/**
7476
* @var bool $dohistory maintain history
@@ -157,6 +159,12 @@ public static function getEnumUIForm() : array {
157159
self::CONFIG_UI_FORM_UNIFORM_HEIGHT => __('Uniform height', 'formcreator'),
158160
];
159161
}
162+
public static function getEnumServiceCatalogHome() : array {
163+
return [
164+
self::CONFIG_SERVICE_CATALOG_HOME_SEARCH => __('Search for assistance', 'formcreator'),
165+
self::CONFIG_SERVICE_CATALOG_HOME_ISSUE => __('User\'s assistance requests', 'formcreator'),
166+
];
167+
}
160168

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

387+
// Service catalog home page
388+
$elements = self::getEnumServiceCatalogHome();
389+
if ($entityId == 0) {
390+
unset($elements[self::CONFIG_PARENT]);
391+
}
392+
echo "<tr class='tab_bg_1'>";
393+
echo "<td>".__('Service catalog home page', 'formcreator')."</td>";
394+
echo "<td>";
395+
Dropdown::showFromArray('service_catalog_home', $elements, ['value' => $this->fields['service_catalog_home']]);
396+
if ($this->fields['service_catalog_home'] == self::CONFIG_PARENT) {
397+
$tid = self::getUsedConfig('service_catalog_home', $entityId);
398+
echo '<br>';
399+
Entity::inheritedValue($elements[$tid], true);
400+
}
401+
echo '</td></tr>';
402+
379403
// Tiles Design
380404
$elements = self::getEnumUIForm();
381405
if ($entityId == 0) {
@@ -479,6 +503,56 @@ public function rawSearchOptions() {
479503
'massiveaction' => true,
480504
];
481505

506+
$tab[] = [
507+
'id' => '9',
508+
'table' => self::getTable(),
509+
'name' => __('Service catalog home page', 'formcreator'),
510+
'field' => 'service_catalog_home',
511+
'datatype' => 'integer',
512+
'nosearch' => true,
513+
'massiveaction' => false,
514+
];
515+
516+
$tab[] = [
517+
'id' => '10',
518+
'table' => self::getTable(),
519+
'name' => __('Default Form list mode', 'formcreator'),
520+
'field' => 'default_form_list_mode',
521+
'datatype' => 'integer',
522+
'nosearch' => true,
523+
'massiveaction' => false,
524+
];
525+
526+
$tab[] = [
527+
'id' => '11',
528+
'table' => self::getTable(),
529+
'name' => __('Counters dashboard', 'formcreator'),
530+
'field' => 'is_dashboard_visible',
531+
'datatype' => 'integer',
532+
'nosearch' => true,
533+
'massiveaction' => false,
534+
];
535+
536+
$tab[] = [
537+
'id' => '12',
538+
'table' => self::getTable(),
539+
'name' => __('Search issue', 'formcreator'),
540+
'field' => 'is_search_issue_visible',
541+
'datatype' => 'integer',
542+
'nosearch' => true,
543+
'massiveaction' => false,
544+
];
545+
546+
$tab[] = [
547+
'id' => '13',
548+
'table' => self::getTable(),
549+
'name' => __('Tile design', 'formcreator'),
550+
'field' => 'tile_design',
551+
'datatype' => 'integer',
552+
'nosearch' => true,
553+
'massiveaction' => false,
554+
];
555+
482556
return $tab;
483557
}
484558

install/install.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class PluginFormcreatorInstall {
7979
'2.12.5' => '2.13',
8080
'2.13' => '2.13.1',
8181
'2.13.1' => '2.13.3',
82+
'2.13.3' => '2.13.4',
8283
];
8384

8485
protected bool $resyncIssues = false;

install/mysql/plugin_formcreator_2.13.4_empty.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
3838
`is_search_issue_visible` int(11) NOT NULL DEFAULT '-2',
3939
`tile_design` int(11) NOT NULL DEFAULT '-2',
4040
`header` text,
41+
`service_catalog_home` int(11) NOT NULL DEFAULT '-2',
4142
PRIMARY KEY (`id`),
4243
UNIQUE KEY `unicity` (`entities_id`)
4344
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

install/upgrade_to_2.13.4.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2021 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
class PluginFormcreatorUpgradeTo2_13_4 {
32+
/** @var Migration */
33+
protected $migration;
34+
35+
public function isResyncIssuesRequired() {
36+
return true;
37+
}
38+
39+
/**
40+
* @param Migration $migration
41+
*/
42+
public function upgrade(Migration $migration) {
43+
$this->migration = $migration;
44+
$this->addServiceCatalogHopepage();
45+
}
46+
47+
public function addServiceCatalogHopepage() {
48+
$table = 'glpi_plugin_formcreator_entityconfigs';
49+
$this->migration->addField($table, 'service_catalog_home', 'integer', [
50+
'value' => -2,
51+
'after' => 'header',
52+
'update' => '0',
53+
'condition' => 'WHERE `entities_id` = 0'
54+
]);
55+
}
56+
}

setup.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,16 @@ function plugin_formcreator_redirect() {
425425
&& isset($_SESSION['glpiactive_entity'])) {
426426
// Interface and active entity are set in session
427427
if (plugin_formcreator_replaceHelpdesk()) {
428-
Html::redirect(FORMCREATOR_ROOTDOC."/front/wizard.php");
428+
switch (PluginFormcreatorEntityConfig::getUsedConfig('service_catalog_home', $_SESSION['glpiactive_entity'])) {
429+
case PluginFormcreatorEntityConfig::CONFIG_SERVICE_CATALOG_HOME_SEARCH:
430+
$homepage = '/front/wizard.php';
431+
break;
432+
433+
case PluginFormcreatorEntityConfig::CONFIG_SERVICE_CATALOG_HOME_ISSUE:
434+
$homepage = '/front/issue.php';
435+
break;
436+
}
437+
Html::redirect(Plugin::getWebDir('formcreator') . $homepage);
429438
}
430439
}
431440
}

0 commit comments

Comments
 (0)