Skip to content
Snippets Groups Projects
Commit 1374ed34 authored by jaapjansma's avatar jaapjansma
Browse files

did some refactoring

parent 7a4193ff
No related branches found
No related tags found
No related merge requests found
......@@ -144,8 +144,7 @@
$objAction->copyValues($action);
// Create a parameter bag for the action
$parameterBag = $dataBag->convertToActionProviderParameterBag($actionProvider);
$mappedParameterBag = $actionProvider->createdMappedParameterBag($parameterBag, $action['mapping']);
$mappedParameterBag = $this->convertDataBagToMappedParameterBag($dataBag, $action['mapping'], $actionProvider);
$outputBag = $action['type']->execute($mappedParameterBag);
// Add the output of the action to the data bag of this action.
$dataBag->setActionDataFromActionProviderParameterBag($objAction, $outputBag);
......@@ -154,6 +153,24 @@
return $formProcessor['output_handler']->handle($dataBag);
}
/**
* Converts a DataBag object to a mapped parameterBag.
*
* @param DataBag $dataBag
* @param array $mapping
* @param $actionProvider
* @return ParameterBag;
*/
protected function convertDataBagToMappedParameterBag(DataBag $dataBag, $mapping, $actionProvider) {
$parameterBag = $actionProvider->createParameterBag();
$fields = $dataBag->getAllAliases();
foreach($fields as $field) {
$parameterBag->setParameter($field, $dataBag->getDataByAlias($field));
}
$mappedParameterBag = $actionProvider->createdMappedParameterBag($parameterBag, $mapping);
return $mappedParameterBag;
}
/**
* @param int $version
* API version.
......
......@@ -107,7 +107,10 @@ class DataBag {
public function getDataByAlias($alias) {
$splitted_alias = explode(".", $alias);
if ($splitted_alias[0] == 'input') {
return $this->inputData[$splitted_alias[1]];
$input = $this->getInputByName($splitted_alias[1]);
if ($input) {
return $this->inputData[$input->id];
}
} elseif ($splitted_alias[0] == 'action') {
return $this->actionData[$splitted_alias[1]][$splitted_alias[2]];
}
......@@ -115,20 +118,37 @@ class DataBag {
}
/**
* Convert this data bag to the action provider parameter bag.
* Returns all the aliases for data fields.
*
* An alias looks like:
* input.email
* action.3.contact_id
*
* @return array.
*/
public function convertToActionProviderParameterBag($actionProvider) {
$parameterBag = $actionProvider->createParameterBag();
public function getAllAliases() {
$aliases = array();
foreach($this->inputs as $input) {
$parameterBag->setParameter('input.'.$input->name, $this->inputData[$input->id]);
$aliases[] = 'input.'.$input->name;
}
foreach($this->actions as $action) {
foreach($this->actionData[$action->id] as $field => $value) {
$outputParameterName = 'action.'.$action->id.'.'.$field;
$parameterBag->setParameter($outputParameterName, $value);
$aliases[] = 'action.'.$action->id.'.'.$field;
}
}
return $parameterBag;
return $aliases;
}
/**
* Returns the input object by its name.
*/
private function getInputByName($name) {
foreach($this->inputs as $input) {
if ($input->name == $name) {
return $input;
}
}
return null;
}
}
......@@ -71,7 +71,7 @@
* @return string
*/
public function getLabel() {
return E::ts('Formal output');
return E::ts('Formatted output');
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment