diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index 7353e16f9..ec7c7fc7f 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -46,6 +46,7 @@ abstract class PluginFormcreatorTarget_Actor extends CommonDBChild implements Pl const ACTOR_TYPE_SUPPLIER = 7; const ACTOR_TYPE_QUESTION_SUPPLIER = 8; const ACTOR_TYPE_QUESTION_ACTORS = 9; + const ACTOR_TYPE_GROUP_FROM_OBJECT = 10; const ACTOR_ROLE_REQUESTER = 1; const ACTOR_ROLE_OBSERVER = 2; @@ -60,6 +61,7 @@ static function getEnumActorType() { self::ACTOR_TYPE_QUESTION_PERSON => __('Person from the question', 'formcreator'), self::ACTOR_TYPE_GROUP => __('Specific group', 'formcreator'), self::ACTOR_TYPE_QUESTION_GROUP => __('Group from the question', 'formcreator'), + self::ACTOR_TYPE_GROUP_FROM_OBJECT => __('Group from an object', 'formcreator'), self::ACTOR_TYPE_SUPPLIER => __('Specific supplier', 'formcreator'), self::ACTOR_TYPE_QUESTION_SUPPLIER => __('Supplier from the question', 'formcreator'), self::ACTOR_TYPE_QUESTION_ACTORS => __('Actors from the question', 'formcreator'), @@ -111,6 +113,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con case self::ACTOR_TYPE_QUESTION_PERSON : case self::ACTOR_TYPE_QUESTION_GROUP : case self::ACTOR_TYPE_QUESTION_SUPPLIER : + case self::ACTOR_TYPE_GROUP_FROM_OBJECT : $question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class); if ($question === false) { $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); @@ -193,6 +196,7 @@ public function export($remove_uuid = false) { case self::ACTOR_TYPE_QUESTION_GROUP: case self::ACTOR_TYPE_SUPPLIER: case self::ACTOR_TYPE_QUESTION_ACTORS: + case self::ACTOR_TYPE_GROUP_FROM_OBJECT: $question = new PluginFormcreatorQuestion; if ($question->getFromDB($target_actor['actor_value'])) { $target_actor['actor_value'] = $question->fields['uuid']; diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index fb561a504..1c2294414 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -442,17 +442,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF switch ($actor['actor_type']) { case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR : $userIds = [$formanswer->fields['requester_id']]; - $notify = $actor['use_notification']; break; case PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR : $userIds = [$_SESSION['glpiID']]; - $notify = $actor['use_notification']; break; case PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON : case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP : case PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER : $userIds = [$actor['actor_value']]; - $notify = $actor['use_notification']; break; case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON : case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP : @@ -462,7 +459,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF $formanswerId = $formanswer->getID(); $answer->getFromDBByCrit([ 'AND' => [ - 'plugin_formcreator_questions_id' => $actorValue, + 'plugin_formcreator_questions_id' => $actorValue, 'plugin_formcreator_formanswers_id' => $formanswerId ] ]); @@ -472,7 +469,6 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF } else { $userIds = [$answer->fields['answer']]; } - $notify = $actor['use_notification']; break; case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS: $answer = new PluginFormcreatorAnswer(); @@ -480,7 +476,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF $formanswerId = $formanswer->getID(); $answer->getFromDBByCrit([ 'AND' => [ - 'plugin_formcreator_questions_id' => $actorValue, + 'plugin_formcreator_questions_id' => $actorValue, 'plugin_formcreator_formanswers_id' => $formanswerId ] ]); @@ -490,9 +486,53 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF } else { $userIds = json_decode($answer->fields['answer'], JSON_OBJECT_AS_ARRAY); } - $notify = $actor['use_notification']; + break; + case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT: + // Get the object from the question + $answer = new PluginFormcreatorAnswer(); + $actorValue = $actor['actor_value']; + $formanswerId = $formanswer->getID(); + $answer->getFromDBByCrit([ + 'AND' => [ + 'plugin_formcreator_questions_id' => $actorValue, + 'plugin_formcreator_formanswers_id' => $formanswerId + ] + ]); + if ($answer->isNewItem()) { + continue 2; + } + // Get the itemtype of the object + $question = new PluginFormcreatorQuestion(); + $question->getFromDB($answer->fields[PluginFormcreatorQuestion::getForeignKeyField()]); + if ($question->isNewItem()) { + continue 2; + } + $itemtype = $question->fields['values']; + if (!is_subclass_of($itemtype, CommonDBTM::class)) { + continue 2; + } + + // Check the object has a group FK + $groupFk = Group::getForeignKeyField(); + $object = new $itemtype(); + if (!$DB->fieldExists($object->getTable(), $groupFk)) { + continue 2; + } + + // get the group + if (!$object->getFromDB($answer->fields['answer'])) { + continue 2; + } + + // ignore invalid ID + if (Group::isNewId($object->fields[$groupFk])) { + continue 2; + } + + $userIds = [$object->fields[$groupFk]]; break; } + $notify = $actor['use_notification']; switch ($actor['actor_type']) { case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR : @@ -506,7 +546,8 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF break; case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP : case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP : - foreach ($userIds as $groupId) { + case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT: + foreach ($userIds as $groupId) { $this->addGroupActor($actor['actor_role'], $groupId); } break; @@ -1104,6 +1145,19 @@ protected function showActorsSettings() { ); echo ''; + echo '
'; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '