Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(cr): improve code
  • Loading branch information
devmiguelangel committed May 27, 2024
commit 105c79724cde093d191a07d7e291b11b659a2440
61 changes: 43 additions & 18 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,31 @@ public function assignableUsers()
return new TokenAssignableUsers($query, $this);
}

/**
* Returns either the owner element or its properties
*
* @param asObject Boolean flag that determines whether the function should return the element directly or its
* properties as an object.
*
* @return If the parameter is true, the function will return the object. If is false, the
* function will return the properties of the object.
*/
private function getDefinitionFromOwner($asObject)
Comment thread
devmiguelangel marked this conversation as resolved.
Resolved
{
$element = $this->getOwnerElement();

return $asObject ? $element : $element->getProperties();
}

/**
* Retrieves a specific element's BPMN definition from a request object and returns either the element
* itself or its properties.
*
* @param asObject Boolean flag that determines whether the function should return the BPMN element instance
* as an object or just its properties.
*
* @return If `asObject` is false, the properties of the BPMN element instance are returned.
*/
private function getDefinitionFromRequest($asObject)
Comment thread
devmiguelangel marked this conversation as resolved.
Resolved
{
$request = $this->processRequest ?: $this->getInstance();
Expand Down Expand Up @@ -1172,26 +1190,9 @@ public function reassign($toUserId, User $requestingUser)
event(new ActivityAssigned($this));
}

/**
* Determines the destination URL based on the element destination type specified in the definition.
*
* @return string|null
*/
public function getElementDestinationAttribute(): ?string
private function getElementDestination($elementDestinationType, $elementDestinationProp)
{
$definition = $this->getDefinition();
$elementDestinationProp = $definition['elementDestination'] ?? null;
$elementDestination = null;
$elementDestinationType = null;

try {
$elementDestinationProp = json_decode($elementDestinationProp, true);
if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
$elementDestinationType = $elementDestinationProp['type'];
}
} catch (Exception $e) {
return null;
}

switch ($elementDestinationType) {
Comment thread
devmiguelangel marked this conversation as resolved.
Resolved
case 'customDashboard':
Expand Down Expand Up @@ -1227,8 +1228,32 @@ public function getElementDestinationAttribute(): ?string
default:
$elementDestination = null;
break;

}

return $elementDestination;
}

/**
* Determines the destination URL based on the element destination type specified in the definition.
*
* @return string|null
*/
public function getElementDestinationAttribute(): ?string
{
$definition = $this->getDefinition();
$elementDestinationProp = $definition['elementDestination'] ?? null;
$elementDestinationType = null;

try {
$elementDestinationProp = json_decode($elementDestinationProp, true);
if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
$elementDestinationType = $elementDestinationProp['type'];
}
} catch (Exception $e) {
return null;
}

return $this->getElementDestination($elementDestinationType, $elementDestinationProp);
}
}