From fedea4d349cf7d10a3df5f958458a682e6963898 Mon Sep 17 00:00:00 2001 From: Charlene Auger Date: Thu, 27 Nov 2025 10:04:44 +0000 Subject: [PATCH 1/7] feat(target): add request source target --- inc/abstracttarget.class.php | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/inc/abstracttarget.class.php b/inc/abstracttarget.class.php index 19ae522..67780e2 100644 --- a/inc/abstracttarget.class.php +++ b/inc/abstracttarget.class.php @@ -195,6 +195,10 @@ abstract protected function getTargetTemplate(array $data): int; const LOCATION_RULE_SPECIFIC = 2; const LOCATION_RULE_ANSWER = 3; + const REQUESTSOURCE_RULE_NONE = 1; + const REQUESTSOURCE_RULE_SPECIFIC = 2; + const REQUESTSOURCE_RULE_ANSWER = 3; + const OLA_RULE_NONE = 1; const OLA_RULE_SPECIFIC = 2; const OLA_RULE_FROM_ANWSER = 3; @@ -276,6 +280,14 @@ public static function getEnumLocationRule() { ]; } + public static function getEnumRequestSourceRule() { + return [ + self::REQUESTSOURCE_RULE_NONE => __('Request source from template or none', 'formcreator'), + self::REQUESTSOURCE_RULE_SPECIFIC => __('Specific request source', 'formcreator'), + self::REQUESTSOURCE_RULE_ANSWER => __('Equals to the answer to the question', 'formcreator'), + ]; + } + public function isEntityAssign() { return false; } @@ -1491,6 +1503,73 @@ protected function showLocationSettings($rand) { echo ''; } + protected function showRequestSourceSettings($rand) { + global $DB; + + echo ''; + echo '' . __('Request source') . ''; + echo ''; + Dropdown::showFromArray('requestsource_rule', static::getEnumRequestSourceRule(), [ + 'value' => $this->fields['requestsource_rule'], + 'on_change' => "plugin_formcreator_change_request_source($rand)", + 'rand' => $rand + ]); + + echo Html::scriptBlock("plugin_formcreator_change_request_source($rand)"); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + } + /** * Sets the time to resolve of the target object * From 07817523482818aa028b32a2209725a9ad940e45 Mon Sep 17 00:00:00 2001 From: Charlene Auger Date: Thu, 27 Nov 2025 10:05:21 +0000 Subject: [PATCH 2/7] refactor(target): add request source target and fix some translations --- inc/targetticket.class.php | 55 +++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index ecf510c..0b90b70 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -229,6 +229,12 @@ public function showForm($ID, $options = []) { // Location selection // ------------------------------------------------------------------------------------------- $this->showLocationSettings($rand); + + // ------------------------------------------------------------------------------------------- + // Request source selection + // ------------------------------------------------------------------------------------------- + $this->showRequestSourceSettings($rand); + // ------------------------------------------------------------------------------------------- // Tags // ------------------------------------------------------------------------------------------- @@ -546,6 +552,17 @@ public function prepareInputForUpdate($input) { $input['location_question'] = '0'; } + switch ($input['requestsource_rule']) { + case self::REQUESTSOURCE_RULE_ANSWER: + $input['requestsource_question'] = $input['_requestsource_question']; + break; + case self::REQUESTSOURCE_RULE_SPECIFIC: + $input['requestsource_question'] = $input['_requestsource_specific']; + break; + default: + $input['requestsource_question'] = '0'; + } + $plugin = new Plugin(); if ($plugin->isActivated('tag')) { $input['tag_questions'] = (!empty($input['_tag_questions'])) @@ -773,6 +790,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer) { $data = $this->setOLA($data, $formanswer); $data = $this->setTargetUrgency($data, $formanswer); $data = $this->setTargetLocation($data, $formanswer); + $data = $this->setTargetRequestSource($data, $formanswer); $data = $this->setTargetAssociatedItem($data, $formanswer); // There is always at least one requester @@ -896,6 +914,35 @@ protected function setTargetLocation($data, $formanswer) { return $data; } + protected function setTargetRequestSource($data, $formanswer) { + global $DB; + + $requestSource = null; + switch ($this->fields['requestsource_rule']) { + case self::REQUESTSOURCE_RULE_ANSWER: + $requestSource = $DB->request([ + 'SELECT' => ['answer'], + 'FROM' => PluginFormcreatorAnswer::getTable(), + 'WHERE' => [ + 'plugin_formcreator_formanswers_id' => $formanswer->fields['id'], + 'plugin_formcreator_questions_id' => $this->fields['requestsource_question'] + ] + ])->next(); + if (ctype_digit($requestSource['answer'])) { + $requestSource = $requestSource['answer']; + } + break; + case self::REQUESTSOURCE_RULE_SPECIFIC: + $requestSource = $this->fields['requestsource_question']; + break; + } + if (!is_null($requestSource)) { + $data['requesttypes_id'] = $requestSource; + } + + return $data; + } + protected function setTargetType(array $data, PluginFormcreatorFormAnswer $formanswer) { global $DB; @@ -927,7 +974,7 @@ protected function setTargetType(array $data, PluginFormcreatorFormAnswer $forma protected function showTypeSettings($rand) { echo ''; - echo '' . __('Request type') . ''; + echo '' . __('Request type', 'formcreator') . ''; echo ''; Dropdown::showFromArray('type_rule', static::getEnumRequestTypeRule(), [ 'value' => $this->fields['type_rule'], @@ -939,7 +986,7 @@ protected function showTypeSettings($rand) { echo ''; echo ''; echo ''; - echo ''; + echo ''; echo ''; echo ''; echo '