diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index 9791c3ede..b299a7fa9 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -933,6 +933,19 @@ public function generateTarget() { $generatedTargets = new PluginFormcreatorComposite(new PluginFormcreatorItem_TargetTicket(), new Ticket_Ticket()); foreach ($all_targets as $targetType => $targets) { foreach ($targets as $targetObject) { + // Check the condition of the target + $this->questionFields = $form->getFields(); + $answers_values = $this->getAnswers($this->getID()); + foreach ($this->questionFields as $id => $field) { + $this->questionFields[$id]->deserializeValue($answers_values['formcreator_field_' . $id]); + } + + if (!PluginFormcreatorFields::isVisible($targetObject, $this->questionFields)) { + // The target shall not be generated + continue; + } + + // Generate the target $generatedTarget = $targetObject->save($this); if ($generatedTarget === null) { $success = false; diff --git a/inc/targetbase.class.php b/inc/targetbase.class.php index def613890..e15256dd1 100644 --- a/inc/targetbase.class.php +++ b/inc/targetbase.class.php @@ -35,8 +35,11 @@ abstract class PluginFormcreatorTargetBase extends CommonDBChild implements PluginFormcreatorExportableInterface, -PluginFormcreatorTargetInterface +PluginFormcreatorTargetInterface, +PluginFormcreatorConditionnableInterface { + use PluginFormcreatorConditionnable; + static public $itemtype = PluginFormcreatorForm::class; static public $items_id = 'plugin_formcreator_forms_id'; @@ -1478,6 +1481,14 @@ protected function convertTags($input) { return $input; } + protected function showConditionsSettings($rand) { + $formFk = PluginFormcreatorForm::getForeignKeyField(); + $form = new PluginFormcreatorForm(); + $form->getFromDB($this->fields[$formFk]); + $condition = new PluginFormcreatorCondition(); + $condition->showConditionsForItem($this); + } + /** * Show header for actors edition * diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 2430186b2..4ff487d91 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -133,6 +133,14 @@ public function export($remove_uuid = false) { } } + // get conditions + $target_data['_conditions'] = []; + $condition = new PluginFormcreatorCondition(); + $all_conditions = $condition->getConditionsFromItem($this); + foreach ($all_conditions as $condition) { + $target_data['_conditions'][] = $condition->export($remove_uuid); + } + // remove ID or UUID $idToRemove = 'id'; if ($remove_uuid) { @@ -225,6 +233,13 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con } } + // Import conditions + if (isset($input['_conditions'])) { + foreach ($input['_conditions'] as $condition) { + PluginFormcreatorCondition::import($linker, $condition, $itemId); + } + } + return $itemId; } @@ -241,7 +256,7 @@ public function showForm($options = []) { $form = $this->getForm(); echo '