From c89b08d5212f294c1bc0bbcce496da3af85ef734 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelca Date: Thu, 6 Jun 2024 15:22:30 -0400 Subject: [PATCH 1/2] FOUR-15859: On Process End - Start a request for another selected process --- ProcessMaker/Models/ProcessRequest.php | 4 ++-- ProcessMaker/Models/ProcessRequestToken.php | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ProcessMaker/Models/ProcessRequest.php b/ProcessMaker/Models/ProcessRequest.php index c03ba2aa81..05e0578b14 100644 --- a/ProcessMaker/Models/ProcessRequest.php +++ b/ProcessMaker/Models/ProcessRequest.php @@ -1057,9 +1057,9 @@ public function getProcessVersionAlternativeAttribute(): string | null /** * Retrieves the destination of the first closed end event. * - * @return ?string Returns a string value representing the element destination of the first closed end event. + * @return ?array Returns a string value representing the element destination of the first closed end event. */ - public function getElementDestination(): ?string + public function getElementDestination(): ?array { $endEvents = $this->tokens() ->where('element_type', 'end_event') diff --git a/ProcessMaker/Models/ProcessRequestToken.php b/ProcessMaker/Models/ProcessRequestToken.php index 2236e7a91d..56bcb0bd1e 100644 --- a/ProcessMaker/Models/ProcessRequestToken.php +++ b/ProcessMaker/Models/ProcessRequestToken.php @@ -136,7 +136,7 @@ class ProcessRequestToken extends ProcessMakerModel implements TokenInterface */ protected $appends = [ 'advanceStatus', - 'elementDestination' + 'elementDestination', ]; /** @@ -1196,13 +1196,14 @@ public function reassign($toUserId, User $requestingUser) * @param elementDestinationType Used to determine the type of destination for an element. * @param elementDestinationProp Used to determine the properties of the destination for an element. * - * @return string|null Returns the destination URL. + * @return array|null Returns the destination URL. */ - private function getElementDestination($elementDestinationType, $elementDestinationProp): ?string + private function getElementDestination($elementDestinationType, $elementDestinationProp): ?array { $elementDestination = null; switch ($elementDestinationType) { + case 'anotherProcess': case 'customDashboard': case 'externalURL': if (array_key_exists('value', $elementDestinationProp)) { @@ -1227,7 +1228,7 @@ private function getElementDestination($elementDestinationType, $elementDestinat case 'processLaunchpad': $elementDestination = route('process.browser.index', [ 'process' => $this->process_id, - 'categorySelected' => -1 + 'categorySelected' => -1, ]); break; case 'taskSource': @@ -1236,18 +1237,20 @@ private function getElementDestination($elementDestinationType, $elementDestinat default: $elementDestination = null; break; - } - return $elementDestination; + return [ + 'type' => $elementDestinationType, + 'value' => $elementDestination, + ]; } /** * Determines the destination URL based on the element destination type specified in the definition. * - * @return string|null + * @return array|null */ - public function getElementDestinationAttribute(): ?string + public function getElementDestinationAttribute(): ?array { $definition = $this->getDefinition(); $elementDestinationProp = $definition['elementDestination'] ?? null; From 567ca96061c25246b6320e15d0d4dc382fc56c80 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelca Date: Fri, 7 Jun 2024 13:37:15 -0400 Subject: [PATCH 2/2] create includeElementDestination interface to support element destination --- ProcessMaker/Http/Resources/Task.php | 1 + ProcessMaker/Models/ProcessRequestToken.php | 1 - ProcessMaker/Traits/TaskResourceIncludes.php | 13 +++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ProcessMaker/Http/Resources/Task.php b/ProcessMaker/Http/Resources/Task.php index 186c6ab89f..893af985ad 100644 --- a/ProcessMaker/Http/Resources/Task.php +++ b/ProcessMaker/Http/Resources/Task.php @@ -38,6 +38,7 @@ class Task extends ApiResource 'interstitial', 'userRequestPermission', 'process', + 'elementDestination', ]; private $process = null; diff --git a/ProcessMaker/Models/ProcessRequestToken.php b/ProcessMaker/Models/ProcessRequestToken.php index 56bcb0bd1e..ab3d2214b1 100644 --- a/ProcessMaker/Models/ProcessRequestToken.php +++ b/ProcessMaker/Models/ProcessRequestToken.php @@ -136,7 +136,6 @@ class ProcessRequestToken extends ProcessMakerModel implements TokenInterface */ protected $appends = [ 'advanceStatus', - 'elementDestination', ]; /** diff --git a/ProcessMaker/Traits/TaskResourceIncludes.php b/ProcessMaker/Traits/TaskResourceIncludes.php index 8b8db4a0f7..04aeff63a5 100644 --- a/ProcessMaker/Traits/TaskResourceIncludes.php +++ b/ProcessMaker/Traits/TaskResourceIncludes.php @@ -6,6 +6,7 @@ use ProcessMaker\Http\Resources\ScreenVersion as ScreenVersionResource; use ProcessMaker\Http\Resources\Users; use ProcessMaker\Managers\DataManager; +use ProcessMaker\Models\ProcessRequestToken; use ProcessMaker\Models\TaskDraft; use ProcessMaker\ProcessTranslations\ProcessTranslation; use StdClass; @@ -137,4 +138,16 @@ private function includeUserRequestPermission() return ['user_request_permission' => $userRequestPermission]; } + + /** + * Include the element destination in the resource response. + * + * @return array + */ + private function includeElementDestination() + { + $elementDestination = $this->resource->getElementDestinationAttribute(); + + return ['elementDestination' => $elementDestination]; + } }