Commit 46ed17e5 authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm: subrecord extended with Prameter 'form' and 'detail'....

AbstractBuildForm: subrecord extended with Prameter 'form' and 'detail'. Renderung subrecord columns rewritten and two new columntypes added: 'url', 'mailto'
parent 9a2a507d
......@@ -426,8 +426,13 @@ abstract class AbstractBuildForm {
}
/**
* Look for key/value list in `sql1`, `parameter:itemList`, column definition (in this order, first match counts)
* Look for key/value list (in this order, first match counts) in
* a) `sql1`
* b) `parameter:itemList`
* c) table.column definition
*
* Copies the found keys to &$itemKey and the values to &$itemValue
* If there are no &$itemKey, copy &$itemValue to &$itemKey.
*
* @param array $formElement
* @param $itemKey
......@@ -702,23 +707,26 @@ abstract class AbstractBuildForm {
}
$option = '';
if (isset($formElement['emptyItemAtStart']))
$option = '<option></option>';
$selected = 'selected';
for ($ii = 0; $ii < count($itemValue); $ii++) {
$option .= '<option ';
$option .= $this->getAttribute('value', $itemKey[$ii]);
if ($itemKey[$ii] === $value) {
$attribute .= 'selected ';
$option .= $selected;
$selected = '';
}
$option .= '>' . $itemValue[$ii] . '</option>';
}
if (isset($formElement['emptyItemAtStart'])) {
$option = "<option $selected></option>";
$selected = '';
}
if (isset($formElement['emptyItemAtEnd']))
$option = '<option></option>';
$option = "<option $selected></option>";
return '<select ' . $attribute . '>' . $option . '</select>';
}
......@@ -747,14 +755,8 @@ abstract class AbstractBuildForm {
$html .= '<tr><th>' . implode('</th><th>', $control['title']) . '</th></tr>';
foreach ($formElement['sql1'] as $row) {
$html .= '<tr>';
foreach ($row as $col => $value) {
if (isset($control['icon'][$col])) {
$cell = ($value === '') ? '' : "<image src='fileadmin/icons/$value'>";
} else {
$cell = isset($control['nostrip'][$col]) ? $value : strip_tags($value);
$cell = substr($cell, 0, $control['width'][$col]);
}
$html .= "<td>$cell</td>";
foreach ($row as $columnName => $value) {
$html .= '<td>' . $this->formatColumn($control, $columnName, $value) . '</td>';
}
$html .= '</tr>';
}
......@@ -768,32 +770,71 @@ abstract class AbstractBuildForm {
* @return array
* @throws UserException
*/
private function getSubrecordColumnControl($titleRaw) {
private function getSubrecordColumnControl(array $titleRaw) {
$control = array();
foreach ($titleRaw AS $col) {
$control['width'][$col] = SUBRECORD_COLUMN_WIDTH;
foreach ($titleRaw AS $columnName) {
$flagWidthLimit = true;
$control['width'][$columnName] = SUBRECORD_COLUMN_WIDTH;
// a) 'City@width=40', b) 'Status@icon', c) 'Mailto@width=80@nostrip'
$arr = KeyValueStringParser::parse($col, '=', '@', IF_VALUE_EMPTY_COPY_KEY);
$arr = KeyValueStringParser::parse($columnName, '=', '@', IF_VALUE_EMPTY_COPY_KEY);
foreach ($arr as $attribute => $value) {
switch ($attribute) {
case 'width':
case 'nostrip':
break;
case 'icon':
case 'url':
case 'mailto':
$flagWidthLimit = false;
break;
default:
$attribute = 'title';
$attribute = is_numeric($value) ? 'width' : 'title';
break;
}
$control[$attribute][$col] = $value;
$control[$attribute][$columnName] = $value;
}
// Limit title length
$control['title'][$col] = substr($control['title'][$col], 0, $control['width'][$col]);
$control['title'][$columnName] = substr($control['title'][$columnName], 0, $control['width'][$columnName]);
if (!$flagWidthLimit) {
$control['width'][$columnName] = false;
}
}
return $control;
}
/**
* @param array $control
* @param $columnName
* @param $value
* @return string
*/
private function formatColumn(array $control, $columnName, $value) {
$cell = isset($control['nostrip'][$columnName]) ? $value : strip_tags($value);
if ($control['width'][$columnName] !== false)
$cell = substr($cell, 0, $control['width'][$columnName]);
if (isset($control['icon'][$columnName])) {
$cell = ($cell === '') ? '' : "<image src='fileadmin/icons/$cell'>";
}
if (isset($control['mailto'][$columnName])) {
$cell = "<a href='mailto:$cell'>$cell</a>";
}
if (isset($control['url'][$columnName])) {
$cell = "<a href='$cell'>$cell</a>";
}
return $cell;
}
/**
* @param array $formElement
* @param $htmlFormElementId
......
......@@ -156,5 +156,6 @@ VALUES
(1, 'created', 'Created', 'readonly', 'input', 420, 40, 20, '', '', '', '', '', '', 3),
(1, '', 'FormElements', 'show', 'subrecord', 500, 0, 0, '', '', '', '{{!SELECT * FROM FormElement WHERE formId=1}}',
'', '', 4);
'',
'form=formelement\ndetail=id:gr_id,#12:x_id', 4);
Supports Markdown
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