Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
f2ab1e4a
Commit
f2ab1e4a
authored
Jan 15, 2016
by
Carsten Rose
Browse files
Form.php: added Evaluate()
parent
ab7eb626
Changes
3
Hide whitespace changes
Inline
Side-by-side
qfq/Form.php
View file @
f2ab1e4a
...
@@ -23,6 +23,7 @@ require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
...
@@ -23,6 +23,7 @@ require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once
(
__DIR__
.
'/../qfq/exceptions/CodeException.php'
);
require_once
(
__DIR__
.
'/../qfq/exceptions/CodeException.php'
);
require_once
(
__DIR__
.
'/../qfq/exceptions/DbException.php'
);
require_once
(
__DIR__
.
'/../qfq/exceptions/DbException.php'
);
require_once
(
__DIR__
.
'/../qfq/Database.php'
);
require_once
(
__DIR__
.
'/../qfq/Database.php'
);
require_once
(
__DIR__
.
'/../qfq/Evaluate.php'
);
require_once
(
__DIR__
.
'/../qfq/FormBuildPlain.php'
);
require_once
(
__DIR__
.
'/../qfq/FormBuildPlain.php'
);
/*
/*
...
@@ -78,6 +79,8 @@ class Form {
...
@@ -78,6 +79,8 @@ class Form {
$build
=
null
;
$build
=
null
;
$master
=
null
;
$master
=
null
;
mb_internal_encoding
(
"UTF-8"
);
// render:
// render:
// plain
// plain
// multimode: none
// multimode: none
...
@@ -88,9 +91,9 @@ class Form {
...
@@ -88,9 +91,9 @@ class Form {
$formName
=
$this
->
loadFormDefinition
();
$formName
=
$this
->
loadFormDefinition
();
$sipFound
=
$this
->
checkFormLoad
();
$sipFound
=
$this
->
validateForm
();
if
(
!
$sipFound
)
{
if
(
!
$sipFound
)
{
$this
->
store
->
create
Fake
SipAfterFormLoad
(
$formName
);
$this
->
store
->
createSipAfterFormLoad
(
$formName
);
}
}
// TODO: replace switch() by Marschaller
// TODO: replace switch() by Marschaller
...
@@ -160,12 +163,12 @@ class Form {
...
@@ -160,12 +163,12 @@ class Form {
private
function
getFormName
()
{
private
function
getFormName
()
{
$formName
=
$this
->
store
->
getVar
(
T
3_BODYTEXT
_FORM
,
STORE_T
3_BODYTEXT
.
STORE_SIP
.
STORE_CLIENT
);
$formName
=
$this
->
store
->
getVar
(
T
YPO3
_FORM
,
STORE_T
YPO3
.
STORE_SIP
.
STORE_CLIENT
);
if
(
$formName
!==
false
)
if
(
$formName
!==
false
)
return
$formName
;
return
$formName
;
// TODO: phpunit tests all - missing formname always fires this exception
// TODO: phpunit tests all - missing formname always fires this exception
throw
new
Code
Exception
(
"Missing form name. Not found in T3_BODYTEXT / SIP / GET"
,
ERROR_MISSING_FORM_NAME
);
throw
new
User
Exception
(
"Missing form name. Not found in T3_BODYTEXT / SIP / GET"
,
ERROR_MISSING_FORM_NAME
);
}
}
/**
/**
...
@@ -173,7 +176,7 @@ class Form {
...
@@ -173,7 +176,7 @@ class Form {
* @throws CodeException
* @throws CodeException
* @throws UserException
* @throws UserException
*/
*/
private
function
checkFormLoad
()
{
private
function
validateForm
()
{
// Retrieve record_id either from SIP (prefered) or via URL
// Retrieve record_id either from SIP (prefered) or via URL
$r
=
$this
->
store
->
getVar
(
SIP_RECORD_ID
,
STORE_SIP
.
STORE_CLIENT
);
$r
=
$this
->
store
->
getVar
(
SIP_RECORD_ID
,
STORE_SIP
.
STORE_CLIENT
);
...
@@ -209,6 +212,11 @@ class Form {
...
@@ -209,6 +212,11 @@ class Form {
throw
new
CodeException
(
"Unknown permission mode: '"
.
$mode
.
"'"
,
ERROR_FORM_UNKNOWN_PERMISSION_MODE
);
throw
new
CodeException
(
"Unknown permission mode: '"
.
$mode
.
"'"
,
ERROR_FORM_UNKNOWN_PERMISSION_MODE
);
}
}
// Form Definition valid?
if
(
$this
->
formDef
[
'multiMode'
]
!==
'none'
&&
$this
->
formDef
[
'multiSql'
]
===
''
)
{
throw
new
UserException
(
"MultiMode selected, but MultiSQL missing"
,
ERROR_MULTI_SQL_MISSING
);
}
return
$sipFound
;
return
$sipFound
;
}
}
...
...
qfq/FormBuildPlain.php
View file @
f2ab1e4a
...
@@ -20,6 +20,7 @@ class FormBuildPlain {
...
@@ -20,6 +20,7 @@ class FormBuildPlain {
protected
$feDefAction
=
array
();
// copy of all formElement.class='action' 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
$feDefNative
=
array
();
// copy of all formElement.class='native' of the loaded form
protected
$store
=
null
;
protected
$store
=
null
;
protected
$evaluate
=
null
;
public
function
__construct
(
array
$formDef
,
array
$feDefAction
,
array
$feDefNative
)
{
public
function
__construct
(
array
$formDef
,
array
$feDefAction
,
array
$feDefNative
)
{
$this
->
formDef
=
$formDef
;
$this
->
formDef
=
$formDef
;
...
@@ -27,10 +28,13 @@ class FormBuildPlain {
...
@@ -27,10 +28,13 @@ class FormBuildPlain {
$this
->
feDefNative
=
$feDefNative
;
$this
->
feDefNative
=
$feDefNative
;
$this
->
store
=
\
qfq\store\Store
::
getInstance
();
$this
->
store
=
\
qfq\store\Store
::
getInstance
();
$this
->
db
=
new
Database
();
$this
->
db
=
new
Database
();
$this
->
evaluate
=
new
Evaluate
(
$this
->
store
,
$this
->
db
);
}
}
public
function
head
()
{
public
function
head
()
{
$html
=
'<h1>'
.
$this
->
formDef
[
'title'
]
.
'</h1><form action="?" method="post" target="_top" accept-charset="UTF-8">'
;
$html
=
'<h1>'
.
$this
->
formDef
[
'title'
]
.
'</h1><form action="?" method="post" target="_top" accept-charset="UTF-8">'
;
return
$html
;
return
$html
;
...
@@ -45,6 +49,10 @@ class FormBuildPlain {
...
@@ -45,6 +49,10 @@ class FormBuildPlain {
public
function
elements
()
{
public
function
elements
()
{
$html
=
''
;
$html
=
''
;
if
(
$this
->
formDef
[
'multiMode'
]
!==
'none'
)
{
$masterRecords
=
$this
->
db
->
sql
(
$this
->
formDef
[
'multiMode'
]);
}
foreach
(
$this
->
feDefNative
as
$fe
)
{
foreach
(
$this
->
feDefNative
as
$fe
)
{
$html
.
=
$fe
[
'name'
]
.
'<br>'
;
$html
.
=
$fe
[
'name'
]
.
'<br>'
;
}
}
...
...
tests/phpunit/FormTest.php
View file @
f2ab1e4a
...
@@ -18,7 +18,7 @@ class FormTest extends PHPUnit_Framework_TestCase {
...
@@ -18,7 +18,7 @@ class FormTest extends PHPUnit_Framework_TestCase {
public
function
testProcess
()
{
public
function
testProcess
()
{
$form
=
new
qfq\Form
(
"
\n
; some comment
\n
"
.
T3_BODYTEXT
_FORM
.
"=testformnameDoNotChange
\n
"
.
T3_BODYTEXT
_DEBUG_SAVE
.
"=6
\n
"
.
T3_BODYTEXT
_DEBUG_LOAD
.
"=7
\n
"
);
$form
=
new
qfq\Form
(
"
\n
; some comment
\n
"
.
TYPO3
_FORM
.
"=testformnameDoNotChange
\n
"
.
TYPO3
_DEBUG_SAVE
.
"=6
\n
"
.
TYPO3
_DEBUG_LOAD
.
"=7
\n
"
);
$this
->
assertEquals
(
""
,
$form
->
process
());
$this
->
assertEquals
(
""
,
$form
->
process
());
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment