From f41ce78d455840995a50e603958e9fdc631100f9 Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Wed, 3 Feb 2016 10:53:57 +0100 Subject: [PATCH] Store: renamed flag 'phpunit' to 'phpUnit' Form: added flag $phpUnit. AbstractBuildForm: added one line description to all functions. Subrecords: changed column title delimiter from '@' to '|' to be more consistant to other places in QFQ. --- qfq/AbstractBuildForm.php | 124 +++++++++++++++++++++++++++++++------- qfq/Form.php | 4 +- qfq/store/Store.php | 10 +-- 3 files changed, 108 insertions(+), 30 deletions(-) diff --git a/qfq/AbstractBuildForm.php b/qfq/AbstractBuildForm.php index 7c6d6b081..d646bcada 100644 --- a/qfq/AbstractBuildForm.php +++ b/qfq/AbstractBuildForm.php @@ -95,6 +95,8 @@ abstract class AbstractBuildForm { abstract public function fillWrap(); /** + * Builds complete form. Depending of Formspecification, the layout will plain / table / bootstrap. + * * @return string The whole form as HTML * @throws CodeException * @throws DbException @@ -125,6 +127,11 @@ abstract class AbstractBuildForm { return $html; } + /** + * Builds the head area of the form. + * + * @return string + */ public function head() { $html = ''; @@ -135,6 +142,8 @@ abstract class AbstractBuildForm { } /** + * Wrap's $this->wrap[$item][WRAP_SETUP_START] around $value. If $flagOmitEmpty==true && $value=='': return ''. + * * @param $item * @param $value * @param bool|false $flagOmitEmpty @@ -147,7 +156,7 @@ abstract class AbstractBuildForm { } /** - * Rreturns complete '<form ...>' + * Rreturns complete '<form ...>'-tag * * @return string */ @@ -211,9 +220,11 @@ abstract class AbstractBuildForm { /** * @param $recordId * @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD + * @param int $feIdContainer * @return string * @throws CodeException * @throws DbException + * @throws \qfq\UserException */ public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0) { $html = ''; @@ -279,6 +290,8 @@ abstract class AbstractBuildForm { abstract public function buildRowSubrecord($formElement, $elementHtml); /** + * Extract Tag from $tag (might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''. + * * @param $tag * @param $value * @param bool|false $flagOmitEmpty @@ -296,6 +309,8 @@ abstract class AbstractBuildForm { } /** + * Builds a label, typically for an html-'<input>'-element. + * * @param array $htmlFormElementId * @param $label * @return string @@ -357,6 +372,8 @@ abstract class AbstractBuildForm { } /** + * Format's an attribute: $type=$value. If $flagOmitEmpty==true && $value=='': return ''. + * * @param $type * @param $value * @param bool|false $flagOmitEmpty @@ -371,6 +388,7 @@ abstract class AbstractBuildForm { /** * Builds a HTML attribute list, based on $attributeList. + * * E.g.: attributeList: [ 'type', 'autofocus' ] * generates: 'type="$formElement['type']" autofocus="$formElement['autofocus']" ' * @@ -389,6 +407,7 @@ abstract class AbstractBuildForm { /** * Construct HTML Input attribute for Client Validation: + * * type data predefined * ------- ----------------------- ------------------------------------------------------------------------------- * min|max <min value>|<max value> min="%s"|max="%s" @@ -420,6 +439,8 @@ abstract class AbstractBuildForm { } /** + * Set corresponding html attributes readonly/required/disabled, based on $formElement['mode']. + * * @param array $formElement * @return string * @throws UserException @@ -569,6 +590,8 @@ abstract class AbstractBuildForm { } /** + * Get the attribute definition list of an enum or set column. For strings, get the default value. Return elements as an array. + * * @param $column * @param $fieldType * @return array @@ -608,6 +631,7 @@ abstract class AbstractBuildForm { /** * For CheckBox's with only one checkbox: if no parameter:checked|unchecked is defined, take defaults: + * * checked: first Element in $itemKey * unchecked: '' * @@ -643,6 +667,8 @@ abstract class AbstractBuildForm { } /** + * Build a Checkbox based on two values. + * * @param array $formElement * @param $htmlFormElementId * @param $attribute @@ -660,7 +686,7 @@ abstract class AbstractBuildForm { $attribute .= $this->getAttributeList($formElement, ['autofocus']); -// $html = $this->buildNativeHidden( $htmlFormElementId, $formElement['unchecked']); + $html = $this->buildNativeHidden($htmlFormElementId, $formElement['unchecked']); $html .= '<input ' . $attribute . '>'; if (isset($formElement['label2'])) { @@ -671,15 +697,27 @@ abstract class AbstractBuildForm { } /** + * Builds a real HTML hidden form element. Usefull for Checkboxes, Multiple-Select and Radios. + * + * @param $htmlFormElementId + * @param $value + * @return string + */ + public function buildNativeHidden($htmlFormElementId, $value) { + return '<input type="hidden" name="' . $htmlFormElementId . '" value="' . htmlentities($value) . '">'; + } + + /** + * Build as many Checkboxes as items * @param array $formElement * @param $htmlFormElementId * @param $attributeBase * @param $value - * @param $itemKey - * @param $itemValue + * @param array $itemKey + * @param array $itemValue * @return string */ - public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, $itemKey, $itemValue) { + public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, array $itemKey, array $itemValue) { // Defines which of the checkboxes will be checked. $values = explode($value, ','); @@ -713,17 +751,6 @@ abstract class AbstractBuildForm { return $html; } - /** - * Builds a real HTML hidden form element. Usefull for Checkboxes, Multiple-Select and Radios. - * - * @param $htmlFormElementId - * @param $value - * @return string - */ - public function buildNativeHidden($htmlFormElementId, $value) { - return '<input type="hidden" name="' . $htmlFormElementId . '" value="' . htmlentities($value) . '">'; - } - /** * Submit hidden values by SIP. * @@ -794,6 +821,8 @@ abstract class AbstractBuildForm { } /** + * Builds a Selct (Dropdown) Box. + * * @param array $formElement * @param $htmlFormElementId * @param $value @@ -876,7 +905,7 @@ abstract class AbstractBuildForm { $html .= '<td>' . $this->editLink($formElement, $row['id'], $primaryRecord) . '</td>'; foreach ($row as $columnName => $value) { - $html .= '<td>' . $this->formatColumn($control, $columnName, $value) . '</td>'; + $html .= '<td>' . $this->renderCell($control, $columnName, $value) . '</td>'; } $html .= '</tr>'; } @@ -886,6 +915,21 @@ abstract class AbstractBuildForm { } /** + * Get various column format information based on the 'raw' column title. The attributes are separated by '|' and specified as 'key' or 'key=value'. + * + * - Return all parsed values as an assoc array. + * - For regular columns: If there is no 'width' specified, take the default 'SUBRECORD_COLUMN_WIDTH' + * - For 'icon / url / mailto': no width limit. + * + * Returned assoc array: + * title Only key. Element is non numeric, which is not a keyword 'width/nostrip/icon/url/mailto' + * width Key/Value Pair. Not provided for 'icon/url/mailto'. + * nostrip Only key. Do not strip HTML Tags from the content. + * icon Only key. Value will rendered (later) as an image. + * url Only key. Value will rendered (later) as a 'href' + * mailto Only key. Value will rendered (later) as a 'href mailto' + * + * * @param $titleRaw * @return array * @throws UserException @@ -898,11 +942,12 @@ abstract class AbstractBuildForm { $control['width'][$columnName] = SUBRECORD_COLUMN_WIDTH; // a) 'City@width=40', b) 'Status@icon', c) 'Mailto@width=80@nostrip' - $arr = KeyValueStringParser::parse($columnName, '=', '@', 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': + case 'title': break; case 'icon': case 'url': @@ -916,6 +961,9 @@ abstract class AbstractBuildForm { $control[$attribute][$columnName] = $value; } + if (!isset($control['title'][$columnName])) + $control['title'][$columnName] = ''; // Fallback: Might be wrong, but better than nothing. + // Limit title length $control['title'][$columnName] = substr($control['title'][$columnName], 0, $control['width'][$columnName]); @@ -928,6 +976,19 @@ abstract class AbstractBuildForm { } /** + * Renders an Link with a symbol (edit) and register a new SIP to grant permission to the link.. + * + * Returns <a href="<Link>"><span ...></span></a> + * + * Link: <page>?s=<SIP>&<standard typo3 params> + * SIP: form = $formElement['form'] (provided via formElement['parameter']) + * r = $targetRecordId + * Parse $formElement['detail'] with possible key/value pairs. E.g.: detail=id:gr_id,#{{a}}:p_id,#12:x_id + * gr_id = <<primarytable.id>> + * p_id = <<variable defined in SIP or Client>> + * x_id = 12 (constant) + * + * * @param $formElement * @param $targetRecordId * @param $record @@ -962,7 +1023,7 @@ abstract class AbstractBuildForm { //----------------- $queryString = Support::arrayToQueryString($queryStringArray); - $sip = $this->store->getSip(); + $sip = $this->store->getSipInstance(); $url = $formElement['page'] . $sip->queryStringToSip($queryString); return "<a href='$url'><span class='glyphicon glyphicon-pencil'></span></a>"; @@ -970,12 +1031,25 @@ abstract class AbstractBuildForm { } /** + * Renders $value as specified in array $control + * + * nostrip: by default, HTML tags are removed. With this attribute, the value will be delivered as it is. + * width: if there is a size limit - apply it. + * icon: The cell will be rendered as an image. $value should contain the name of an image in 'fileadmin/icons/' + * mailto: The cell will be rendered as an <a> tag with the 'mailto' attribute. + * url: The cell will be rendered as an <a> tag. The value will be exploded by '|'. $value[0] = href, value[1] = text. + * E.g. $value = 'www.math.uzh.ch/?id=45&v=234|Show details for Modul 123' >> <a href="www.math.uzh.ch/?id=45&v=234">Show details for Modul 123</a> + * * @param array $control * @param $columnName * @param $value * @return string */ - private function formatColumn(array $control, $columnName, $value) { + private function renderCell(array $control, $columnName, $value) { + + $arr = explode('|', $value); + if (count($arr) == 1) + $arr[1] = $arr[0]; $cell = isset($control['nostrip'][$columnName]) ? $value : strip_tags($value); @@ -987,17 +1061,19 @@ abstract class AbstractBuildForm { } if (isset($control['mailto'][$columnName])) { - $cell = "<a href='mailto:$cell'>$cell</a>"; + $cell = "<a href='mailto:$arr[0]'>$arr[1]</a>"; } if (isset($control['url'][$columnName])) { - $cell = "<a href='$cell'>$cell</a>"; + $cell = "<a href='$arr[0]'>$arr[1]</a>"; } return $cell; } /** + * Builts an Upload (File) Button. + * * @param array $formElement * @param $htmlFormElementId * @param $value @@ -1057,6 +1133,8 @@ abstract class AbstractBuildForm { } /** + * Build a HTML fieldset. Renders all assigned FormElements inside the fieldset. + * * @param array $formElement * @param $htmlFormElementId * @param $value @@ -1103,7 +1181,7 @@ abstract class AbstractBuildForm { unset($sipArray[SIP_URLPARAM]); $queryString = Support::arrayToQueryString($sipArray); - $sip = $this->store->getSip(); + $sip = $this->store->getSipInstance(); $sipValue = $sip->queryStringToSip($queryString, RETURN_SIP); diff --git a/qfq/Form.php b/qfq/Form.php index 191994c02..470d11c7e 100644 --- a/qfq/Form.php +++ b/qfq/Form.php @@ -93,10 +93,10 @@ class Form { * * @param string $bodytext */ - public function __construct($bodytext = '') { + public function __construct($bodytext = '', $phpUnit = false) { try { - $this->store = Store::getInstance($bodytext); + $this->store = Store::getInstance($bodytext, $phpUnit); $this->db = new Database(); $this->eval = new Evaluate($this->store, $this->db); } catch (UserException $e) { diff --git a/qfq/store/Store.php b/qfq/store/Store.php index 2c2889fb0..fae07dbef 100644 --- a/qfq/store/Store.php +++ b/qfq/store/Store.php @@ -286,12 +286,12 @@ class Store { /** * @param string $bodytext - * @param bool|false $phpunit + * @param bool|false $phpUnit * @return null|\qfq\Store */ - public static function getInstance($bodytext = '', $phpunit = false) { + public static function getInstance($bodytext = '', $phpUnit = false) { - if ($phpunit) { + if ($phpUnit) { if (self::$instance !== null) { self::unsetStore(STORE_TYPO3); @@ -343,7 +343,7 @@ class Store { $tmpUrlparam = OnArray::toString($tmpParam); // Create a fake SIP which has never been passed by URL - further processing might expect this to exist. - $sip = self::getSip()->queryStringToSip($tmpUrlparam, RETURN_SIP); + $sip = self::getSipInstance()->queryStringToSip($tmpUrlparam, RETURN_SIP); self::setVar(CLIENT_SIP, $sip, STORE_CLIENT); // Store in SIP Store (cause it's empty until now). @@ -355,7 +355,7 @@ class Store { /** * @return null|Sip */ - public static function getSip() { + public static function getSipInstance() { return self::$sip; } -- GitLab