@@ -442,17 +442,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
442
442
switch ($ actor ['actor_type ' ]) {
443
443
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
444
444
$ userIds = [$ formanswer ->fields ['requester_id ' ]];
445
- $ notify = $ actor ['use_notification ' ];
446
445
break ;
447
446
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR :
448
447
$ userIds = [$ _SESSION ['glpiID ' ]];
449
- $ notify = $ actor ['use_notification ' ];
450
448
break ;
451
449
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON :
452
450
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
453
451
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER :
454
452
$ userIds = [$ actor ['actor_value ' ]];
455
- $ notify = $ actor ['use_notification ' ];
456
453
break ;
457
454
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON :
458
455
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP :
@@ -462,7 +459,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
462
459
$ formanswerId = $ formanswer ->getID ();
463
460
$ answer ->getFromDBByCrit ([
464
461
'AND ' => [
465
- 'plugin_formcreator_questions_id ' => $ actorValue ,
462
+ 'plugin_formcreator_questions_id ' => $ actorValue ,
466
463
'plugin_formcreator_formanswers_id ' => $ formanswerId
467
464
]
468
465
]);
@@ -472,15 +469,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
472
469
} else {
473
470
$ userIds = [$ answer ->fields ['answer ' ]];
474
471
}
475
- $ notify = $ actor ['use_notification ' ];
476
472
break ;
477
473
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
478
474
$ answer = new PluginFormcreatorAnswer ();
479
475
$ actorValue = $ actor ['actor_value ' ];
480
476
$ formanswerId = $ formanswer ->getID ();
481
477
$ answer ->getFromDBByCrit ([
482
478
'AND ' => [
483
- 'plugin_formcreator_questions_id ' => $ actorValue ,
479
+ 'plugin_formcreator_questions_id ' => $ actorValue ,
484
480
'plugin_formcreator_formanswers_id ' => $ formanswerId
485
481
]
486
482
]);
@@ -490,9 +486,53 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
490
486
} else {
491
487
$ userIds = json_decode ($ answer ->fields ['answer ' ], JSON_OBJECT_AS_ARRAY );
492
488
}
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 ]];
494
533
break ;
495
534
}
535
+ $ notify = $ actor ['use_notification ' ];
496
536
497
537
switch ($ actor ['actor_type ' ]) {
498
538
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -506,7 +546,8 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
506
546
break ;
507
547
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
508
548
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 ) {
510
551
$ this ->addGroupActor ($ actor ['actor_role ' ], $ groupId );
511
552
}
512
553
break ;
@@ -1104,6 +1145,19 @@ protected function showActorsSettings() {
1104
1145
);
1105
1146
echo '</div> ' ;
1106
1147
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
+
1107
1161
echo '<div id="block_requester_question_actors" style="display:none"> ' ;
1108
1162
PluginFormcreatorQuestion::dropdownForForm (
1109
1163
$ this ->getForm ()->getID (),
@@ -1164,6 +1218,12 @@ protected function showActorsSettings() {
1164
1218
echo $ img_group . ' <b> ' . __ ('Group from the question ' , 'formcreator ' )
1165
1219
. '</b> " ' . $ question ->getName () . '" ' ;
1166
1220
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 ;
1167
1227
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
1168
1228
$ question = new PluginFormcreatorQuestion ();
1169
1229
$ question ->getFromDB ($ values ['actor_value ' ]);
@@ -1241,6 +1301,19 @@ protected function showActorsSettings() {
1241
1301
);
1242
1302
echo '</div> ' ;
1243
1303
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
+
1244
1317
echo '<div id="block_watcher_question_actors" style="display:none"> ' ;
1245
1318
PluginFormcreatorQuestion::dropdownForForm (
1246
1319
$ this ->getForm ()->getID (),
@@ -1301,6 +1374,12 @@ protected function showActorsSettings() {
1301
1374
echo $ img_group . ' <b> ' . __ ('Group from the question ' , 'formcreator ' )
1302
1375
. '</b> " ' . $ question ->getName () . '" ' ;
1303
1376
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 ;
1304
1383
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
1305
1384
$ question = new PluginFormcreatorQuestion ();
1306
1385
$ question ->getFromDB ($ values ['actor_value ' ]);
@@ -1385,6 +1464,19 @@ protected function showActorsSettings() {
1385
1464
);
1386
1465
echo '</div> ' ;
1387
1466
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
+
1388
1480
echo '<div id="block_assigned_question_actors" style="display:none"> ' ;
1389
1481
PluginFormcreatorQuestion::dropdownForForm (
1390
1482
$ this ->getForm ()->getID (),
@@ -1459,6 +1551,12 @@ protected function showActorsSettings() {
1459
1551
echo $ img_group . ' <b> ' . __ ('Group from the question ' , 'formcreator ' )
1460
1552
. '</b> " ' . $ question ->getName () . '" ' ;
1461
1553
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 ;
1462
1560
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
1463
1561
$ question = new PluginFormcreatorQuestion ();
1464
1562
$ question ->getFromDB ($ values ['actor_value ' ]);
0 commit comments