Commit 8f3e3ce4 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Manual.rst: Doc updated for latest subrecord column special names

AbstractBuildForm.php: new function subrecordHead(). Replaced several hard coded subrecord column names against constants.
parent 4820c4d0
......@@ -2848,13 +2848,13 @@ will be rendered inside the form as a HTML table.
* Notice the **exclamation mark** after '{{' - this is necessary to return an array of elements, instead of a single string.
* Exactly one column **'id'** has to exist; it specifies the primary record for the target form.
In case the id should not be visible to the user, it has to be named **'_id'**.
* Columnname: *[title=]<title>[|[width=]<number>][|nostrip][|icon][|link][|url][|mailto][|_rowClass][|_rowTitle]*
* Columnname: *[title=]<title>[|[maxLength=]<number>][|width=<number>][|nostrip][|icon][|link][|url][|mailto][|_rowClass][|_rowTooltip]*
* All parameter are position independet.
* Separate parameter by '|'.
* If the keyword is used, all parameter are position independent.
* Parameter are seperated by '|'.
* *[title=]<text>*: Title of the column. The keyword 'title=' is optional. Columns with a title starting with '_' won't be rendered.
* *[width=]<number>*: Max. width of chars displayed per cell. The keyword 'width=' is optional. Default max width: 20.
This setting also affects the title of the column.
* *[maxLength=]<number>*: Max. number of characters displayed per cell. The keyword 'maxLength=' is optional. Default
maxLength '20'. A value of '0' means no limit. This setting also affects the title of the column.
* *nostrip*: by default, html tags will be stripped off the cell content before rendering. This protects the table
layout. 'nostrip' deactivates the cleaning to make pure html possible.
* *icon*: the cell value contains the name of an icon in *typo3conf/ext/qfq/Resources/Public/icons*. Empty cell values
......@@ -2865,21 +2865,21 @@ will be rendered inside the form as a HTML table.
* *_rowClass*
* The value is a CSS class name(s) which will be rendered in the *<tr class="<_rowClass>">* of the subrecord table.
* The column itself is hidden to the user.
* The column itself is not rendered.
* By using Bootstrap, the following predefined classes are available:
* Text color: *text-muted|text-primary|text-success|text-info|text-warning|text-danger* (http://getbootstrap.com/css/#helper-classes)
* Row background: *active|success|info|warning|danger* (http://getbootstrap.com/css/#tables-contextual-classes)
* *_rowTitle*
* *_rowTooltip*
* Defines the title attribute of a subrecod table row (tooltip).
* Defines the title attribute (=tooltip) of a subrecord table row.
* Examples::
{{!SELECT id, note1 AS 'Comment', note2 AS 'Comment|50' , note3 AS 'title=Comment|width=100|nostrip', note4 AS '50|Comment',
{{!SELECT id, note1 AS 'Comment', note2 AS 'Comment|50' , note3 AS 'title=Comment|maxLength=100|nostrip', note4 AS '50|Comment',
'checked.png' AS 'Status|icon', email AS 'mailto', CONCAT(homepage, '|Homepage') AS 'url',
ELT(status,'info','warning','danger') AS '_rowClass', help AS '_rowTitle' ...}}
ELT(status,'info','warning','danger') AS '_rowClass', help AS '_rowTooltip' ...}}
* *FormElement.parameter*
......
......@@ -2320,6 +2320,33 @@ abstract class AbstractBuildForm {
return $html . $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
/**
* @param string $linkNew Complete Button, incl. SIP href
* @param bool $flagDelete Flag to show if there is columns 'delete' rendered.
* @param array $firstRow First row of all subrecords to extract columntitles
* @param array $control Array with <th> column names / format.
*
* @return string
*/
private function subrecordHead($linkNew, $flagDelete, array $firstRow, array &$control) {
$columns = $linkNew;
if (!empty($firstRow)) {
// construct column attributes
$control = $this->getSubrecordColumnControl(array_keys($firstRow));
// Subrecord: Column titles
$columns .= '<th>' . implode('</th><th>', $control[SUBRECORD_COLUMN_TITLE]) . '</th>';
}
if ($flagDelete) {
$columns .= '<th></th>';
}
return Support::wrapTag('<thead><tr>', $columns);
}
/**
* Construct a HTML table of the subrecord data.
* Column syntax
......@@ -2347,7 +2374,7 @@ abstract class AbstractBuildForm {
$primaryRecord = $this->store->getStore(STORE_RECORD);
if (!$this->prepareSubrecod($formElement, $primaryRecord, $rcText, $nameColumnId)) {
if (!$this->prepareSubrecord($formElement, $primaryRecord, $rcText, $nameColumnId)) {
return $rcText;
}
......@@ -2365,23 +2392,9 @@ abstract class AbstractBuildForm {
$linkNew = $flagNew ? Support::wrapTag('<th>', $this->createFormLink($formElement, 0, $primaryRecord, $this->symbol[SYMBOL_NEW], 'New')) : '<th></th>';
}
$columns = $linkNew;
if (isset($formElement[FE_SQL1][0])) {
// construct column attributes
$control = $this->getSubrecordColumnControl(array_keys($formElement[FE_SQL1][0]));
// Subrecord: Column titles
$columns .= '<th>' . implode('</th><th>', $control['title']) . '</th>';
}
if ($flagDelete) {
$columns .= '<th></th>';
}
// Table head
$html = Support::wrapTag('<thead><tr>', $columns);
$firstRow = isset($formElement[FE_SQL1][0]) ? $formElement[FE_SQL1][0] : null;
$htmlHead = $this->subrecordHead($linkNew, $flagDelete, $firstRow, $control);
$htmlBody = '';
foreach ($formElement[FE_SQL1] as $row) {
$rowHtml = '';
......@@ -2395,8 +2408,8 @@ abstract class AbstractBuildForm {
// All columns
foreach ($row as $columnName => $value) {
if (isset($control['title'][$columnName])) {
$rowHtml .= Support::wrapTag('<td>', $this->renderCell($control, $columnName, $value));
if (isset($control[SUBRECORD_COLUMN_TITLE][$columnName])) {
$rowHtml .= Support::wrapTag("<td>", $this->renderCell($control, $columnName, $value));
}
}
......@@ -2411,21 +2424,25 @@ abstract class AbstractBuildForm {
$rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete btn btn-default' data-sip='$s' " . Support::doAttribute('title', $toolTip) . ">", '<span class="glyphicon ' . GLYPH_ICON_DELETE . '"></span>'));
}
Support::setIfNotSet($row, FE_SUBRECORD_ROW_CLASS);
$rowClass = 'record ';
$rowClass .= $row[FE_SUBRECORD_ROW_CLASS];
Support::setIfNotSet($row, FE_SUBRECORD_ROW_TITLE);
$rowTitle = $row[FE_SUBRECORD_ROW_TITLE];
Support::setIfNotSet($row, SUBRECORD_COLUMN_ROW_CLASS);
$rowClass = 'record ';
$rowClass .= $row[SUBRECORD_COLUMN_ROW_CLASS];
$rowTooltip = '';
if (isset($row[SUBRECORD_COLUMN_ROW_TOOLTIP])) {
$rowTooltip = $row[SUBRECORD_COLUMN_ROW_TOOLTIP];
} elseif (isset($row[SUBRECORD_COLUMN_ROW_TITLE])) { // backward compatibility
$rowTooltip = $row[SUBRECORD_COLUMN_ROW_TITLE];
}
$rowAttribute = Support::doAttribute('class', $rowClass);
$rowAttribute .= Support::doAttribute('title', $rowTitle);
$html .= Support::wrapTag("<tr $rowAttribute>", $rowHtml, true);
$rowAttribute .= Support::doAttribute('title', $rowTooltip);
$htmlBody .= Support::wrapTag("<tr $rowAttribute>", $rowHtml, true);
}
$attribute = Support::doAttribute('class', $formElement[FE_SUBRECORD_TABLE_CLASS]);
return Support::wrapTag("<table $attribute>", $html, true);
return Support::wrapTag("<table $attribute>", $htmlHead . Support::wrapTag('<tbody>', $htmlBody), true);
}
/**
......@@ -2442,7 +2459,7 @@ abstract class AbstractBuildForm {
* @return bool
* @throws \qfq\UserFormException
*/
private function prepareSubrecod(array $formElement, array $primaryRecord, &$rcText, &$nameColumnId) {
private function prepareSubrecord(array $formElement, array $primaryRecord, &$rcText, &$nameColumnId) {
if (!isset($primaryRecord['id'])) {
$rcText = 'Please save this record first.';
......@@ -2604,53 +2621,53 @@ abstract class AbstractBuildForm {
foreach ($titleRaw AS $columnName) {
switch ($columnName) {
case FE_SUBRECORD_ROW_CLASS:
case FE_SUBRECORD_ROW_TITLE:
case SUBRECORD_COLUMN_ROW_CLASS:
case SUBRECORD_COLUMN_ROW_TOOLTIP:
case SUBRECORD_COLUMN_ROW_TITLE: // Backward compatibility
continue 2;
default:
break;
}
$flagWidthLimit = true;
$control['width'][$columnName] = SUBRECORD_COLUMN_WIDTH;
$control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName] = SUBRECORD_COLUMN_DEFAULT_MAX_LENGTH;
// a) 'City@width=40', b) 'Status@icon', c) 'Mailto@width=80@nostrip'
// a) 'City@maxLength=40', b) 'Status@icon', c) 'Mailto@maxLength=80@nostrip'
$arr = KeyValueStringParser::parse($columnName, '=', '|', KVP_IF_VALUE_EMPTY_COPY_KEY);
foreach ($arr as $attribute => $value) {
switch ($attribute) {
case 'width':
case 'nostrip':
case 'title':
case 'link':
case SUBRECORD_COLUMN_MAX_LENGTH:
case SUBRECORD_COLUMN_NO_STRIP:
case SUBRECORD_COLUMN_TITLE:
case SUBRECORD_COLUMN_LINK:
break;
case 'icon':
case 'url':
case 'mailto':
case SUBRECORD_COLUMN_ICON:
case SUBRECORD_COLUMN_URL:
case SUBRECORD_COLUMN_MAILTO:
$flagWidthLimit = false;
break;
default:
$attribute = is_numeric($value) ? 'width' : 'title';
$attribute = is_numeric($value) ? SUBRECORD_COLUMN_MAX_LENGTH : SUBRECORD_COLUMN_TITLE;
break;
}
$control[$attribute][$columnName] = $value;
}
if (!isset($control['title'][$columnName]))
$control['title'][$columnName] = ''; // Fallback: Might be wrong, but better than nothing.
if (!isset($control[SUBRECORD_COLUMN_TITLE][$columnName]))
$control[SUBRECORD_COLUMN_TITLE][$columnName] = ''; // Fallback: Might be wrong, but better than nothing.
// Don't render Columns starting with '_...'.
if (substr($control['title'][$columnName], 0, 1) === '_') {
unset($control['title'][$columnName]); // Do not render column later.
if (substr($control[SUBRECORD_COLUMN_TITLE][$columnName], 0, 1) === '_') {
unset($control[SUBRECORD_COLUMN_TITLE][$columnName]); // Do not render column later.
continue;
}
// Limit title length
$control['title'][$columnName] = substr($control['title'][$columnName], 0, $control['width'][$columnName]);
$control[SUBRECORD_COLUMN_TITLE][$columnName] = mb_substr($control[SUBRECORD_COLUMN_TITLE][$columnName], 0, $control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName]);
if (!$flagWidthLimit) {
$control['width'][$columnName] = false;
$control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName] = false;
}
}
return $control;
......@@ -2678,8 +2695,8 @@ abstract class AbstractBuildForm {
$link = null;
switch ($columnName) {
case FE_SUBRECORD_ROW_CLASS:
case FE_SUBRECORD_ROW_TITLE:
case SUBRECORD_COLUMN_ROW_CLASS:
case SUBRECORD_COLUMN_ROW_TITLE:
return '';
default:
break;
......@@ -2689,32 +2706,31 @@ abstract class AbstractBuildForm {
if (count($arr) == 1) {
$arr[1] = $arr[0];
}
// $cell = isset($control['nostrip'][$columnName]) ? $columnValue : strip_tags($columnValue);
if (isset($control['nostrip'][$columnName])) {
if (isset($control[SUBRECORD_COLUMN_NO_STRIP][$columnName])) {
$cell = $columnValue;
$control['width'][$columnName] = false;
$control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName] = false;
} else {
$cell = strip_tags($columnValue);
}
if ($control['width'][$columnName] !== false && $control['width'][$columnName] != 0) {
$cell = substr($cell, 0, $control['width'][$columnName]);
if ($control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName] !== false && $control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName] != 0) {
$cell = mb_substr($cell, 0, $control[SUBRECORD_COLUMN_MAX_LENGTH][$columnName]);
}
if (isset($control['icon'][$columnName])) {
if (isset($control[SUBRECORD_COLUMN_ICON][$columnName])) {
$cell = ($cell === '') ? '' : "<image src='" . PATH_ICONS . "/$cell'>";
}
if (isset($control['mailto'][$columnName])) {
if (isset($control[SUBRECORD_COLUMN_MAILTO][$columnName])) {
$cell = "<a " . Support::doAttribute('href', "mailto:$arr[0]") . ">$arr[1]</a>";
}
if (isset($control['url'][$columnName])) {
if (isset($control[SUBRECORD_COLUMN_URL][$columnName])) {
$cell = "<a " . Support::doAttribute('href', $arr[0]) . ">$arr[1]</a>";
}
if (isset($control['link'][$columnName])) {
if (isset($control[SUBRECORD_COLUMN_LINK][$columnName])) {
if (!isset($link)) {
$link = new Link($this->sip);
}
......
......@@ -672,7 +672,7 @@ const ALIGN_HORIZONTAL = 'horizontal';
const ALIGN_VERTICAL = 'vertical';
// Subrecord
const SUBRECORD_COLUMN_WIDTH = 20;
const SUBRECORD_COLUMN_DEFAULT_MAX_LENGTH = 20;
const FORM_ELEMENTS_NATIVE = 'native';
const FORM_ELEMENTS_SUBRECORD = 'subrecord';
const FORM_ELEMENTS_NATIVE_SUBRECORD = 'native_subrecord';
......@@ -684,6 +684,17 @@ const SUBRECORD_PARAMETER_FORM = CLIENT_FORM;
const SUBRECORD_PARAMETER_PAGE = 'page';
const SUBRECORD_PARAMETER_DETAIL = 'detail';
const SUBRECORD_COLUMN_TITLE = 'title';
const SUBRECORD_COLUMN_MAX_LENGTH = 'maxLength';
const SUBRECORD_COLUMN_NO_STRIP = 'nostrip';
const SUBRECORD_COLUMN_ICON = 'icon';
const SUBRECORD_COLUMN_LINK = 'link';
const SUBRECORD_COLUMN_URL = 'url';
const SUBRECORD_COLUMN_MAILTO = 'mailto';
const SUBRECORD_COLUMN_ROW_CLASS = '_rowClass';
const SUBRECORD_COLUMN_ROW_TITLE = '_rowTitle';
const SUBRECORD_COLUMN_ROW_TOOLTIP = '_rowTooltip';
const GLYPH_ICON = 'glyphicon';
const GLYPH_ICON_EDIT = 'glyphicon-pencil';
const GLYPH_ICON_NEW = 'glyphicon-plus';
......@@ -793,9 +804,6 @@ const FE_CLASS_NATIVE = 'native';
const FE_CLASS_ACTION = 'action';
const FE_CLASS_CONTAINER = 'container';
const FE_SUBRECORD_ROW_CLASS = '_rowClass';
const FE_SUBRECORD_ROW_TITLE = '_rowTitle';
// FormElement columns: real
const FE_ID = 'id';
const FE_ID_CONTAINER = 'feIdContainer';
......
......@@ -331,107 +331,107 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['sql1'] = $this->db->sql('SELECT id, name, firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tr class="record" ><td>1</td><td>Doe</td><td>John</td></tr><tr class="record" ><td>2</td><td>Smith</td><td>Jane</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tbody><tr class="record" ><td>1</td><td>Doe</td><td>John</td></tr><tr class="record" ><td>2</td><td>Smith</td><td>Jane</td></tr></tbody></table>', $result);
// _id: 1, name: Doe,
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe,title=''
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, column: _Person
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "unused|width=2|title=_Person", firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>firstName</th></tr></thead><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>firstName</th></tr></thead><tbody><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, title: PERSON
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PERSON</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PERSON</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, "This is a much longer text than necessary": Default max:20
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "This is a much longer text than necessary" FROM Person ORDER BY id LIMIT 1');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>This is a much longe</th></tr></thead><tr class="record" ><td>This is a much longe</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>This is a much longe</th></tr></thead><tbody><tr class="record" ><td>This is a much longe</td></tr></tbody></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PE</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PE</th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: Doe ('width':3)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Nam</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Nam</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
// _id: 1, name: Doe (width:3, title:PERSON)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PER</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PER</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b>
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b>, width=2
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Na</th></tr></thead><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Na</th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b> , nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tbody><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></tbody></table>', $result);
// _id: 1, icon: bullet-green.gif
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "bullet-green.gif" AS "Status|icon" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Status</th></tr></thead><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Status</th></tr></thead><tbody><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></tbody></table>', $result);
// _id: 1, mailto: john@doe.com
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "john@doe.com" AS "EMail|mailto" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>EMail</th></tr></thead><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>EMail</th></tr></thead><tbody><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></tbody></table>', $result);
// _id: 1, url: www.uzh.ch
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "www.uzh.ch" AS "URL|url" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>URL</th></tr></thead><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>URL</th></tr></thead><tbody><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowclass (text)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning", "text-danger") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowClass (text & background)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning active", "text-danger success") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowTitle
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, title, width, nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, "<b>This again is a very long text</b>" AS "title=Important|width=10|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th>Important</th></tr></thead><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th>Important</th></tr></thead><tbody><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></tbody></table>', $result);
// _id: 1, name: Doe, link
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, CONCAT("s:1|p:form&form=person&r=" , id , "|t:", name) AS "link" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th></th></tr></thead><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Smith</a></td></tr></table>', $result);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th></th></tr></thead><tbody><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Smith</a></td></tr></tbody></table>', $result);
}
/**
......
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