15
15
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
16
*/
17
17
18
- /*
19
- * <w:fldSimple w:instr=" NUMWORDS \# "€ #.##0,00;(€ #.##0,00)" \* Arabic \* MERGEFORMAT ">
20
- <w:r>
21
- <w:rPr>
22
- <w:noProof/>
23
- </w:rPr>
24
- <w:t>5</w:t>
25
- </w:r>
26
- </w:fldSimple>
27
-
28
- */
29
-
30
-
31
18
namespace PhpOffice \PhpWord \Element ;
32
19
33
20
use PhpOffice \PhpWord \Shared \String ;
37
24
*/
38
25
class Field extends AbstractElement
39
26
{
40
- /** @const */
41
27
42
- //self::$fieldsArray;
28
+
29
+ /**
30
+ * Field properties and options. Depending on type, a field can have different properties
31
+ * and options
32
+ *
33
+ * @var array
34
+ */
43
35
protected $ fieldsArray = array (
44
- 'PAGE ' =>array (
45
- 'properties ' =>array (
46
- 'format ' => array ('Arabic ' , 'ArabicDash ' , 'alphabetic ' , 'ALPHABETIC ' , 'roman ' , 'ROMAN ' ),
47
- ),
48
- 'options ' =>array ()
36
+ 'PAGE ' =>array (
37
+ 'properties ' =>array (
38
+ 'format ' => array ('Arabic ' , 'ArabicDash ' , 'alphabetic ' , 'ALPHABETIC ' , 'roman ' , 'ROMAN ' ),
39
+ ),
40
+ 'options ' =>array (' PreserveFormat ' )
49
41
),
50
42
'NUMPAGES ' =>array (
51
- 'properties ' =>array (
52
- 'format ' => array ('Arabic ' , 'ArabicDash ' , 'alphabetic ' , 'ALPHABETIC ' , 'roman ' , 'ROMAN ' ),
53
- 'numformat ' => array ('0 ' , '0,00 ' , '#.##0 ' , '#.##0,00 ' , '€ #.##0,00(€ #.##0,00) ' , '0% ' , '0,00% ' )
54
- ),
55
- 'options ' =>array ()
43
+ 'properties ' =>array (
44
+ 'format ' => array ('Arabic ' , 'ArabicDash ' , 'alphabetic ' , 'ALPHABETIC ' , 'roman ' , 'ROMAN ' ),
45
+ 'numformat ' => array ('0 ' , '0,00 ' , '#.##0 ' , '#.##0,00 ' , '€ #.##0,00(€ #.##0,00) ' , '0% ' , '0,00% ' )
46
+ ),
47
+ 'options ' =>array ('PreserveFormat ' )
48
+ ),
49
+ 'DATE ' =>array (
50
+ 'properties ' => array (
51
+ 'dateformat ' =>array ('d-M-yyyy ' , 'dddd d MMMM yyyy ' , 'd MMMM yyyy ' , 'd-M-yy ' , 'yyyy-MM-dd ' ,
52
+ 'd-MMM-yy ' , 'd/M/yyyy ' , 'd MMM. yy ' , 'd/M/yy ' , 'MMM-yy ' , 'd-M-yyy H:mm ' , 'd-M-yyyy H:mm:ss ' ,
53
+ 'h:mm am/pm ' , 'h:mm:ss am/pm ' , 'HH:mm ' , 'HH:mm:ss ' )
54
+ ),
55
+ 'options ' =>array ('PreserveFormat ' , 'LunarCalendar ' , 'SakaEraCalendar ' , 'LastUsedFormat ' )
56
56
)
57
57
);
58
58
@@ -128,15 +128,14 @@ public function getType()
128
128
public function setProperties ($ properties = array ())
129
129
{
130
130
if (is_array ($ properties )) {
131
- //CREATE FUNCTION, WHICH MATCHES SUBARRAY
132
-
133
- if (array_key_exists ($ properties , $ this ->fieldsArray [$ this ->type ])) {
134
- $ this ->properties =array_merge ($ this ->properties , $ properties );
135
- } else {
136
- throw new \InvalidArgumentException ("Invalid property " );
131
+ foreach ($ properties as $ propkey => $ propval ) {
132
+ if (!(array_key_exists ($ propkey , $ this ->fieldsArray [$ this ->type ]['properties ' ]))) {
133
+ throw new \InvalidArgumentException ("Invalid property " );
134
+ }
137
135
}
136
+ $ this ->properties =array_merge ($ this ->properties , $ properties );
138
137
}
139
- return self ;
138
+ return $ this -> properties ;
140
139
}
141
140
142
141
/**
@@ -158,13 +157,14 @@ public function getProperties()
158
157
public function setOptions ($ options = array ())
159
158
{
160
159
if (is_array ($ options )) {
161
- if ( array_key_exists ( $ options, self :: $ fieldsArray [ $ this -> type ]) ) {
162
- $ this ->options = array_merge ( $ this ->options , $ options );
163
- } else {
164
- throw new \ InvalidArgumentException ( " Invalid option " );
160
+ foreach ( $ options as $ optionkey => $ optionval ) {
161
+ if (!( array_key_exists ( $ optionkey , $ this ->fieldsArray [ $ this ->type ][ ' options ' ]))) {
162
+ throw new \ InvalidArgumentException ( " Invalid option " );
163
+ }
165
164
}
165
+ $ this ->options =array_merge ($ this ->options , $ options );
166
166
}
167
- return self ;
167
+ return $ this -> options ;
168
168
}
169
169
170
170
/**
@@ -176,5 +176,4 @@ public function getOptions()
176
176
{
177
177
return $ this ->options ;
178
178
}
179
-
180
179
}
0 commit comments