Commit 4d6abeda authored by Carsten  Rose's avatar Carsten Rose
Browse files

Link.php, Report.php: starting with cleaning up class Link. Constructor...

Link.php, Report.php: starting with cleaning up class Link. Constructor purified, enhanced error reporting might be later implemented again.
AbstractBuildForm.php, BuildFormBootsrrap.php, BuildFormTable.php: renamed getAttribute() to doAttribute()
LinkTest.php: starting creation.
parent 2e3c31f3
......@@ -160,7 +160,7 @@ abstract class AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->getAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......@@ -183,7 +183,7 @@ abstract class AbstractBuildForm {
* @param bool|false $flagOmitEmpty
* @return string
*/
public function getAttribute($type, $value, $flagOmitEmpty = true) {
public function doAttribute($type, $value, $flagOmitEmpty = true) {
if ($flagOmitEmpty && $value === "")
return '';
......@@ -446,7 +446,7 @@ abstract class AbstractBuildForm {
public function buildInput(array $formElement, $htmlFormElementId, $value, &$json) {
$textarea = '';
$attribute = $this->getAttribute('name', $htmlFormElementId);
$attribute = $this->doAttribute('name', $htmlFormElementId);
// Check for input type 'textarea'
$colsRows = explode(',', $formElement['size'], 2);
......@@ -454,8 +454,8 @@ abstract class AbstractBuildForm {
// <textarea>
$htmlTag = '<textarea';
$attribute .= $this->getAttribute('cols', $colsRows[0]);
$attribute .= $this->getAttribute('rows', $colsRows[1]);
$attribute .= $this->doAttribute('cols', $colsRows[0]);
$attribute .= $this->doAttribute('rows', $colsRows[1]);
$textarea = htmlentities($value) . '</textarea>';
} else {
......@@ -471,13 +471,13 @@ abstract class AbstractBuildForm {
// 'maxLength' needs an upper 'L': naming convention for DB tables!
$attribute .= $this->getAttributeList($formElement, ['type', 'size', 'maxLength']);
$attribute .= $this->getAttribute('value', htmlentities($value), false);
$attribute .= $this->doAttribute('value', htmlentities($value), false);
}
}
$attribute .= $this->getAttributeList($formElement, ['autocomplete', 'autofocus', 'placeholder']);
$attribute .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->getAttribute('title', $formElement['tooltip']);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('title', $formElement['tooltip']);
$attribute .= $this->getInputCheckPattern($formElement['checkType'], $formElement['checkPattern']);
$attribute .= $this->getAttributeMode($formElement);
......@@ -541,7 +541,7 @@ abstract class AbstractBuildForm {
$attribute = '';
foreach ($attributeList as $item) {
if (isset($formElement[$item]))
$attribute .= $this->getAttribute(strtolower($item), $formElement[$item]);
$attribute .= $this->doAttribute(strtolower($item), $formElement[$item]);
}
return $attribute;
}
......@@ -611,15 +611,15 @@ abstract class AbstractBuildForm {
case 'show':
break;
case 'readonly':
$attribute .= $this->getAttribute('readonly', 'readonly');
$attribute .= $this->doAttribute('readonly', 'readonly');
break;
case 'required':
$attribute .= $this->getAttribute('required', 'required');
$attribute .= $this->doAttribute('required', 'required');
break;
case 'lock':
break;
case 'disabled':
$attribute .= $this->getAttribute('disabled', 'disabled');
$attribute .= $this->doAttribute('disabled', 'disabled');
break;
default:
$this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
......@@ -683,7 +683,7 @@ abstract class AbstractBuildForm {
}
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= $this->getAttribute('type', $formElement['type']);
$attributeBase .= $this->doAttribute('type', $formElement['type']);
switch ($formElement['checkBoxMode']) {
case 'single':
......@@ -865,12 +865,12 @@ abstract class AbstractBuildForm {
public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value) {
$html = '';
$attribute .= $this->getAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttribute('value', $formElement['checked'], false);
$attribute .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('value', $formElement['checked'], false);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
if ($formElement['checked'] === $value) {
$attribute .= $this->getAttribute('checked', 'checked');
$attribute .= $this->doAttribute('checked', 'checked');
}
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
......@@ -917,8 +917,8 @@ abstract class AbstractBuildForm {
// Defines which of the checkboxes will be checked.
$values = explode(',', $value);
$attributeBase .= $this->getAttribute('name', $htmlFormElementId);
$attributeBase .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->doAttribute('name', $htmlFormElementId);
$attributeBase .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$html = $this->buildNativeHidden($htmlFormElementId, '');
......@@ -933,14 +933,14 @@ abstract class AbstractBuildForm {
if ($flagFirst) {
$flagFirst = false;
if (isset($formElement['autofocus']))
$attribute .= $this->getAttribute('autofocus', $formElement['autofocus']);
$attribute .= $this->doAttribute('autofocus', $formElement['autofocus']);
}
$attribute .= $this->getAttribute('value', $itemKey[$ii]);
$attribute .= $this->doAttribute('value', $itemKey[$ii]);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
$attribute .= $this->getAttribute('checked', 'checked');
$attribute .= $this->doAttribute('checked', 'checked');
}
$htmlCheckbox = '<input ' . $attribute . '>';
......@@ -998,9 +998,9 @@ abstract class AbstractBuildForm {
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= $this->getAttribute('name', $htmlFormElementId);
$attributeBase .= $this->getAttribute('type', $formElement['type']);
$attributeBase .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->doAttribute('name', $htmlFormElementId);
$attributeBase .= $this->doAttribute('type', $formElement['type']);
$attributeBase .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$jj = 0;
$flagFirst = true;
......@@ -1012,12 +1012,12 @@ abstract class AbstractBuildForm {
if ($flagFirst) {
$flagFirst = false;
if (isset($formElement['autofocus']))
$attribute .= $this->getAttribute('autofocus', $formElement['autofocus']);
$attribute .= $this->doAttribute('autofocus', $formElement['autofocus']);
}
$attribute .= $this->getAttribute('value', $itemKey[$ii]);
$attribute .= $this->doAttribute('value', $itemKey[$ii]);
if ($itemKey[$ii] === $value) {
$attribute .= $this->getAttribute('checked', 'checked');
$attribute .= $this->doAttribute('checked', 'checked');
}
$element = '<input ' . $attribute . '>' . $itemValue[$ii];
......@@ -1057,13 +1057,13 @@ abstract class AbstractBuildForm {
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attribute = $this->getAttributeMode($formElement);
$attribute .= $this->getAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
if (isset($formElement['size']) && $formElement['size'] > 1) {
$attribute .= $this->getAttribute('size', $formElement['size']);
$attribute .= $this->getAttribute('multiple', 'multiple');
$attribute .= $this->doAttribute('size', $formElement['size']);
$attribute .= $this->doAttribute('multiple', 'multiple');
}
$option = '';
......@@ -1072,7 +1072,7 @@ abstract class AbstractBuildForm {
for ($ii = 0; $ii < count($itemValue); $ii++) {
$option .= '<option ';
$option .= $this->getAttribute('value', $itemKey[$ii]);
$option .= $this->doAttribute('value', $itemKey[$ii]);
$jsonValues[] = [
'value' => $itemKey[$ii],
......@@ -1416,10 +1416,10 @@ abstract class AbstractBuildForm {
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) {
$attribute = $this->getAttributeMode($formElement);
$attribute .= $this->getAttribute('type', 'file');
$attribute .= $this->getAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('type', 'file');
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttributeList($formElement, ['autofocus', 'accept']);
$attribute .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
......@@ -1490,8 +1490,8 @@ abstract class AbstractBuildForm {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
$attribute .= $this->getAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
// <fieldset>
$html = '<fieldset ' . $attribute . '>';
......
......@@ -94,7 +94,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->getAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$title = Support::wrapTag('<div class="hidden-xs col-sm-6 col-md-8">', Support::wrapTag('<h3>', $this->formSpec['title']));
$button = Support::wrapTag('<div class="col-xs-12 col-sm-6 col-md-4">', $this->buildButtons());
......
......@@ -67,7 +67,7 @@ class BuildFormTable extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->getAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......
......@@ -65,11 +65,15 @@ require_once(__DIR__ . '/../store/Sip.php');
class Link {
private $mailto = "", $url = "", $image = "", $text = "", $altText = "", $imageTitle = "", $question = "", $target = "", $additionalUrlParams = "";
private $toolTip = array(), $modeRender = 0, $picturePosition = "l", $modeHash = false, $encryption = 1;
private $toolTip = array();
private $modeRender = 0, $picturePosition = "l", $modeHash = false, $encryption = 1;
private $linkClass = "", $defaultLinkClass = "";
private $linkClassSelector = array("i" => "internal", "e" => "external");
private $renderControl, $link = "";
//TODO: delete muss noch implementiert werden
private $delete = '';
/**
* @var Sip
*/
......@@ -83,7 +87,6 @@ class Link {
// Simulate global variable: will be set much earlier in other functions. Will be shown in error messages.
private $fr_error;
private $exceptionBody = "";
/**
* @var Utils
*/
......@@ -99,21 +102,14 @@ class Link {
/**
* __construct
*
* @param string $fullLevel Recent processed level, f.e.: '10.20.sql'
* @param string $sql Recent processed query, f.e.: SELECT p.name FROM person AS p
* @param string $columnValue Definition of link
* @param int $count
* @param int $columnIndex
* @param string $fr_error
* @param string $dbAlias
* @param $fr_error
* @param Sip $sip
*/
public function __construct($fullLevel, $sql, $columnValue, $count, $columnIndex, $fr_error, $dbAlias = '', $sip) {
$this->exceptionBody = "Level: " . $fullLevel . ".sql = " . $sql . "\nRow: " . $count . " , Column: " . $columnIndex . " , Bad link: " . $columnValue . "\n";
public function __construct($fr_error, Sip $sip) {
$this->fr_error = $fr_error;
$this->dbAlias = $dbAlias;
$this->sip = $sip;
$this->store = Store::getInstance();
$this->toolTip = ['', ''];
$this->cssLinkClassInternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_INTERNAL, STORE_SYSTEM);
$this->cssLinkClassExternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_EXTERNAL, STORE_SYSTEM);
$this->initRenderControl();
......@@ -178,33 +174,32 @@ class Link {
* Build the whole link
*
* @param string $str : Qualifier with params. 'report'-syntax. F.e.: A:u:www.example.com|G:P:home.gif|t:Home"
* @param string $count
* @param string &$hash hash used by the link, and maybe created for the link if count=1
*
* @return string The complete Link
*/
public function renderLink($str, $count, &$hash) {
public function renderLink($str) {
// str="u:http://www.example.com|c:i|t:delete"
$parm = explode("|", $str);
$param = explode("|", $str);
// Parse all parameter, fill variables
foreach ($parm as $item) {
foreach ($param as $item) {
$arr = explode(":", $item, 2);
// set class defaults
$this->parseItem($arr[0], $arr[1]);
}
// if there is no url or mailto definition: {{global.pageId}}
if (!$this->url && !$this->mailto) $this->url = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
if (!$this->url && !$this->mailto)
$this->url = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
$this->doCssClass();
$htmlUrl = $this->doUrl($count, $hash);
// $htmlUrl = $this->doUrl($count, $hash);
$htmlUrl = $this->doUrl();
$htmlImage = $this->doImage();
// One space distance
if ($this->text) $distance = " ";
// Compose Image & Text
$distance = ' ';
$this->text = ($this->picturePosition == "l") ? $htmlImage . $distance . $this->text : $this->text . $distance . $htmlImage;
......@@ -274,7 +269,8 @@ class Link {
case '22':
case '23':
case '24':
$this->link = "<a href=\"javascript: void(0);\" onClick=\"var del = new FR.Delete({recordId:'" . $count . "',hash:'" . $hash . "',forward:'" . $this->pageAlias . "'});\" " . $this->linkClass . ">" . $this->text . "</a>";
//TODO: Alter Code, umstellen auf JS Client von RO. Vorlage koennte 'Delete' in Subrecord sein.
$this->link = "<a href=\"javascript: void(0);\" onClick=\"var del = new FR.Delete({recordId:'',hash:'',forward:'" . $this->pageAlias . "'});\" " . $this->linkClass . ">" . $this->text . "</a>";
}
return $this->link;
......@@ -415,6 +411,7 @@ class Link {
case "G":
case "A":
$arr = explode(":", $value, 2);
// set class defaults
$this->parseItem($arr[0], $arr[1]);
break;
case "" :
......@@ -434,18 +431,22 @@ class Link {
* @return void
*/
private function doCssClass() {
$class = '';
// class: i|e|n|<custom name>
if ($this->linkClass != 'n') {
if (!$this->linkClass) $this->linkClass = $this->defaultLinkClass;
if ($this->linkClassSelector[$this->linkClass])
$this->linkClass = $this->linkClassSelector[$this->linkClass];
$this->linkClass = ' class="' . $this->linkClass . '"';
} else {
$this->linkClass = "";
switch ($this->linkClass) {
case 'n':
$class = '';
break;
case 'i':
case 'e':
$class = $this->linkClassSelector[$this->linkClass];
break;
default:
$class = ($this->linkClass == '') ? $this->defaultLinkClass : $this->linkClass;
break;
}
$this->linkClass = ($class == '') ? '' : ' class="' . $this->linkClass . '"';
}
/**
......
......@@ -583,8 +583,8 @@ class Report {
$content = "";
switch ($columnName) {
case "link":
$link = new Link($full_level, $this->frArray[$full_level . ".sql"], $columnValue, $rowIndex, $columnIndex, $this->fr_error, $this->sip);
$content .= $link->renderLink($columnValue, $rowIndex, $this->frArray[$full_level . "." . "hash." . "$columnIndex"]);
$link = new Link($this->fr_error, $this->dbAlias, $this->sip);
$content .= $link->renderLink($columnValue);
# unset $link;
break;
case "exec":
......@@ -601,8 +601,8 @@ class Report {
case "Pages":
$linkValue = $this->doFixColPosPage($columnName, $columnValue);
$link = new Link($full_level, $this->frArray[$full_level . ".sql"], $linkValue, $rowIndex, $columnIndex, $this->fr_error, $this->dbAlias, $this->sip);
$content .= $link->renderLink($linkValue, $rowIndex, $this->frArray[$full_level . "." . "hash." . "$columnIndex"]);
$link = new Link($this->fr_error, $this->sip);
$content .= $link->renderLink($linkValue);
break;
case "page":
......@@ -617,8 +617,8 @@ class Report {
$linkValue = $this->doPage($columnName, $columnValue);
// debug($linkValue);
$link = new Link($full_level, $this->frArray[$full_level . ".sql"], $linkValue, $rowIndex, $columnIndex, $this->fr_error, $this->dbAlias, $this->sip);
$content .= $link->renderLink($linkValue, $rowIndex, $this->frArray[$full_level . "." . "hash." . "$columnIndex"]);
$link = new Link($this->fr_error, $this->sip);
$content .= $link->renderLink($linkValue);
break;
case "img":
......@@ -811,7 +811,7 @@ class Report {
* -------------
* [<page id|alias>[&param=value&...]] | [record id] | [text] | [tooltip] | [msgbox] | [class] | [target] | [render mode] | [create hash]
*
* param[0]: <page id|alias>[&param=value&..
* param[0]: <page id|alias>[&param=value&...]
* param[1]: record id
* param[2]: text
* param[3]: tooltip
......@@ -832,7 +832,8 @@ class Report {
// Split definition
$param = explode('|', $columnValue);
if (count($param) > 9) throw new SyntaxReportException ("Too many parameter (max=9): $columnValue", "", __FILE__, __LINE__, $this->fr_error);
if (count($param) > 9)
throw new SyntaxReportException ("Too many parameter (max=9): $columnValue", "", __FILE__, __LINE__, $this->fr_error);
// make first 'P' lowercase
$columnName = 'p' . substr($columnName, 1);
......@@ -854,7 +855,8 @@ class Report {
if (!$param[8]) $param[8] = $this->page_control["hash"][$columnName]; // if no hash behaviour defined, use default
if ($param[8] == "h") $link .= "h|";
if ($this->page_control["icon"][$columnName]) $link .= $this->page_control["icon"][$columnName] . "|";
if ($this->page_control["icon"][$columnName])
$link .= $this->page_control["icon"][$columnName] . "|";
return ($link);
}
......
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 3/31/16
* Time: 10:06 PM
*/
namespace qfq;
require_once(__DIR__ . '/../../qfq/report/Link.php');
class LinkTest extends \PHPUnit_Framework_TestCase {
public function testLinkSingle() {
$link = new Link(null, null);
$result = $link->renderLink('u:http://math.uzh.ch');
$this->assertEquals($result, '<a href="http://math.uzh.ch" class=""> </a>');
}
public function testLinkClass() {
}
}
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