1
1
<?php
2
+
2
3
/**
3
4
* Read-only complement of {@link DropdownField}.
4
- * Shows the "human value" of the dropdown field for the currently selected value.
5
+ *
6
+ * Shows the "human value" of the dropdown field for the currently selected
7
+ * value.
8
+ *
5
9
* @package forms
6
10
* @subpackage fields-basic
7
11
*/
8
12
class LookupField extends DropdownField {
9
13
14
+ /**
15
+ * @var boolean $readonly
16
+ */
10
17
protected $ readonly = true ;
11
18
12
19
/**
13
20
* Returns a readonly span containing the correct value.
21
+ *
22
+ * @param array $properties
23
+ *
24
+ * @return string
14
25
*/
15
26
public function Field ($ properties = array ()) {
16
27
$ source = $ this ->getSource ();
17
28
18
-
19
29
// Normalize value to array to simplify further processing
20
- $ values = (is_array ($ this ->value ) || is_object ($ this ->value )) ? $ this ->value : array (trim ($ this ->value ));
30
+ if (is_array ($ this ->value ) || is_object ($ this ->value )) {
31
+ $ values = $ this ->value ;
32
+ } else {
33
+ $ values = array (trim ($ this ->value ));
34
+ }
21
35
22
36
$ mapped = array ();
37
+
23
38
if ($ source instanceof SQLMap) {
24
- foreach ($ values as $ value ) $ mapped [] = $ source ->getItem ($ value );
39
+ foreach ($ values as $ value ) {
40
+ $ mapped [] = $ source ->getItem ($ value );
41
+ }
25
42
} else if ($ source instanceof ArrayAccess || is_array ($ source )) {
43
+ $ source = ArrayLib::flatten ($ source );
44
+
26
45
foreach ($ values as $ value ) {
27
- if (isset ($ source [$ value ])) $ mapped [] = $ source [$ value ];
46
+ if (isset ($ source [$ value ])) {
47
+ $ mapped [] = $ source [$ value ];
48
+ }
28
49
}
29
50
} else {
30
51
$ mapped = array ();
@@ -39,7 +60,11 @@ public function Field($properties = array()) {
39
60
40
61
if ($ mapped ) {
41
62
$ attrValue = implode (', ' , array_values ($ mapped ));
42
- if (!$ this ->dontEscape ) $ attrValue = Convert::raw2xml ($ attrValue );
63
+
64
+ if (!$ this ->dontEscape ) {
65
+ $ attrValue = Convert::raw2xml ($ attrValue );
66
+ }
67
+
43
68
$ inputValue = implode (', ' , array_values ($ values ));
44
69
} else {
45
70
$ attrValue = "<i>(none)</i> " ;
@@ -51,17 +76,26 @@ public function Field($properties = array()) {
51
76
"\" value= \"" . $ inputValue . "\" /> " ;
52
77
}
53
78
79
+ /**
80
+ * @return LookupField
81
+ */
54
82
public function performReadonlyTransformation () {
55
83
$ clone = clone $ this ;
84
+
56
85
return $ clone ;
57
86
}
58
87
88
+ /**
89
+ * @return string
90
+ */
59
91
public function Type () {
60
92
return "lookup readonly " ;
61
93
}
62
94
63
95
/**
64
- * Override parent behaviour by not merging arrays.
96
+ * Override parent behavior by not merging arrays.
97
+ *
98
+ * @return array
65
99
*/
66
100
public function getSource () {
67
101
return $ this ->source ;
0 commit comments