Commit 3eb33091 authored by Carsten  Rose's avatar Carsten Rose
Browse files

*: Namespaces of helper classes changed to qfq. New Class 'HelperFormElement'....

*: Namespaces of helper classes changed to qfq. New Class 'HelperFormElement'. HTML 'fieldset' implemented.
parent 9f4c5c05
......@@ -8,15 +8,17 @@
namespace qfq;
use qfq;
use qfq\store\Store;
use qfq\Store;
use qfq\exceptions\UserException;
use qfq\helper\OnArray;
use qfq\OnArray;
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
/**
* Class AbstractBuildForm
......@@ -41,6 +43,7 @@ abstract class AbstractBuildForm {
$this->evaluate = new Evaluate($this->store, $this->db);
// $sip = $this->store->getVar(CLIENT_SIP, STORE_CLIENT);
// render mode specific
$this->fillWrap();
$this->buildElementFunctionName = [
......@@ -57,7 +60,8 @@ abstract class AbstractBuildForm {
'select' => 'Select',
'subrecord' => 'Subrecord',
'upload' => 'File',
'url' => 'Input'
'fieldset' => 'Fieldset',
'pill' => 'Pill'
];
$this->inputCheckPattern = [
......@@ -112,7 +116,7 @@ abstract class AbstractBuildForm {
* @throws exceptions\CodeException
* @throws exceptions\DbException
*/
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE) {
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer=0) {
$html = '';
// get current data record
......@@ -402,7 +406,7 @@ abstract class AbstractBuildForm {
}
} elseif (isset($formElement['itemList'])) {
$arr = qfq\helper\KeyValueStringParser::parse($formElement['itemList'], ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$arr = KeyValueStringParser::parse($formElement['itemList'], ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$itemValue = array_values($arr);
$itemKey = array_keys($arr);
} elseif ($fieldType === 'enum' || $fieldType === 'set') {
......@@ -719,7 +723,7 @@ abstract class AbstractBuildForm {
$control['width'][$col] = SUBRECORD_COLUMN_WIDTH;
// a) 'City@width=40', b) 'Status@icon', c) 'Mailto@width=80@nostrip'
$arr = qfq\helper\KeyValueStringParser::parse($col, '=', '@', IF_VALUE_EMPTY_COPY_KEY);
$arr = KeyValueStringParser::parse($col, '=', '@', IF_VALUE_EMPTY_COPY_KEY);
foreach ($arr as $attribute => $value) {
switch ($attribute) {
case 'width':
......@@ -787,4 +791,67 @@ abstract class AbstractBuildForm {
return $value;
}
/**
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @return mixed
*/
public function buildPill(array $formElement, $htmlFormElementId, $value) {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
$sql = SQL_FORM_ELEMENT;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [ 'yes', $this->formSpec["id"], 'native,container', $formElement['id'] ]);
HelperFormElement::explodeParameter($this->feSpecNative);
$html = $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD);
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
return $html;
}
/**
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @return mixed
*/
public function buildFieldset(array $formElement, $htmlFormElementId, $value) {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
// <fieldset>
$html = '<fieldset ' . $this->getAttribute('name', $htmlFormElementId) . '>';
if($formElement['label'] !== '') {
$html .= '<legend>' . $formElement['label'] . '</legend>';
}
$html .= $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START];
// child FE's
$sql = SQL_FORM_ELEMENT;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [ 'yes', $this->formSpec["id"], 'native,container', $formElement['id'] ]);
HelperFormElement::explodeParameter($this->feSpecNative);
$html .= $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD);
$html .= $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END];
$html .= '</fieldset>';
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
return $html;
}
}
\ No newline at end of file
......@@ -35,6 +35,10 @@ class BuildFormBootstrap extends AbstractBuildForm {
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
}
/**
......@@ -72,10 +76,6 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function wrapElement($htmlFormElementId, $formElement, $value) {
$html = '';
// Construct Marshaller Name
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
$html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true);
$html .= '<form action="?" method="post" target="_top" accept-charset="UTF-8">';
return $html;
......
......@@ -35,6 +35,10 @@ class BuildFormPlain extends AbstractBuildForm {
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
}
/**
......@@ -75,11 +79,14 @@ class BuildFormPlain extends AbstractBuildForm {
// Construct Marshaller Name
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
if($formElement['nestedInFieldSet']==='no')
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
if($formElement['nestedInFieldSet']==='no')
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
return $html;
}
......
......@@ -38,6 +38,9 @@ class BuildFormTable extends AbstractBuildForm {
$this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_END] = '</p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
}
/**
......@@ -85,11 +88,18 @@ class BuildFormTable extends AbstractBuildForm {
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['note']);
} else {
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
if ($formElement['nestedInFieldSet'] === 'no') {
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
} else {
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
if($formElement['note']!=='')
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['note']);
}
}
return $html;
......
......@@ -21,6 +21,8 @@ const SESSION_FE_USER_UID = 'fe_user_uid';
const RETURN_URL = 'return_url';
const RETURN_SIP = 'return_sip';
const SQL_FORM_ELEMENT = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
// Sanatize Classifier
const SANATIZE_ALLOW_ALNUMX = "alnumx";
const SANATIZE_ALLOW_DIGIT = "digit";
......@@ -34,6 +36,7 @@ const WRAP_SETUP_LABEL = 'label';
const WRAP_SETUP_INPUT = 'input';
const WRAP_SETUP_NOTE = 'note';
const WRAP_SETUP_SUBRECORD = 'subrecord';
const WRAP_SETUP_IN_FIELDSET = 'inFieldset';
const WRAP_SETUP_START = 'start';
const WRAP_SETUP_END = 'end';
......
......@@ -9,8 +9,7 @@
namespace qfq;
use qfq;
use qfq\store;
use qfq\exceptions;
use qfq\Store;
use qfq\exceptions\CodeException;
use qfq\exceptions\UserException;
use qfq\exceptions\DbException;
......@@ -33,7 +32,7 @@ class Database {
*/
public $pdo = null;
/**
* @var store\Store
* @var Store
*/
private $store = null;
private $stmt = null;
......@@ -46,7 +45,7 @@ class Database {
* @throws UserException
*/
public function __construct() {
$this->store = \qfq\store\Store::getInstance();
$this->store = Store::getInstance();
$this->pdo = $this->store->getVar(SYSTEM_DBH, STORE_SYSTEM);
......
......@@ -9,7 +9,7 @@
namespace qfq;
use qfq;
use qfq\store\Store;
use qfq\Store;
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Database.php');
......
......@@ -10,16 +10,20 @@
namespace qfq;
use qfq;
use qfq\BuildFormPlain;
use qfq\BuildFormTable;
use qfq\BuildFormBootstrap;
use qfq\exceptions\UserException;
use qfq\exceptions\CodeException;
use qfq\exceptions\DbException;
use qfq\helper;
use qfq\store\Store;
//use qfq\helper;
use qfq\Store;
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
......@@ -48,7 +52,7 @@ require_once(__DIR__ . '/../qfq/BuildFormBootstrap.php');
class Form {
/**
* @var \qfq\store\Store instantiated class
* @var \qfq\Store instantiated class
*/
protected $store = null;
/**
......@@ -175,13 +179,17 @@ class Form {
$this->formSpec = $this->eval->parseArray($this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName]));
$this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM);
$sql = "SELECT * FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted='no' AND fe.class = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
$this->feSpecAction = $this->eval->parseArray($this->db->sql($sql, ROW_REGULAR, [$this->formSpec["id"], 'action']));
$this->explodeFormElementParameter($this->feSpecAction);
// Native FormElements will be evaluated later
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [$this->formSpec["id"], 'native']);
$this->explodeFormElementParameter($this->feSpecNative);
// "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
$sql = SQL_FORM_ELEMENT;
// FE: Action
$this->feSpecAction = $this->eval->parseArray($this->db->sql($sql, ROW_REGULAR, ['no', $this->formSpec["id"], 'action', 0]));
HelperFormElement::explodeParameter($this->feSpecAction);
// FE: Native & Container
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, ['no', $this->formSpec["id"], 'native,container', 0]);
HelperFormElement::explodeParameter($this->feSpecNative);
return $formName;
}
......@@ -202,34 +210,6 @@ class Form {
throw new UserException("Missing form name. Not found in T3_BODYTEXT / SIP / GET", ERROR_MISSING_FORM_NAME);
}
/**
* Iterates over all FormElements in $elements.
* If $element['parameter'] exist and is filled: explode the content and apend them to the current FormElement Array.
*
* @param array $elements
* @throws UserException
*/
private function explodeFormElementParameter(array &$elements) {
// Iterate all FormElements
foreach ($elements AS $key => $element) {
// Something to explode?
if (isset($element['parameter']) && $element['parameter'] !== '') {
// Explode
$arr = helper\KeyValueStringParser::parse($element['parameter'], "=", "\n");
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
$this->store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM);
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM);
throw new UserException("Found reserved keyname '$checkKey'");
}
}
$elements[$key] = array_merge($element, $arr);
}
}
}
/**
* @return bool - 'true' if SIP exists, else 'false'
* @throws CodeException
......
......@@ -8,6 +8,8 @@
namespace qfq\exceptions;
use qfq\Store;
/**
* Class UserException
*
......
......@@ -9,6 +9,8 @@
namespace qfq\exceptions;
use qfq\Store;
require_once(__DIR__ . '/../../qfq/store/Store.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
......@@ -25,7 +27,7 @@ class DbException extends \Exception {
* @return string HTML formatted error string
*/
public function formatMessage() {
$store = \qfq\store\Store::getInstance('');
$store = Store::getInstance('');
$message = '<table border=1><tr><th>DB Exception</th></tr>' .
'<tr><td>Message</td><td><b>' . $this->getMessage() . '</b></td></tr>' .
......
......@@ -9,6 +9,8 @@
namespace qfq\exceptions;
use qfq\Store;
require_once(__DIR__ . '/../../qfq/store/Store.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
......
......@@ -8,7 +8,7 @@
* $Id$
*/
namespace qfq\helper;
namespace qfq;
use qfq;
use qfq\exceptions\UserException;
......
......@@ -7,13 +7,13 @@
*/
namespace qfq\helper;
namespace qfq;
require_once(__DIR__ . '/../../qfq/Constants.php');
/**
* Class OnArray
* @package qfq\helper
* @package qfq
*/
class OnArray {
......
......@@ -6,13 +6,12 @@
* Time: 10:26 PM
*/
namespace qfq\store;
namespace qfq;
use qfq\exceptions\CodeException;
use qfq\exceptions\UserException;
//use qfq\helper;
use qfq\helper\OnArray;
use qfq\helper\KeyValueStringParser;
use qfq\OnArray;
use qfq\KeyValueStringParser;
require_once(__DIR__ . '/../../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
......@@ -80,7 +79,7 @@ class Sip {
$script = $this->splitParamClientSip($paramArray, $clientArray, $sipArray);
// sort array to guarantee identical respresentation in $_SESSION. Param 'a, r, b, ...' should be saved as 'a, b, r, ..'
\qfq\helper\OnArray::sortKey($sipArray);
OnArray::sortKey($sipArray);
// Generate keyname for $_SESSION[]
$sipParamString = OnArray::toString($sipArray);
......
......@@ -6,11 +6,12 @@
* Time: 6:51 PM
*/
namespace qfq\store;
namespace qfq;
use qfq\exceptions\CodeException;
use qfq\keyValueStringParser;
use qfq\OnArray;
use qfq;
use \qfq\helper\keyValueStringParser;
require_once(__DIR__ . '/../../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../../qfq/helper/Sanatize.php');
......@@ -220,7 +221,7 @@ class Store {
private function fillStoreSip() {
$sessionName = self::getVar(SYSTEM_SESSIONNAME, STORE_SYSTEM);
self::$sip = new \qfq\store\Sip($sessionName);
self::$sip = new Sip($sessionName);
$s = self::getVar(CLIENT_SIP, STORE_CLIENT);
if ($s !== false) {
......@@ -277,7 +278,7 @@ class Store {
/**
* @param string $bodytext
* @param bool|false $phpunit
* @return null|\qfq\store\Store
* @return null|\qfq\Store
*/
public static function getInstance($bodytext = '', $phpunit = false) {
......@@ -312,7 +313,7 @@ class Store {
self::setVarArray($tmpParam, STORE_SIP);
// Construct fake urlparam
$tmpUrlparam = \qfq\helper\OnArray::toString($tmpParam);
$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()->urlparamToSip($tmpUrlparam, RETURN_SIP);
......
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