Skip to content

Commit

Permalink
Merge 4e78927 into ff2b37f
Browse files Browse the repository at this point in the history
  • Loading branch information
xunto committed Jan 20, 2017
2 parents ff2b37f + 4e78927 commit ea6c164
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 51 deletions.
24 changes: 6 additions & 18 deletions src/Workflow/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Process
private $completed;
private $variables;
private $tasks;
private $variablesReference;
private $tasksReference;

/**
* @return string
Expand Down Expand Up @@ -80,32 +78,22 @@ public function setCompleted($completed)

public function getVariables()
{
if (!isset($this->variables)) {
$reference = $this->variablesReference;
$this->variables = $reference();
}

return $this->variables;
}

public function getTasks()
public function setVariables($variables)
{
if (!isset($this->tasks)) {
$reference = $this->tasksReference;
$this->tasks = $reference();
}

return $this->tasks;
$this->variables = $variables;
}

public function setVariablesReference(Closure $variablesReference)
public function getTasks()
{
$this->variablesReference = $variablesReference;
return $this->tasks;
}

public function setTasksReference(Closure $tasksReference)
public function setTasks($tasks)
{
$this->tasksReference = $tasksReference;
$this->tasks = $tasks;
}

}
58 changes: 25 additions & 33 deletions src/Workflow/WorkflowManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,47 @@ public function createProcess($process_definition_key, $variables = [], $items =
$data['items'] = $items;

$result = $this->api->request('process_create', $data);
return $this->buildProcessObject($result['entry']);

return $this->findProcess($result['entry']['id']);
}

private function buildProcessObject($data)
/**
* Find alfresco process by id
* @var $id - process id (alfresco)
* @return Process process object
**/
public function findProcess($id)
{
$process = new Process();

$id = $data['id'];
// Fetch basic process info
$data = $this->api->request('process_info', [
'id' => $id
]);

$process->setId($id);
$process->setProcessDefinitionKey($data['processDefinitionKey']);
$process->setBusinessKey($data['businessKey']);
$process->setCompleted($data['completed']);

$process->setVariablesReference(function () use ($id) {
$result = $this->api->request('process_variables', [
'id' => $id
]);
// Fetch process variables
$data = $this->api->request('process_variables', [
'id' => $id
]);

$object = [];
foreach ($result['list']['entries'] as $entry) {
$name = $entry['entry']['name'];
@$value = $entry['entry']['value'];
$variables = [];
foreach ($data['list']['entries'] as $entry) {
$name = $entry['entry']['name'];
@$value = $entry['entry']['value'];

$object[$name] = $value;
}
$object[$name] = $value;
}

return $object;
});
$process->setVariables($variables);

$process->setTasksReference(function () use ($id) {
//TODO: implement
// $data = $this->api->request('/workflow/versions/1/processes/'. $process->getId() .'/tasks');
return [];
});
// Fetch tasks
$process->setTasks([]);

return $process;
}

/**
* Find alfresco process by id
* @var $id - process id (alfresco)
* @return Process process object
**/
public function findProcess($id)
{
$result = $this->api->request('process_info', [
'id' => $id
]);
return $this->buildProcessObject($result['entry']);
}
}

0 comments on commit ea6c164

Please sign in to comment.