@@ -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 ' ]);
0 commit comments