phpMv
-UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
FormInstanceViewer.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ajax\semantic\widgets\dataform
;
4
5
use
Ajax\semantic\widgets\base\InstanceViewer
;
6
use
Ajax\service\JString
;
7
use
Ajax\semantic\html\collections\form\HtmlFormInput
;
8
9
class
FormInstanceViewer
extends
InstanceViewer
{
10
protected
$separators
;
11
protected
$headers
;
12
protected
$wrappers
;
13
14
public
function
__construct
($identifier,
$instance
=
NULL
,
$captions
=
NULL
) {
15
parent::__construct($identifier,
$instance
,
$captions
);
16
$this->
separators
=[-1];
17
$this->
headers
=[];
18
$this->
wrappers
=[];
19
$this->
defaultValueFunction
=
function
($name,$value,
$index
){
20
$caption=$this->
getCaption
(
$index
);
21
$input=
new
HtmlFormInput
($this->
widgetIdentifier
.
"-"
.$name,$caption,
"text"
,$value);
22
$input->setName($name);
23
return
$input;
24
};
25
}
26
27
protected
function
_beforeAddProperty
(
$index
,&
$field
){
28
if
(JString::endswith(
$field
,
"\n"
)===
true
){
29
$this->
addSeparatorAfter
(
$index
);
30
}
31
if
(
$index
>1 && JString::startswith(
$field
,
"\n"
)===
true
){
32
$this->
addSeparatorAfter
(
$index
-1);
33
}
34
$field
=
\str_replace
(
"\n"
,
""
,
$field
);
35
if
(($header=$this->
hasHeader
(
$field
))!==
false
){
36
$this->
addHeaderDividerBefore
(
$index
, $header);
37
}
38
}
39
40
protected
function
hasHeader
(&
$field
){
41
$matches
=[];
$result
=
false
;
42
if
(\
preg_match
(
'/\{(.*?)\}/s'
,
$field
,
$matches
)===1){
43
$result
=
$matches
[1];
44
$field
=
\str_replace
(
"{"
.
$result
.
"}"
,
""
,
$field
);
45
}
46
return
$result
;
47
}
48
49
50
51
public
function
addSeparatorAfter
(
$fieldNum
){
52
if
(\
array_search
(
$fieldNum
, $this->
separators
)===
false
)
53
$this->
separators
[]=
$fieldNum
;
54
return
$this
;
55
}
56
57
public
function
addHeaderDividerBefore
(
$fieldNum
,$header){
58
$this->
headers
[
$fieldNum
]=$header;
59
if
(
$fieldNum
>0)
60
$this->
addSeparatorAfter
(
$fieldNum
-1);
61
return
$this
;
62
}
63
64
public
function
addWrapper
(
$fieldNum
,
$contentBefore
,
$contentAfter
=
null
){
65
$this->
wrappers
[
$fieldNum
]=[
$contentBefore
,
$contentAfter
];
66
return
$this
;
67
}
68
69
public
function
getSeparators
() {
70
return
$this->separators
;
71
}
72
73
public
function
removeSeparator
(
$index
){
74
\array_splice
($this->
separators
,
$index
,1);
75
}
76
77
public
function
removeField
(
$index
){
78
parent::removeField(
$index
);
79
$pos
=
\array_search
(
$index
, $this->
separators
);
80
if
(
$pos
!==
false
){
81
$sepCount
=
\sizeof
($this->
separators
);
82
for
(
$i
=
$pos
+1;
$i
<
$sepCount
;
$i
++){
83
$this->
separators
[
$i
]--;
84
}
85
\array_splice
($this->
separators
,
$pos
, 1);
86
}
87
return
$this
;
88
}
89
90
public
function
setSeparators
(
$separators
) {
91
$this->
separators
=
\array_merge
([-1],
$separators
);
92
return
$this
;
93
}
94
95
public
function
getHeaders
() {
96
return
$this->headers
;
97
}
98
99
public
function
getWrappers
() {
100
return
$this->wrappers
;
101
}
102
103
public
function
setWrappers
(
$wrappers
) {
104
$this->
wrappers
=
$wrappers
;
105
return
$this
;
106
}
107
108
109
110
}
Ajax\semantic\html\collections\form\HtmlFormInput
Definition
HtmlFormInput.php:7
Ajax\semantic\widgets\base\InstanceViewer
Definition
InstanceViewer.php:8
Ajax\semantic\widgets\base\InstanceViewer\getCaption
getCaption($index)
Definition
InstanceViewer.php:331
Ajax\semantic\widgets\base\InstanceViewer\$index
static $index
Definition
InstanceViewer.php:32
Ajax\semantic\widgets\base\InstanceViewer\$captions
$captions
Definition
InstanceViewer.php:24
Ajax\semantic\widgets\base\InstanceViewer\$instance
$instance
Definition
InstanceViewer.php:12
Ajax\semantic\widgets\dataform\FormInstanceViewer
Definition
FormInstanceViewer.php:9
Ajax\semantic\widgets\dataform\FormInstanceViewer\addHeaderDividerBefore
addHeaderDividerBefore($fieldNum, $header)
Definition
FormInstanceViewer.php:57
Ajax\semantic\widgets\dataform\FormInstanceViewer\getHeaders
getHeaders()
Definition
FormInstanceViewer.php:95
Ajax\semantic\widgets\dataform\FormInstanceViewer\$separators
$separators
Definition
FormInstanceViewer.php:10
Ajax\semantic\widgets\dataform\FormInstanceViewer\$headers
$headers
Definition
FormInstanceViewer.php:11
Ajax\semantic\widgets\dataform\FormInstanceViewer\_beforeAddProperty
_beforeAddProperty($index, &$field)
Definition
FormInstanceViewer.php:27
Ajax\semantic\widgets\dataform\FormInstanceViewer\addWrapper
addWrapper($fieldNum, $contentBefore, $contentAfter=null)
Definition
FormInstanceViewer.php:64
Ajax\semantic\widgets\dataform\FormInstanceViewer\removeSeparator
removeSeparator($index)
Definition
FormInstanceViewer.php:73
Ajax\semantic\widgets\dataform\FormInstanceViewer\getWrappers
getWrappers()
Definition
FormInstanceViewer.php:99
Ajax\semantic\widgets\dataform\FormInstanceViewer\addSeparatorAfter
addSeparatorAfter($fieldNum)
Definition
FormInstanceViewer.php:51
Ajax\semantic\widgets\dataform\FormInstanceViewer\setSeparators
setSeparators($separators)
Definition
FormInstanceViewer.php:90
Ajax\semantic\widgets\dataform\FormInstanceViewer\hasHeader
hasHeader(&$field)
Definition
FormInstanceViewer.php:40
Ajax\semantic\widgets\dataform\FormInstanceViewer\$wrappers
$wrappers
Definition
FormInstanceViewer.php:12
Ajax\semantic\widgets\dataform\FormInstanceViewer\getSeparators
getSeparators()
Definition
FormInstanceViewer.php:69
Ajax\semantic\widgets\dataform\FormInstanceViewer\__construct
__construct($identifier, $instance=NULL, $captions=NULL)
Definition
FormInstanceViewer.php:14
Ajax\semantic\widgets\dataform\FormInstanceViewer\removeField
removeField($index)
Definition
FormInstanceViewer.php:77
Ajax\semantic\widgets\dataform\FormInstanceViewer\setWrappers
setWrappers($wrappers)
Definition
FormInstanceViewer.php:103
Ajax\service\JString
Definition
JString.php:4
Ajax\semantic\widgets\dataform
Definition
DataForm.php:3
Ajax
semantic
widgets
dataform
FormInstanceViewer.php
Generated on Sun Dec 10 2023 16:16:10 for
phpMv-UI
by
doxygen
1.9.8