Skip to content

Commit 539604d

Browse files
committed
feat(issue): group validator in issue
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent b110ed3 commit 539604d

File tree

5 files changed

+159
-104
lines changed

5 files changed

+159
-104
lines changed

hook.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function plugin_formcreator_addDefaultWhere($itemtype) {
142142
$condition = Search::addDefaultWhere(Ticket::class);
143143
$condition = str_replace('`glpi_tickets`', '`glpi_plugin_formcreator_issues`', $condition);
144144
$condition = str_replace('`users_id_recipient`', '`requester_id`', $condition);
145-
$condition = "($condition OR `glpi_plugin_formcreator_issues`.`validator_id` = '" . Session::getLoginUserID() . "')";
145+
$condition = "($condition OR `glpi_plugin_formcreator_issues`.`users_id_validator` = '" . Session::getLoginUserID() . "')";
146146
break;
147147

148148
case PluginFormcreatorFormAnswer::class:
@@ -178,10 +178,16 @@ function plugin_formcreator_addLeftJoin($itemtype, $ref_table, $new_table, $link
178178
if ($new_table == 'glpi_groups') {
179179
foreach ($already_link_tables as $table) {
180180
if (strpos($table, $new_table) === 0) {
181-
$AS = $table;
181+
$ref = explode('.', $table);
182+
$AS = $ref[0];
183+
$fk = getForeignKeyFieldForTable($ref[0]);
184+
if (count($ref) > 1) {
185+
$AS = $ref[0];
186+
$fk = $ref[1];
187+
}
182188
}
183189
}
184-
$join = " LEFT JOIN `$new_table` AS `$AS` ON (`glpi_groups_tickets_original_id`.`groups_id` = `$AS`.`id`) ";
190+
$join = " LEFT JOIN `$new_table` AS `$AS` ON (`$ref_table`.`$fk` = `$AS`.`id`) ";
185191
}
186192

187193
if ($new_table == 'glpi_users' && $linkfield == 'users_id') {
@@ -190,7 +196,7 @@ function plugin_formcreator_addLeftJoin($itemtype, $ref_table, $new_table, $link
190196
$AS = $table;
191197
}
192198
}
193-
$join = " LEFT JOIN `$new_table` AS `$AS` ON (`glpi_tickets_users_original_id`.`users_id` = `$AS`.`id`) ";
199+
$join = " LEFT JOIN `$new_table` AS `$AS` ON (`$ref_table`.`users_id` = `$AS`.`id`) ";
194200
}
195201
break;
196202
}

inc/formanswer.class.php

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,17 +1331,18 @@ private function createIssue() {
13311331
// There are several tickets for this form answer
13321332
// The issue must be created from this form answer
13331333
$issue->add([
1334-
'original_id' => $this->getID(),
1335-
'sub_itemtype' => PluginFormcreatorFormAnswer::class,
1336-
'name' => addslashes($this->fields['name']),
1337-
'status' => $this->fields['status'],
1338-
'date_creation' => $this->fields['request_date'],
1339-
'date_mod' => $this->fields['request_date'],
1340-
'entities_id' => $this->fields['entities_id'],
1341-
'is_recursive' => $this->fields['is_recursive'],
1342-
'requester_id' => $this->fields['requester_id'],
1343-
'validator_id' => $this->fields['users_id_validator'],
1344-
'comment' => '',
1334+
'original_id' => $this->getID(),
1335+
'sub_itemtype' => PluginFormcreatorFormAnswer::class,
1336+
'name' => addslashes($this->fields['name']),
1337+
'status' => $this->fields['status'],
1338+
'date_creation' => $this->fields['request_date'],
1339+
'date_mod' => $this->fields['request_date'],
1340+
'entities_id' => $this->fields['entities_id'],
1341+
'is_recursive' => $this->fields['is_recursive'],
1342+
'requester_id' => $this->fields['requester_id'],
1343+
'users_id_validator' => $this->fields['users_id_validator'],
1344+
'groups_id_validator'=> $this->fields['groups_id_validator'],
1345+
'comment' => '',
13451346
]);
13461347
} else {
13471348
// There is one ticket for this form answer
@@ -1365,17 +1366,18 @@ private function createIssue() {
13651366
);
13661367
$ticketUserRow = array_pop($ticketUserRow);
13671368
$issue->add([
1368-
'original_id' => $ticketId,
1369-
'sub_itemtype' => Ticket::class,
1370-
'name' => addslashes($ticket->getField('name')),
1371-
'status' => $ticket->getField('status'),
1372-
'date_creation' => $ticket->getField('date'),
1373-
'date_mod' => $ticket->getField('date_mod'),
1374-
'entities_id' => $ticket->getField('entities_id'),
1375-
'is_recursive' => '0',
1376-
'requester_id' => $ticketUserRow['users_id'],
1377-
'validator_id' => '',
1378-
'comment' => addslashes($ticket->getField('content')),
1369+
'original_id' => $ticketId,
1370+
'sub_itemtype' => Ticket::class,
1371+
'name' => addslashes($ticket->getField('name')),
1372+
'status' => $ticket->getField('status'),
1373+
'date_creation' => $ticket->getField('date'),
1374+
'date_mod' => $ticket->getField('date_mod'),
1375+
'entities_id' => $ticket->getField('entities_id'),
1376+
'is_recursive' => '0',
1377+
'requester_id' => $ticketUserRow['users_id'],
1378+
'users_id_validator' => '',
1379+
'groups_id_validator'=> '',
1380+
'comment' => addslashes($ticket->getField('content')),
13791381
]);
13801382
}
13811383
}
@@ -1404,18 +1406,19 @@ private function updateIssue() {
14041406
]
14051407
]);
14061408
$issue->update([
1407-
'id' => $issue->getID(),
1408-
'original_id' => $this->getID(),
1409-
'sub_itemtype' => PluginFormcreatorFormAnswer::class,
1410-
'name' => addslashes($this->fields['name']),
1411-
'status' => $this->fields['status'],
1412-
'date_creation' => $this->fields['request_date'],
1413-
'date_mod' => $this->fields['request_date'],
1414-
'entities_id' => $this->fields['entities_id'],
1415-
'is_recursive' => $this->fields['is_recursive'],
1416-
'requester_id' => $this->fields['requester_id'],
1417-
'validator_id' => $this->fields['users_id_validator'],
1418-
'comment' => '',
1409+
'id' => $issue->getID(),
1410+
'original_id' => $this->getID(),
1411+
'sub_itemtype' => PluginFormcreatorFormAnswer::class,
1412+
'name' => addslashes($this->fields['name']),
1413+
'status' => $this->fields['status'],
1414+
'date_creation' => $this->fields['request_date'],
1415+
'date_mod' => $this->fields['request_date'],
1416+
'entities_id' => $this->fields['entities_id'],
1417+
'is_recursive' => $this->fields['is_recursive'],
1418+
'requester_id' => $this->fields['requester_id'],
1419+
'users_id_validator' => $this->fields['users_id_validator'],
1420+
'groups_id_validator'=> $this->fields['groups_id_validator'],
1421+
'comment' => '',
14191422
]);
14201423
} else {
14211424
// There is one ticket for this form answer
@@ -1445,18 +1448,19 @@ private function updateIssue() {
14451448
]
14461449
]);
14471450
$issue->update([
1448-
'id' => $issue->getID(),
1449-
'original_id' => $ticketId,
1450-
'sub_itemtype' => Ticket::class,
1451-
'name' => addslashes($ticket->getField('name')),
1452-
'status' => $ticket->getField('status'),
1453-
'date_creation' => $ticket->getField('date'),
1454-
'date_mod' => $ticket->getField('date_mod'),
1455-
'entities_id' => $ticket->getField('entities_id'),
1456-
'is_recursive' => '0',
1457-
'requester_id' => $ticketUserRow['users_id'],
1458-
'validator_id' => '',
1459-
'comment' => addslashes($ticket->getField('content')),
1451+
'id' => $issue->getID(),
1452+
'original_id' => $ticketId,
1453+
'sub_itemtype' => Ticket::class,
1454+
'name' => addslashes($ticket->getField('name')),
1455+
'status' => $ticket->getField('status'),
1456+
'date_creation' => $ticket->getField('date'),
1457+
'date_mod' => $ticket->getField('date_mod'),
1458+
'entities_id' => $ticket->getField('entities_id'),
1459+
'is_recursive' => '0',
1460+
'requester_id' => $ticketUserRow['users_id'],
1461+
'users_id_validator' => '',
1462+
'groups_id_validator'=> '',
1463+
'comment' => addslashes($ticket->getField('content')),
14601464
]);
14611465
}
14621466
} else {

inc/issue.class.php

Lines changed: 85 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,20 @@ public static function cronSyncIssues(CronTask $task) {
7272
// 1 ticket linked to 1 form_answer => 1 issue which is the ticket sub_itemtype
7373
// several tickets linked to the same form_answer => 1 issue which is the form_answer sub_itemtype
7474
$query = "SELECT DISTINCT
75-
NULL AS `id`,
76-
`f`.`name` AS `name`,
77-
CONCAT('f_',`fanswer`.`id`) AS `display_id`,
78-
`fanswer`.`id` AS `original_id`,
79-
'PluginFormcreatorFormAnswer' AS `sub_itemtype`,
80-
`fanswer`.`status` AS `status`,
81-
`fanswer`.`request_date` AS `date_creation`,
82-
`fanswer`.`request_date` AS `date_mod`,
83-
`fanswer`.`entities_id` AS `entities_id`,
84-
`fanswer`.`is_recursive` AS `is_recursive`,
85-
`fanswer`.`requester_id` AS `requester_id`,
86-
`fanswer`.`users_id_validator` AS `validator_id`,
87-
`fanswer`.`comment` AS `comment`
75+
NULL AS `id`,
76+
`f`.`name` AS `name`,
77+
CONCAT('f_',`fanswer`.`id`) AS `display_id`,
78+
`fanswer`.`id` AS `original_id`,
79+
'PluginFormcreatorFormAnswer' AS `sub_itemtype`,
80+
`fanswer`.`status` AS `status`,
81+
`fanswer`.`request_date` AS `date_creation`,
82+
`fanswer`.`request_date` AS `date_mod`,
83+
`fanswer`.`entities_id` AS `entities_id`,
84+
`fanswer`.`is_recursive` AS `is_recursive`,
85+
`fanswer`.`requester_id` AS `requester_id`,
86+
`fanswer`.`users_id_validator` AS `validator_id`,
87+
`fanswer`.`groups_id_validator` AS `validator_id`,
88+
`fanswer`.`comment` AS `comment`
8889
FROM `glpi_plugin_formcreator_formanswers` AS `fanswer`
8990
LEFT JOIN `glpi_plugin_formcreator_forms` AS `f`
9091
ON`f`.`id` = `fanswer`.`plugin_formcreator_forms_id`
@@ -108,7 +109,8 @@ public static function cronSyncIssues(CronTask $task) {
108109
`tic`.`entities_id` AS `entities_id`,
109110
0 AS `is_recursive`,
110111
`tu`.`users_id` AS `requester_id`,
111-
0 AS `validator_id`,
112+
0 AS `users_id_validator`,
113+
0 AS `groups_id_validator`,
112114
`tic`.`content` AS `comment`
113115
FROM `glpi_tickets` AS `tic`
114116
LEFT JOIN `glpi_items_tickets` AS `itic`
@@ -396,7 +398,7 @@ public function rawSearchOptions() {
396398
'id' => '9',
397399
'table' => 'glpi_users',
398400
'field' => 'name',
399-
'linkfield' => 'validator_id',
401+
'linkfield' => 'users_id_validator',
400402
'name' => __('Form approver', 'formcreator'),
401403
'datatype' => 'dropdown',
402404
'massiveaction' => false
@@ -481,6 +483,16 @@ public function rawSearchOptions() {
481483
]
482484
];
483485

486+
$tab[] = [
487+
'id' => '16',
488+
'table' => 'glpi_groups',
489+
'field' => 'completename',
490+
'name' => __('Form approver group', 'formcreator'),
491+
'datatype' => 'itemlink',
492+
'massiveaction' => false,
493+
'linkfield' => 'groups_id_validator',
494+
];
495+
484496
return $tab;
485497
}
486498

@@ -635,55 +647,77 @@ static function getWaitingCriteria() {
635647
}
636648

637649
static function getValidateCriteria() {
638-
$currentUser = Session::getLoginUserID();
639-
return ['criteria' => [['field' => 4,
640-
'searchtype' => 'equals',
641-
'value' => 'waiting',
642-
'link' => 'AND'],
643-
['field' => 9,
644-
'searchtype' => 'equals',
645-
'value' => $currentUser,
646-
'link' => 'AND'],
647-
['field' => 4,
648-
'searchtype' => 'equals',
649-
'value' => 'waiting',
650-
'link' => 'OR'],
651-
['field' => 11,
650+
return ['criteria' => [['link' => 'AND',
651+
'field' => 4,
652652
'searchtype' => 'equals',
653-
'value' => $currentUser,
654-
'link' => 'AND']],
653+
'value' => PluginFormcreatorFormAnswer::STATUS_WAITING,
654+
],
655+
['link' => 'AND'] + self::getMeAsValidatorCriteria()
656+
],
655657
'reset' => 'reset'];
656658
}
657659

658660
static function getSolvedCriteria() {
659661
$currentUser = Session::getLoginUserID();
660-
return ['criteria' => [['field' => 4,
661-
'searchtype' => 'equals',
662-
'value' => 'old',
663-
'link' => 'AND'],
664-
['field' => 8,
662+
return ['criteria' => [['link' => 'AND',
663+
'field' => 8,
665664
'searchtype' => 'equals',
666665
'value' => $currentUser,
667-
'link' => 'AND'],
668-
['field' => 4,
666+
],
667+
['link' => 'AND',
668+
'criteria' => [[
669+
'link' => 'AND',
670+
'field' => 4,
671+
'searchtype' => 'equals',
672+
'value' => 'old', // see Ticket::getAllStatusArray()
673+
],
674+
['field' => 4,
675+
'searchtype' => 'equals',
676+
'value' => PluginFormcreatorFormAnswer::STATUS_REFUSED,
677+
'link' => 'OR']
678+
]],
679+
['link' => 'OR',
680+
'criteria' => [[
681+
'link' => 'AND',
682+
'field' => 9,
669683
'searchtype' => 'equals',
670-
'value' => 'refused',
671-
'link' => 'OR'],
672-
['field' => 8,
673-
'searchtype' => 'equals',
674-
'value' => $currentUser,
675-
'link' => 'AND'],
676-
['field' => 4,
684+
'value' => $currentUser,
685+
],
686+
['link' => 'OR',
687+
'field' => 16,
677688
'searchtype' => 'equals',
678-
'value' => 'refused',
679-
'link' => 'OR'],
680-
['field' => 9,
681-
'searchtype' => 'equals',
682-
'value' => $currentUser,
683-
'link' => 'AND']],
689+
'value' => 'mygroups',
690+
],
691+
]],
692+
['link' => 'AND',
693+
'field' => 4,
694+
'searchtype' => 'equals',
695+
'value' => PluginFormcreatorFormAnswer::STATUS_REFUSED,
696+
]],
684697
'reset' => 'reset'];
685698
}
686699

700+
public static function getMeAsValidatorCriteria() {
701+
$currentUser = Session::getLoginUserID();
702+
return ['criteria' => [[
703+
'link' => 'AND',
704+
'field' => 9,
705+
'searchtype' => 'equals',
706+
'value' => $currentUser,
707+
],
708+
['link' => 'OR',
709+
'field' => 16,
710+
'searchtype' => 'equals',
711+
'value' => 'mygroups',
712+
],
713+
['link' => 'OR',
714+
'field' => 11,
715+
'searchtype' => 'equals',
716+
'value' => $currentUser,
717+
]]
718+
];
719+
}
720+
687721
static function getTicketSummary() {
688722
$status = [
689723
Ticket::INCOMING => 0,

install/mysql/plugin_formcreator_empty.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,16 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` (
242242
`date_mod` datetime NOT NULL,
243243
`entities_id` int(11) NOT NULL DEFAULT '0',
244244
`is_recursive` tinyint(1) NOT NULL DEFAULT '0',
245-
`requester_id` int(11) NOT NULL DEFAULT '0',
246-
`validator_id` int(11) NOT NULL DEFAULT '0',
245+
`requester_id` int(11) NOT NULL DEFAULT '0',
246+
`users_id_validator` int(11) NOT NULL DEFAULT '0',
247+
`groups_id_validator` int(11) NOT NULL DEFAULT '0',
247248
`comment` longtext,
248249
PRIMARY KEY (`id`),
249250
INDEX `original_id_sub_itemtype` (`original_id`, `sub_itemtype`),
250251
INDEX `entities_id` (`entities_id`),
251252
INDEX `requester_id` (`requester_id`),
252-
INDEX `validator_id` (`validator_id`)
253+
INDEX `users_id_validator` (`users_id_validator`),
254+
INDEX `groups_id_validator` (`groups_id_validator`)
253255
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
254256

255257
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_items_targettickets` (

install/upgrade_to_2.10.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,14 @@ public function upgrade(Migration $migration) {
6262
$migration->addField($table, 'show_rule', 'integer', ['value' => '1', 'after' => 'category_question']);
6363
$table = 'glpi_plugin_formcreator_targettickets';
6464
$migration->addField($table, 'show_rule', 'integer', ['value' => '1', 'after' => 'location_question']);
65+
66+
// support for validator group in issues
67+
$table = 'glpi_plugin_formcreator_issues';
68+
$migration->changeField($table, 'validator_id', 'users_id_validator', 'integer');
69+
$migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']);
70+
$migration->migrationOneTable($table);
71+
$migration->dropKey($table, 'validator_id');
72+
$migration->addKey($table, 'users_id_validator');
73+
$migration->addKey($table, 'groups_id_validator');
6574
}
6675
}

0 commit comments

Comments
 (0)