Skip to content
Snippets Groups Projects
Commit 54e8e69d authored by Carsten  Rose's avatar Carsten Rose
Browse files

Form.php: started to implement FormPlain

FormBuildPlan.php: created
parent 124d7232
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,8 @@ namespace qfq;
use qfq;
use qfq\exceptions\UserException;
use qfq\exceptions\CodeException;
use qfq\exceptions\DbException;
use qfq\helper;
use qfq\store;
......@@ -18,12 +20,22 @@ require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/FormBuildPlain.php');
class Form {
protected $config = null;
protected $store = null;
protected $db = null;
protected $formDef = array(); // copy of the loaded form
protected $feDefAction = array(); // copy of all formElement.class='action' of the loaded form
protected $feDefNative = array(); // copy of all formElement.class='native' of the loaded form
protected $fe = array(); // current processed formElement
// protected $formElements = null;
// protected $userLog = null;
......@@ -45,27 +57,79 @@ class Form {
*/
$this->store = \qfq\store\Store::getInstance($bodytext);
$this->db = new Database();
}
/*
*
*/
public function process() {
$html = '';
$build = null;
// render:
// plain
// multimode: none
try {
// Form action: load or save?
$mode = ($this->store->getVar(CLIENT_POST_SIP, STORE_CLIENT) === false) ? FORM_LOAD : FORM_SAVE;
$this->loadFormDefinition();
// TODO: replace switch() by Marschaller
// render: FormPlain | FormBootstrap
switch ($this->formDef['render']) {
case 'Plain':
$build = new FormBuildPlain($this->formDef, $this->feDefAction, $this->feDefNative);
break;
case 'Bootstrap':
//TODO: implement bootstrap rendering: FormBuildBootstrap
break;
default:
throw new CodeException("this statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
switch ($mode) {
case FORM_LOAD:
// $this->formActionBefore();
$html .= $build->head();
$html .= $build->elements();
$html .= $build->tail();
// $this->formActionAfter();
break;
case FORM_SAVE:
break;
default:
throw new CodeException("this statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
return $html;
} catch (UserException $e) {
echo $e->formatMessage();
} catch (CodeException $e) {
echo $e->formatMessage();
} catch (DbException $e) {
echo $e->formatMessage();
} catch (\Exception $e) {
echo "Generic Exception: " . $e->getMessage();
}
$this->loadFormDefinition();
return "Hello World from class Form";
}
/**
* @throws DbException
*/
private function loadFormDefinition() {
$formName = $this->getFormName();
$this->formDef = $this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName]);
echo "Formname: $formName";
$sql = "SELECT * FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted='no' AND fe.class = ? AND fe.enabled='yes' ORDER BY fe.order, fe.id";
$this->feDefAction = $this->db->sql($sql, ROW_REGULAR, [$this->formDef["id"], 'action']);
$this->feDefNative = $this->db->sql($sql, ROW_REGULAR, [$this->formDef["id"], 'native']);
}
/**
......
<?php
namespace qfq;
use qfq;
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/Database.php');
/**
* Created by PhpStorm.
* User: crose
* Date: 1/6/16
* Time: 8:02 PM
*/
class FormBuildPlain {
protected $formDef = array(); // copy of the loaded form
protected $feDefAction = array(); // copy of all formElement.class='action' of the loaded form
protected $feDefNative = array(); // copy of all formElement.class='native' of the loaded form
protected $store = null;
public function __construct(array $formDef, array $feDefAction, array $feDefNative) {
$this->formDef = $formDef;
$this->feDefAction = $feDefAction;
$this->feDefNative = $feDefNative;
$this->store = \qfq\store\Store::getInstance();
$this->db = new Database();
}
public function head() {
$html = '<h1>' . $this->formDef['title'] . '</h1><form action="?" method="post" target="_top" accept-charset="UTF-8">';
return $html;
}
public function tail() {
$html = '<input type="submit" value="Submit"></form>';
return $html;
}
public function elements() {
$html = '';
foreach ($this->feDefNative as $fe) {
$html .= $fe['name'] . '<br>';
}
return $html;
}
}
\ No newline at end of file
......@@ -67,7 +67,8 @@ class Store {
// SYSTEM_FORM_ELEMENT_FIELD => SANATIZE_ALL,
SYSTEM_SQL_RAW => SANATIZE_ALL,
SYSTEM_SQL_FINAL => SANATIZE_ALL,
SYSTEM_SQL_COUNT => SANATIZE_DIGIT
SYSTEM_SQL_COUNT => SANATIZE_DIGIT,
SYSTEM_SQL_PARAM_ARRAY => SANATIZE_ALL
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment