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
feat: add element destination for custom dashboard and external url b…
…ehavior
  • Loading branch information
devmiguelangel committed May 24, 2024
commit 478ca1049881dea1cd03899b7365a373f4d0015f
53 changes: 41 additions & 12 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use DB;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Notification;
Expand Down Expand Up @@ -287,18 +288,15 @@ public function assignableUsers()
return new TokenAssignableUsers($query, $this);
}

/**
* Get the BPMN definition of the element where the token is.
*
* @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
*/
public function getDefinition($asObject = false, $par = null)
private function getDefinitionFromOwner($asObject)
Comment thread
devmiguelangel marked this conversation as resolved.
Resolved
{
if ($this->getOwner() && $this->getOwnerElement()) {
$element = $this->getOwnerElement();
$element = $this->getOwnerElement();

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

private function getDefinitionFromRequest($asObject)
Comment thread
devmiguelangel marked this conversation as resolved.
Resolved
{
$request = $this->processRequest ?: $this->getInstance();

if (!$request) {
Expand All @@ -308,13 +306,28 @@ public function getDefinition($asObject = false, $par = null)
$process = $request->processVersion ?: $request->process;
$definitions = $process->getDefinitions();
$element = $definitions->findElementById($this->element_id);

if (!$element) {
return [];
}

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

/**
* Get the BPMN definition of the element where the token is.
*
* @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
*/
public function getDefinition($asObject = false, $par = null)
{
if ($this->getOwner() && $this->getOwnerElement()) {
return $this->getDefinitionFromOwner($asObject);
}

return $this->getDefinitionFromRequest($asObject);
}

/**
* Get the BPMN element node where the token is currently located.
*
Expand Down Expand Up @@ -1167,13 +1180,29 @@ public function reassign($toUserId, User $requestingUser)
public function getElementDestinationAttribute(): ?string
{
$definition = $this->getDefinition();
$elementDestinationType = $definition['elementDestinationType'] ?? null;
$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':
case 'externalURL':
$elementDestination = $definition['elementDestinationURL'] ?? null;
if (array_key_exists('value', $elementDestinationProp)) {
if (is_string($elementDestinationProp['value'])) {
$elementDestination = $elementDestinationProp['value'];
} else {
$elementDestination = $elementDestinationProp['value']['url'] ?? null;
}
}
break;
case 'taskList':
$elementDestination = route('tasks.index');
Expand Down