1515* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
1616*/
1717
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-
3118namespace PhpOffice \PhpWord \Element ;
3219
3320use PhpOffice \PhpWord \Shared \String ;
3724 */
3825class Field extends AbstractElement
3926{
40- /** @const */
4127
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+ */
4335 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 ' )
4941 ),
5042 '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 ' )
5656 )
5757 );
5858
@@ -128,15 +128,14 @@ public function getType()
128128 public function setProperties ($ properties = array ())
129129 {
130130 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+ }
137135 }
136+ $ this ->properties =array_merge ($ this ->properties , $ properties );
138137 }
139- return self ;
138+ return $ this -> properties ;
140139 }
141140
142141 /**
@@ -158,13 +157,14 @@ public function getProperties()
158157 public function setOptions ($ options = array ())
159158 {
160159 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+ }
165164 }
165+ $ this ->options =array_merge ($ this ->options , $ options );
166166 }
167- return self ;
167+ return $ this -> options ;
168168 }
169169
170170 /**
@@ -176,5 +176,4 @@ public function getOptions()
176176 {
177177 return $ this ->options ;
178178 }
179-
180179}
0 commit comments