Commit 62cf0470 authored by Carsten  Rose's avatar Carsten Rose
Browse files

HelperFormElement: renamed explodeFieldParameter() to explodeParameter()

parent 7cd7aa5f
......@@ -17,41 +17,57 @@ require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../../qfq/exceptions/UserException.php');
class HelperFormElement {
class HelperFormElement
{
/**
* Take all rows from field $element['parameter'] and merge them with $element. '$element' grows in size.
*
* Iterates over all FormElements in $elements.
* If $element['parameter'] exist and is filled: explode the content and apend them to the current array.
* If $element['parameter'] exist and is filled: explode the content and append them to the current array.
*
* @param array $elements
* @throws UserException
*/
public static function explodeFieldParameter(array &$elements) {
// Iterate all FormElements
foreach ($elements AS $key => $element) {
// Something to explode?
if (isset($element['parameter']) && $element['parameter'] !== '') {
// Explode
$arr = KeyValueStringParser::parse($element['parameter'], "=", "\n");
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
$store = Store::getInstance();
$store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM);
$store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM);
throw new UserException("Found reserved keyname '$checkKey'", ERROR_RESERVED_KEY_NAME);
}
public static function explodeParameter(array &$element)
{
// Something to explode?
if (isset($element['parameter']) && $element['parameter'] !== '') {
// Explode
$arr = KeyValueStringParser::parse($element['parameter'], "=", "\n");
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
$store = Store::getInstance();
$store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM);
$store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM);
throw new UserException("Found reserved keyname '$checkKey'", ERROR_RESERVED_KEY_NAME);
}
$elements[$key] = array_merge($element, $arr);
}
$element = array_merge($element, $arr);
}
}
/**
* @param array $elements
* @throws \qfq\UserException
*/
public static function explodeParameterInArrayElements(array &$elements)
{
foreach ($elements AS $key => $element) {
self::explodeParameter($element);
}
}
public static function buildFormElementId($field, $id) {
return($field . ':' . $id);
/**
* @param $field
* @param $id
* @return string
*/
public static function buildFormElementId($field, $id)
{
return ($field . ':' . $id);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment