Commit 419b692b authored by Carsten  Rose's avatar Carsten Rose
Browse files

Added column type 'link' to subrecords.

UsersManual/indes.rst: Desription for subrecord updated.
Sip.php: code cleaned up. Static SIP defined.
AbstractBuildForm.php: Column 'link' implemented.
parent e82f65e5
......@@ -903,7 +903,7 @@ 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][|url][|mailto][|_rowClass][|_rowTitle]*
* Columnname: *[title=]<title>[|[width=]<number>][|nostrip][|icon][|link][|url][|mailto][|_rowClass][|_rowTitle]*
* All parameter are position independet.
* Separate parameter by '|'.
......@@ -914,9 +914,9 @@ will be rendered inside the form as a HTML 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
will omit an html image tag (=nothing rendered in the cell).
* *mailto*: value will be rendered as a mailto link.
* *url*: value will be rendered as a link.
* *link*: value will be rendered as described under :ref:`column-link`
* *url*: value will be rendered as a href url.
* *mailto*: value will be rendered as a href mailto.
* *_rowClass*
* The value is a CSS class name(s) which will be rendered in the *<tr class="<_rowClass>">* of the subrecord table.
......
......@@ -21,6 +21,7 @@ require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../qfq/helper/Support.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../qfq/report/Link.php');
/**
......@@ -1419,13 +1420,14 @@ abstract class AbstractBuildForm {
// All columns
foreach ($row as $columnName => $value) {
if (isset($control['title'][$columnName]))
if (isset($control['title'][$columnName])) {
$rowHtml .= Support::wrapTag('<td>', $this->renderCell($control, $columnName, $value));
}
}
if ($flagDelete) {
$s = $this->createDeleteUrl($targetTableName, $row['id'], RETURN_SIP);
$rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete btn btn-default' data-sip='$s'>", '<span class="glyphicon ' . GLYPH_ICON_DELETE .'"></span>'));
$rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete btn btn-default' data-sip='$s'>", '<span class="glyphicon ' . GLYPH_ICON_DELETE . '"></span>'));
}
Support::setIfNotSet($row, FE_SUBRECORD_ROW_CLASS);
......@@ -1605,6 +1607,7 @@ abstract class AbstractBuildForm {
case 'width':
case 'nostrip':
case 'title':
case 'link':
break;
case 'icon':
case 'url':
......@@ -1650,10 +1653,11 @@ abstract class AbstractBuildForm {
*
* @param array $control
* @param $columnName
* @param $value
* @param $columnValue
* @return string
*/
private function renderCell(array $control, $columnName, $value) {
private function renderCell(array $control, $columnName, $columnValue) {
$link = null;
switch ($columnName) {
case FE_SUBRECORD_ROW_CLASS:
......@@ -1663,11 +1667,11 @@ abstract class AbstractBuildForm {
break;
}
$arr = explode('|', $value);
$arr = explode('|', $columnValue);
if (count($arr) == 1)
$arr[1] = $arr[0];
$cell = isset($control['nostrip'][$columnName]) ? $value : strip_tags($value);
$cell = isset($control['nostrip'][$columnName]) ? $columnValue : strip_tags($columnValue);
if ($control['width'][$columnName] !== false)
$cell = substr($cell, 0, $control['width'][$columnName]);
......@@ -1684,6 +1688,13 @@ abstract class AbstractBuildForm {
$cell = "<a " . Support::doAttribute('href', $arr[0]) . ">$arr[1]</a>";
}
if (isset($control['link'][$columnName])) {
if (!isset($link)) {
$link = new Link($this->sip);
}
$cell = $link->renderLink($columnValue);
}
return $cell;
}
......
......@@ -74,13 +74,13 @@ class Sip {
$sipParamString = OnArray::toString($sipArray);
$sessionParamSip = Session::get($sipParamString);
if ($sessionParamSip !== false) {
$s = $sessionParamSip;
} else {
if ($sessionParamSip === false) {
// Not found: create new entry
$s = $this->sipUniqId();
$s = $this->sipUniqId('badcaffee1234');
Session::set($sipParamString, $s);
Session::set($s, $sipParamString);
} else {
$s = $sessionParamSip;
}
// Append SIP to final parameter
......
......@@ -477,6 +477,11 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$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"><tr><th>name</th><th>Important</th></tr><tr class="record" ><td>Doe</td><td><b>This ag</td></tr><tr class="record" ><td>Smith</td><td><b>This ag</td></tr></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"><tr><th>name</th><th></th></tr><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);
}
/**
......
......@@ -51,9 +51,8 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$result = $sip->queryStringToSip("id=input&r=1&L=2&form=person&type=99", RETURN_SIP);
$this->assertEquals('badcaffee1234', $result);
$sip->sipUniqId('badcaffee0000');
$result = $sip->queryStringToSip("id=input&r=10&L=2&form=person&type=99", RETURN_SIP);
$this->assertEquals('badcaffee0000', $result);
$this->assertEquals('badcaffee1234', $result);
}
......@@ -78,7 +77,7 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$sip2 = $sip->queryStringToSip("http://example.com/index.php?aa=hello&bb=world", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2);
$this->assertEquals(['aa' => 'hello', 'bb' => 'world', 'r' => 0], $arr);
$this->assertEquals('badcaffee0000', $sip2);
$this->assertEquals('badcaffee1234', $sip2);
$sip2 = $sip->queryStringToSip("aaa=Don&bbb=John", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2);
......
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