Commit 11e2de14 authored by Carsten  Rose's avatar Carsten Rose

QuickFormQuery: renamed from Form.php to QuickFormQuery.php. Include 'Report'....

QuickFormQuery: renamed from Form.php to QuickFormQuery.php. Include 'Report'. New: If there is no formname specified, this is not an error anymore - just do nothing.
QuickFormQueryTest: renamed from FormTest.php to QuickFormQueryTest.php
formEditor.sql: Fixed some missing 'not null' definitions.
BuildFormPlainTest, SipTest: Adjustments from renaming Form.php
qfq.php: renamed from form.php to qfq.php
index.php: Adjustments from renaming form.php
report.php: new test file, to see something with report (not working now)
parent fa26ecec
......@@ -30,7 +30,7 @@
<body>
<?php
require_once("t3/form.php");
require_once("t3/qfq.php");
require_once("qfq/Constants.php"); // just for the debug string below to simulate the t3 bodytext
//qfq\renderForm("\n# some notes\ndebugLoad = 5\n debugSave = 0\n form = mytestform");
......
......@@ -30,7 +30,7 @@
<body>
<?php
require_once("t3/form.php");
require_once("t3/qfq.php");
require_once("qfq/Constants.php"); // just for the debug string below to simulate the t3 bodytext
//qfq\renderForm("\n# some notes\ndebugLoad = 5\n debugSave = 0\n form = mytestform");
......
......@@ -66,7 +66,7 @@ const ERROR_CODE_SHOULD_NOT_HAPPEN = 1003;
const ERROR_VALUE_ALREADY_CODPIED = 1004;
const ERROR_SIP_MALFORMED = 1005;
const ERROR_SIP_INVALID = 1006;
const ERROR_MISSING_FORM_NAME = 1007;
//const ERROR_MISSING_FORM_NAME = 1007;
const ERROR_IN_SQL_STATEMENT = 1008;
const ERROR_READ_FILE = 1009;
const ERROR_MISSING_SESSIONNAME = 1010;
......
......@@ -10,14 +10,17 @@
namespace qfq;
use qfq;
use qfq\BuildFormPlain;
use qfq\BuildFormTable;
use qfq\BuildFormBootstrap;
use qfq\UserException;
use qfq\CodeException;
use qfq\DbException;
//use qfq\Report;
//use qfq\BuildFormPlain;
//use qfq\BuildFormTable;
//use qfq\BuildFormBootstrap;
//use qfq\UserException;
//use qfq\CodeException;
//use qfq\DbException;
//use qfq\helper;
use qfq\Store;
//use qfq\Store;
require_once(__DIR__ . '/../qfq/store/Store.php');
......@@ -33,6 +36,7 @@ require_once(__DIR__ . '/../qfq/Evaluate.php');
require_once(__DIR__ . '/../qfq/BuildFormPlain.php');
require_once(__DIR__ . '/../qfq/BuildFormTable.php');
require_once(__DIR__ . '/../qfq/BuildFormBootstrap.php');
require_once(__DIR__ . '/../qfq/report/Report.php');
/*
* Form will be called
......@@ -47,10 +51,10 @@ require_once(__DIR__ . '/../qfq/BuildFormBootstrap.php');
*/
/**
* Class Form
* Class Qfq
* @package qfq
*/
class Form {
class QuickFormQuery {
/**
* @var \qfq\Store instantiated class
......@@ -82,8 +86,8 @@ class Form {
*/
// protected $formElements = null;
// protected $userLog = null;
//TODO: remove this as soon as Report use STORE_TYPO3 to transfer the bodytext.
private $bodytext = '';
/**
* Construct the Form Class and Store too. This is the base initialization moment.
......@@ -96,9 +100,13 @@ class Form {
public function __construct($bodytext = '', $phpUnit = false) {
try {
//TODO: remove this as soon as Report use STORE_TYPO3 to transfer the bodytext.
$this->bodytext = $bodytext;
$this->store = Store::getInstance($bodytext, $phpUnit);
$this->db = new Database();
$this->eval = new Evaluate($this->store, $this->db);
} catch (UserException $e) {
echo $e->formatMessage();
exit;
......@@ -126,49 +134,10 @@ class Form {
mb_internal_encoding("UTF-8");
// render:
// plain
// multimode: none
try {
// Form action: load or save?
$mode = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' ? FORM_SAVE : FORM_LOAD;
$formName = $this->loadFormSpecification($mode);
$sipFound = $this->validateForm();
if (!$sipFound) {
$this->store->createSipAfterFormLoad($formName);
}
$this->store->fillStoreTableDefaultColumnType($this->formSpec['tableName']);
switch ($this->formSpec['render']) {
case 'plain':
$build = new BuildFormPlain($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
case 'table':
$build = new BuildFormTable($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
case 'bootstrap':
$build = new BuildFormBootstrap($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
default:
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
switch ($mode) {
case FORM_LOAD:
$html .= $build->process();
break;
case FORM_SAVE:
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative);
$save->process();
break;
default:
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
return $html;
$html .= $this->doForm();
// $html .= $this->doReport();
} catch (UserException $e) {
echo $e->formatMessage();
......@@ -183,6 +152,57 @@ class Form {
return $html;
}
/**
* Process form (load or save) if a formname is found.
* @return string
* @throws CodeException
* @throws UserException
*/
private function doForm() {
$html = '';
// Form action: load or save?
$mode = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' ? FORM_SAVE : FORM_LOAD;
$formName = $this->loadFormSpecification($mode);
if ($formName === false)
return '';
$sipFound = $this->validateForm();
if (!$sipFound) {
$this->store->createSipAfterFormLoad($formName);
}
$this->store->fillStoreTableDefaultColumnType($this->formSpec['tableName']);
switch ($this->formSpec['render']) {
case 'plain':
$build = new BuildFormPlain($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
case 'table':
$build = new BuildFormTable($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
case 'bootstrap':
$build = new BuildFormBootstrap($this->formSpec, $this->feSpecAction, $this->feSpecNative);
break;
default:
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
switch ($mode) {
case FORM_LOAD:
$html .= $build->process();
break;
case FORM_SAVE:
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative);
$save->process();
break;
default:
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
return $html;
}
/**
* Loads specification of recent form.
* Evaluates Form and all FormElements.
......@@ -192,13 +212,15 @@ class Form {
* Loaded 'native' FormElements are in $this->feSpecNative
*
* @param string $mode FORM_LOAD|FORM_SAVE
* @return string formName
* @return string|bool if found the formName, else 'false'.
* @throws DbException
* @throws UserException
*/
private function loadFormSpecification($mode) {
$formName = $this->getFormName();
if (false === $formName = $this->getFormName()) {
return false;
}
$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
$form = $this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName], 'Form not found or multiple forms with the same name.');
......@@ -233,7 +255,7 @@ class Form {
}
/**
* @return string
* @return string|bool Formname (Form.name) or FALSE if no formname found.
* @throws UserException
* @throws CodeException
*/
......@@ -241,11 +263,7 @@ class Form {
private function getFormName() {
$formName = $this->store->getVar(SIP_FORM, STORE_TYPO3 . STORE_SIP . STORE_CLIENT);
if ($formName !== false)
return $formName;
// TODO: phpunit tests all - missing formname always fires this exception
throw new UserException("Missing form name. Not found in T3_BODYTEXT / SIP / GET", ERROR_MISSING_FORM_NAME);
return $formName;
}
/**
......@@ -297,4 +315,13 @@ class Form {
return $sipFound;
}
private function doReport() {
$report = new Report();
$html = $report->process($this->bodytext);
return $html;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="packages/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="packages/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="packages/jqwidgets/css/jqx.base.css">
<link rel="stylesheet" href="packages/jqwidgets/css/jqx.darkblue.css">
<script src="packages/jquery/js/jquery.min.js"></script>
<script src="packages/bootstrap/js/bootstrap.min.js"></script>
<script src="packages/jqwidgets/js/jqx-all.js"></script>
<title>QFQ DevWrapper</title>
<style>
/*inline elements in horizontal mode are too much left*/
.form-horizontal .form-inline .form-group {
margin: 0;
}
.form-inline .control-label {
font-weight: normal;
}
</style>
</head>
<body>
<?php
require_once("t3/qfq.php");
require_once("qfq/Constants.php"); // just for the debug string below to simulate the t3 bodytext
//qfq\renderForm("\n# some notes\ndebugLoad = 5\n debugSave = 0\n form = mytestform");
qfq\renderForm("\n10.sql = SELECT * FROM Form\n10.head = <p>Hello world</p><p>\n10.tail=</p>\n");
?>
</body>
</html>
\ No newline at end of file
......@@ -64,12 +64,12 @@ CREATE TABLE IF NOT EXISTS `FormElement` (
`mode` ENUM('show', 'readonly', 'required', 'lock', 'disabled') NOT NULL DEFAULT 'show',
`class` ENUM('native', 'action', 'container') NOT NULL DEFAULT 'native',
`type` ENUM('checkbox', 'dateJQW', 'datetimeJQW', 'gridJQW', 'hidden', 'input',
`type` ENUM('checkbox', 'dateJQW', 'datetimeJQW', 'gridJQW', 'hidden', 'input',
'note', 'password', 'radio', 'select', 'subrecord', 'upload', 'fieldset', 'pill',
'before_load', 'before_save', 'before_insert', 'before_update', 'before_delete', 'after_load',
'after_save', 'after_insert', 'after_update', 'after_delete', 'feGroup',
'sendmail') NOT NULL DEFAULT 'input',
`checkType` ENUM('', 'min|max', 'pattern', 'number', 'email'),
`checkType` ENUM('', 'min|max', 'pattern', 'number', 'email') NOT NULL DEFAULT '',
`checkPattern` VARCHAR(255) NOT NULL DEFAULT '',
`onChange` VARCHAR(255) NOT NULL DEFAULT '',
......@@ -88,10 +88,10 @@ CREATE TABLE IF NOT EXISTS `FormElement` (
`sql1` TEXT NOT NULL,
`sql2` TEXT NOT NULL,
`parameter` TEXT NOT NULL,
`clientJs` TEXT,
`clientJs` TEXT NOT NULL,
`feGroup` VARCHAR(255) NOT NULL DEFAULT '',
`debug` ENUM('yes', 'no') NOT NULL DEFAULT 'no',
`debug` ENUM('yes', 'no') NOT NULL DEFAULT 'no',
`deleted` ENUM('yes', 'no') NOT NULL DEFAULT 'no',
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
......@@ -210,8 +210,6 @@ VALUES
(137, 2, 'created', 'Created', 'readonly', 'input', 'native', 420, 40, 20, '', '', '', '', '', '', 104, 'no');
# FormEditor: Small
INSERT INTO Form (name, title, noteInternal, tableName, permitNew, permitEdit, render, multiSql, parameter) VALUES
('person', 'Person {{SELECT ": ", firstName, " ", name, " (", id, ")" FROM Person WHERE id = {{recordId:S0}}}}',
......
......@@ -33,4 +33,5 @@ CREATE TABLE Gruppe (
t1 TEXT
);
# ---------------------------
......@@ -9,11 +9,11 @@
namespace qfq;
use qfq;
use qfq\exceptions\UserException;
use qfq\exceptions\CodeException;
use qfq\exceptions\DbException;
//use qfq\UserException;
//use qfq\CodeException;
//use qfq\DbException;
require_once(__DIR__ . '/../qfq/Form.php');
require_once(__DIR__ . '/../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
......@@ -30,8 +30,8 @@ require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
function renderForm($bodytext = "") {
try {
$form = new Form($bodytext);
echo $form->process();
$qfq = new QuickFormQuery($bodytext);
echo $qfq->process();
echo "test";
......
<?php
require_once(__DIR__ . '/../../qfq/BuildFormPlain.php');
require_once(__DIR__ . '/../../qfq/Form.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/AbstractDatabaseTest.php');
/**
......@@ -12,8 +12,6 @@ require_once(__DIR__ . '/AbstractDatabaseTest.php');
*/
class BuildFormPlainTest extends AbstractDatabaseTest {
// private $form;
public function testGetProcessFilter() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
......@@ -390,11 +388,10 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
// $this->executeSQLFile(__DIR__ . '/fixtures/TestFormEditor.sql', true);
$this->form = new \qfq\Form("form=form\nr=3", true);
$this->form = new \qfq\QuickFormQuery("form=form\nr=3", true);
// this is necessary to initialize SIP
$content = $this->form->process();
}
}
......@@ -9,16 +9,16 @@
require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/Form.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../../qfq/store/Store.php');
class FormTest extends \PHPUnit_Framework_TestCase {
class QuickFormQueryTest extends \PHPUnit_Framework_TestCase {
private $store;
public function testProcess() {
$form = new qfq\Form("\n; some comment\n" . TYPO3_FORM . "=testformnameDoNotChange\n" . TYPO3_DEBUG_SAVE . "=6\n" . TYPO3_DEBUG_LOAD . "=7\n");
$form = new qfq\QuickFormQuery("\n; some comment\n" . TYPO3_FORM . "=testformnameDoNotChange\n" . TYPO3_DEBUG_SAVE . "=6\n" . TYPO3_DEBUG_LOAD . "=7\n");
// $this->assertEquals("", $form->process());
}
......
......@@ -5,7 +5,7 @@ namespace qfq;
//use qfq\Sip;
require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/Form.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../../qfq/store/Sip.php');
/**
......
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