Skip to content

Commit b37e1c0

Browse files
stonebuzzbtry
andauthored
feat(issue): add option to hide search Issue if needed
Co-authored-by: btry <tbugier@teclib.com>
1 parent 1fc81bc commit b37e1c0

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

front/issue.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,19 @@
5353
if (Session::getCurrentInterface() == 'helpdesk') {
5454
PluginFormcreatorCommon::showMiniDashboard();
5555
}
56+
57+
//backup session value
58+
$save_session_fold_search = $_SESSION['glpifold_search'];
59+
//hide search if need
60+
if (PluginFormcreatorEntityconfig::getUsedConfig('is_search_issue_visible', Session::getActiveEntity()) == PluginFormcreatorEntityconfig::CONFIG_SEARCH_ISSUE_HIDDEN) {
61+
$_SESSION['glpifold_search'] = true;
62+
}
63+
5664
Search::show('PluginFormcreatorIssue');
5765

66+
//restore session value
67+
$_SESSION['glpifold_search'] = $save_session_fold_search;
68+
5869
if (Session::getCurrentInterface() == "helpdesk") {
5970
Html::helpFooter();
6071
} else {

inc/entityconfig.class.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
6363
const CONFIG_DASHBOARD_HIDDEN = 0;
6464
const CONFIG_DASHBOARD_VISIBLE = 1;
6565

66+
const CONFIG_SEARCH_ISSUE_HIDDEN = 0;
67+
const CONFIG_SEARCH_ISSUE_VISIBLE = 1;
68+
6669
/**
6770
* @var bool $dohistory maintain history
6871
*/
@@ -135,6 +138,14 @@ public static function getEnumDashboardVisibility() : array {
135138
];
136139
}
137140

141+
public static function getEnumSearchIssueVisibility() : array {
142+
return [
143+
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
144+
self::CONFIG_SEARCH_ISSUE_VISIBLE => __('Visible', 'formcreator'),
145+
self::CONFIG_SEARCH_ISSUE_HIDDEN => __('Hidden', 'formcreator'),
146+
];
147+
}
148+
138149
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
139150
if ($item->getType() == 'Entity') {
140151
$config = new self();
@@ -315,6 +326,22 @@ public function showFormForEntity(Entity $entity) {
315326
}
316327
echo '</td></tr>';
317328

329+
// Search issue visibility
330+
$elements = self::getEnumSearchIssueVisibility();
331+
if ($entityId == 0) {
332+
unset($elements[self::CONFIG_PARENT]);
333+
}
334+
echo "<tr class='tab_bg_1'>";
335+
echo "<td>".__('Search issue', 'formcreator')."</td>";
336+
echo "<td>";
337+
Dropdown::showFromArray('is_search_issue_visible', $elements, ['value' => $this->fields['is_search_issue_visible']]);
338+
if ($this->fields['is_search_issue_visible'] == self::CONFIG_PARENT) {
339+
$tid = self::getUsedConfig('is_search_issue_visible', $entityId);
340+
echo '<br>';
341+
Entity::inheritedValue($elements[$tid], true);
342+
}
343+
echo '</td></tr>';
344+
318345
// header
319346
echo "<tr class='tab_bg_1'>";
320347
echo "<td>" . _n('Header', 'Headers', 1, 'formcreator') . "</td>";

install/install.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,16 @@ protected function configureExistingEntities() {
263263

264264
/** Value -2 is "inheritance from parent" @see PluginFormcreatorEntityconfig::CONFIG_PARENT */
265265
$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
266-
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible)
266+
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible, is_search_issue_visible)
267267
SELECT ent.id,
268268
IF(ent.id = 0, 0, -2),
269269
IF(ent.id = 0, 0, -2),
270270
IF(ent.id = 0, 0, -2),
271271
IF(ent.id = 0, 0, -2),
272272
IF(ent.id = 0, 0, -2),
273273
IF(ent.id = 0, 1, -2),
274-
IF(ent.id = 0, 0, -2)
274+
IF(ent.id = 0, 0, -2),
275+
IF(ent.id = 0, 1, -2)
275276
FROM glpi_entities ent
276277
LEFT JOIN glpi_plugin_formcreator_entityconfigs conf
277278
ON ent.id = conf.entities_id

install/mysql/plugin_formcreator_empty.sql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` (
2828
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2929

3030
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
31-
`id` int unsigned NOT NULL AUTO_INCREMENT,
32-
`entities_id` int unsigned NOT NULL DEFAULT '0',
33-
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
34-
`default_form_list_mode` int(11) NOT NULL DEFAULT '-2',
35-
`sort_order` int(11) NOT NULL DEFAULT '-2',
36-
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
37-
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
38-
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
39-
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
40-
`header` text,
31+
`id` int unsigned NOT NULL AUTO_INCREMENT,
32+
`entities_id` int unsigned NOT NULL DEFAULT '0',
33+
`replace_helpdesk` int(11) NOT NULL DEFAULT '-2',
34+
`default_form_list_mode` int(11) NOT NULL DEFAULT '-2',
35+
`sort_order` int(11) NOT NULL DEFAULT '-2',
36+
`is_kb_separated` int(11) NOT NULL DEFAULT '-2',
37+
`is_search_visible` int(11) NOT NULL DEFAULT '-2',
38+
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
39+
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
40+
`is_search_issue_visible` int(11) NOT NULL DEFAULT '-2',
41+
`header` text,
4142
PRIMARY KEY (`id`),
4243
UNIQUE KEY `unicity` (`entities_id`)
4344
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

install/upgrade_to_2.13.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public function upgrade(Migration $migration) {
4848
$this->addTargetValidationSetting();
4949
$this->addFormVisibility();
5050
$this->addRequestSourceSetting();
51+
$this->addEntityOption();
52+
}
53+
54+
public function addEntityOption() {
55+
global $DB;
56+
$table = 'glpi_plugin_formcreator_entityconfigs';
57+
58+
if (!$DB->fieldExists($table, 'is_search_issue_visible')) {
59+
$this->migration->addField($table, 'is_search_issue_visible', 'integer', ['after' => 'is_header_visible', 'value' => '-2']);
60+
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `is_search_issue_visible`= 1 WHERE `entities_id` = 0");
61+
}
5162
}
5263

5364
public function addFormAnswerTitle() {

0 commit comments

Comments
 (0)