Skip to content

Commit 0461a91

Browse files
committed
feat(targetticket,targetchange): set a group from an object from a question
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 2ca5498 commit 0461a91

File tree

3 files changed

+116
-8
lines changed

3 files changed

+116
-8
lines changed

inc/target_actor.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ abstract class PluginFormcreatorTarget_Actor extends CommonDBChild implements Pl
4646
const ACTOR_TYPE_SUPPLIER = 7;
4747
const ACTOR_TYPE_QUESTION_SUPPLIER = 8;
4848
const ACTOR_TYPE_QUESTION_ACTORS = 9;
49+
const ACTOR_TYPE_GROUP_FROM_OBJECT = 10;
4950

5051
const ACTOR_ROLE_REQUESTER = 1;
5152
const ACTOR_ROLE_OBSERVER = 2;
@@ -60,6 +61,7 @@ static function getEnumActorType() {
6061
self::ACTOR_TYPE_QUESTION_PERSON => __('Person from the question', 'formcreator'),
6162
self::ACTOR_TYPE_GROUP => __('Specific group', 'formcreator'),
6263
self::ACTOR_TYPE_QUESTION_GROUP => __('Group from the question', 'formcreator'),
64+
self::ACTOR_TYPE_GROUP_FROM_OBJECT => __('Group from an object', 'formcreator'),
6365
self::ACTOR_TYPE_SUPPLIER => __('Specific supplier', 'formcreator'),
6466
self::ACTOR_TYPE_QUESTION_SUPPLIER => __('Supplier from the question', 'formcreator'),
6567
self::ACTOR_TYPE_QUESTION_ACTORS => __('Actors from the question', 'formcreator'),
@@ -111,6 +113,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
111113
case self::ACTOR_TYPE_QUESTION_PERSON :
112114
case self::ACTOR_TYPE_QUESTION_GROUP :
113115
case self::ACTOR_TYPE_QUESTION_SUPPLIER :
116+
case self::ACTOR_TYPE_GROUP_FROM_OBJECT :
114117
$question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class);
115118
if ($question === false) {
116119
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
@@ -193,6 +196,7 @@ public function export($remove_uuid = false) {
193196
case self::ACTOR_TYPE_QUESTION_GROUP:
194197
case self::ACTOR_TYPE_SUPPLIER:
195198
case self::ACTOR_TYPE_QUESTION_ACTORS:
199+
case self::ACTOR_TYPE_GROUP_FROM_OBJECT:
196200
$question = new PluginFormcreatorQuestion;
197201
if ($question->getFromDB($target_actor['actor_value'])) {
198202
$target_actor['actor_value'] = $question->fields['uuid'];

inc/targetbase.class.php

Lines changed: 106 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
442442
switch ($actor['actor_type']) {
443443
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
444444
$userIds = [$formanswer->fields['requester_id']];
445-
$notify = $actor['use_notification'];
446445
break;
447446
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR :
448447
$userIds = [$_SESSION['glpiID']];
449-
$notify = $actor['use_notification'];
450448
break;
451449
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON :
452450
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
453451
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER :
454452
$userIds = [$actor['actor_value']];
455-
$notify = $actor['use_notification'];
456453
break;
457454
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON :
458455
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP :
@@ -462,7 +459,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
462459
$formanswerId = $formanswer->getID();
463460
$answer->getFromDBByCrit([
464461
'AND' => [
465-
'plugin_formcreator_questions_id' => $actorValue,
462+
'plugin_formcreator_questions_id' => $actorValue,
466463
'plugin_formcreator_formanswers_id' => $formanswerId
467464
]
468465
]);
@@ -472,15 +469,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
472469
} else {
473470
$userIds = [$answer->fields['answer']];
474471
}
475-
$notify = $actor['use_notification'];
476472
break;
477473
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS:
478474
$answer = new PluginFormcreatorAnswer();
479475
$actorValue = $actor['actor_value'];
480476
$formanswerId = $formanswer->getID();
481477
$answer->getFromDBByCrit([
482478
'AND' => [
483-
'plugin_formcreator_questions_id' => $actorValue,
479+
'plugin_formcreator_questions_id' => $actorValue,
484480
'plugin_formcreator_formanswers_id' => $formanswerId
485481
]
486482
]);
@@ -490,9 +486,53 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
490486
} else {
491487
$userIds = json_decode($answer->fields['answer'], JSON_OBJECT_AS_ARRAY);
492488
}
493-
$notify = $actor['use_notification'];
489+
break;
490+
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
491+
// Get the object from the question
492+
$answer = new PluginFormcreatorAnswer();
493+
$actorValue = $actor['actor_value'];
494+
$formanswerId = $formanswer->getID();
495+
$answer->getFromDBByCrit([
496+
'AND' => [
497+
'plugin_formcreator_questions_id' => $actorValue,
498+
'plugin_formcreator_formanswers_id' => $formanswerId
499+
]
500+
]);
501+
if ($answer->isNewItem()) {
502+
continue 2;
503+
}
504+
// Get the itemtype of the object
505+
$question = new PluginFormcreatorQuestion();
506+
$question->getFromDB($answer->fields[PluginFormcreatorQuestion::getForeignKeyField()]);
507+
if ($question->isNewItem()) {
508+
continue 2;
509+
}
510+
$itemtype = $question->fields['values'];
511+
if (!is_subclass_of($itemtype, CommonDBTM::class)) {
512+
continue 2;
513+
}
514+
515+
// Check the object has a group FK
516+
$groupFk = Group::getForeignKeyField();
517+
$object = new $itemtype();
518+
if (!$DB->fieldExists($object->getTable(), $groupFk)) {
519+
continue 2;
520+
}
521+
522+
// get the group
523+
if (!$object->getFromDB($answer->fields['answer'])) {
524+
continue 2;
525+
}
526+
527+
// ignore invalid ID
528+
if (Group::isNewId($object->fields[$groupFk])) {
529+
continue 2;
530+
}
531+
532+
$userIds = [$object->fields[$groupFk]];
494533
break;
495534
}
535+
$notify = $actor['use_notification'];
496536

497537
switch ($actor['actor_type']) {
498538
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -506,7 +546,8 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
506546
break;
507547
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
508548
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP :
509-
foreach ($userIds as $groupId) {
549+
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
550+
foreach ($userIds as $groupId) {
510551
$this->addGroupActor($actor['actor_role'], $groupId);
511552
}
512553
break;
@@ -1104,6 +1145,19 @@ protected function showActorsSettings() {
11041145
);
11051146
echo '</div>';
11061147

1148+
echo '<div id="block_requester_group_from_object" style="display:none">';
1149+
PluginFormcreatorQuestion::dropdownForForm(
1150+
$this->getForm()->getID(),
1151+
[
1152+
'fieldtype' => ['glpiselect'],
1153+
],
1154+
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
1155+
[
1156+
'value' => 0
1157+
]
1158+
);
1159+
echo '</div>';
1160+
11071161
echo '<div id="block_requester_question_actors" style="display:none">';
11081162
PluginFormcreatorQuestion::dropdownForForm(
11091163
$this->getForm()->getID(),
@@ -1164,6 +1218,12 @@ protected function showActorsSettings() {
11641218
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
11651219
. '</b> "' . $question->getName() . '"';
11661220
break;
1221+
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
1222+
$question = new PluginFormcreatorQuestion();
1223+
$question->getFromDB($values['actor_value']);
1224+
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
1225+
. '</b> "' . $question->getName() . '"';
1226+
break;
11671227
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS:
11681228
$question = new PluginFormcreatorQuestion();
11691229
$question->getFromDB($values['actor_value']);
@@ -1241,6 +1301,19 @@ protected function showActorsSettings() {
12411301
);
12421302
echo '</div>';
12431303

1304+
echo '<div id="block_watcher_group_from_object" style="display:none">';
1305+
PluginFormcreatorQuestion::dropdownForForm(
1306+
$this->getForm()->getID(),
1307+
[
1308+
'fieldtype' => ['glpiselect'],
1309+
],
1310+
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
1311+
[
1312+
'value' => 0
1313+
]
1314+
);
1315+
echo '</div>';
1316+
12441317
echo '<div id="block_watcher_question_actors" style="display:none">';
12451318
PluginFormcreatorQuestion::dropdownForForm(
12461319
$this->getForm()->getID(),
@@ -1301,6 +1374,12 @@ protected function showActorsSettings() {
13011374
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
13021375
. '</b> "' . $question->getName() . '"';
13031376
break;
1377+
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
1378+
$question = new PluginFormcreatorQuestion();
1379+
$question->getFromDB($values['actor_value']);
1380+
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
1381+
. '</b> "' . $question->getName() . '"';
1382+
break;
13041383
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
13051384
$question = new PluginFormcreatorQuestion();
13061385
$question->getFromDB($values['actor_value']);
@@ -1385,6 +1464,19 @@ protected function showActorsSettings() {
13851464
);
13861465
echo '</div>';
13871466

1467+
echo '<div id="block_assigned_group_from_object" style="display:none">';
1468+
PluginFormcreatorQuestion::dropdownForForm(
1469+
$this->getForm()->getID(),
1470+
[
1471+
'fieldtype' => ['glpiselect'],
1472+
],
1473+
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
1474+
[
1475+
'value' => 0
1476+
]
1477+
);
1478+
echo '</div>';
1479+
13881480
echo '<div id="block_assigned_question_actors" style="display:none">';
13891481
PluginFormcreatorQuestion::dropdownForForm(
13901482
$this->getForm()->getID(),
@@ -1459,6 +1551,12 @@ protected function showActorsSettings() {
14591551
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
14601552
. '</b> "' . $question->getName() . '"';
14611553
break;
1554+
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
1555+
$question = new PluginFormcreatorQuestion();
1556+
$question->getFromDB($values['actor_value']);
1557+
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
1558+
. '</b> "' . $question->getName() . '"';
1559+
break;
14621560
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
14631561
$question = new PluginFormcreatorQuestion();
14641562
$question->getFromDB($values['actor_value']);

js/scripts.js.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ function plugin_formcreator_ChangeActorRequester(value) {
714714
$('#block_requester_question_user').hide();
715715
$('#block_requester_group').hide();
716716
$('#block_requester_question_group').hide();
717+
$('#block_requester_group_from_object').hide();
717718
$('#block_requester_question_actors').hide();
718719
$('#block_requester_supplier').hide();
719720
$('#block_requester_question_supplier').hide();
@@ -723,6 +724,7 @@ function plugin_formcreator_ChangeActorRequester(value) {
723724
case '4' : $('#block_requester_question_user').show(); break;
724725
case '5' : $('#block_requester_group').show(); break;
725726
case '6' : $('#block_requester_question_group').show(); break;
727+
case '10': $('#block_requester_group_from_object').show(); break;
726728
case '9' : $('#block_requester_question_actors').show(); break;
727729
case '7' : $('#block_requester_supplier').show(); break;
728730
case '8' : $('#block_requester_question_supplier').show(); break;
@@ -734,6 +736,7 @@ function plugin_formcreator_ChangeActorWatcher(value) {
734736
$('#block_watcher_question_user').hide();
735737
$('#block_watcher_group').hide();
736738
$('#block_watcher_question_group').hide();
739+
$('#block_watcher_group_from_object').hide();
737740
$('#block_watcher_question_actors').hide();
738741
$('#block_watcher_supplier').hide();
739742
$('#block_watcher_question_supplier').hide();
@@ -744,6 +747,7 @@ function plugin_formcreator_ChangeActorWatcher(value) {
744747
case '5' : $('#block_watcher_group').show(); break;
745748
case '6' : $('#block_watcher_question_group').show(); break;
746749
case '9' : $('#block_watcher_question_actors').show(); break;
750+
case '10': $('#block_watcher_group_from_object').show(); break;
747751
case '7' : $('#block_watcher_supplier').show(); break;
748752
case '8' : $('#block_watcher_question_supplier').show(); break;
749753
}
@@ -754,6 +758,7 @@ function plugin_formcreator_ChangeActorAssigned(value) {
754758
$('#block_assigned_question_user').hide();
755759
$('#block_assigned_group').hide();
756760
$('#block_assigned_question_group').hide();
761+
$('#block_assigned_group_from_object').hide();
757762
$('#block_assigned_question_actors').hide();
758763
$('#block_assigned_supplier').hide();
759764
$('#block_assigned_question_supplier').hide();
@@ -765,6 +770,7 @@ function plugin_formcreator_ChangeActorAssigned(value) {
765770
case '5' : $('#block_assigned_group').show(); break;
766771
case '6' : $('#block_assigned_question_group').show(); break;
767772
case '9' : $('#block_assigned_question_actors').show(); break;
773+
case '10': $('#block_assigned_group_from_object').show(); break;
768774
case '7' : $('#block_assigned_supplier').show(); break;
769775
case '8' : $('#block_assigned_question_supplier').show(); break;
770776
}

0 commit comments

Comments
 (0)