@@ -8,20 +8,23 @@ public static function sortByName($a, $b)
88 return strcmp (strtolower ($ a ['facility ' ]->getName ()), strtolower ($ b ['facility ' ]->getName ()));
99 }
1010
11- public static function getClass ($ attribute )
11+ public static function getClass ($ type )
1212 {
13- if ($ attribute ['type ' ] === 'java.lang.String ' || $ attribute ['type ' ] === 'java.lang.LargeString ' ) {
14- return 'string ' ;
15- } elseif ($ attribute ['type ' ] === 'java.lang.Integer ' ) {
16- return 'integer ' ;
17- } elseif ($ attribute ['type ' ] === 'java.lang.Boolean ' ) {
18- return 'boolean ' ;
19- } elseif ($ attribute ['type ' ] === 'java.util.ArrayList ' || $ attribute ['type ' ] === 'java.util.LargeArrayList ' ) {
20- return 'array ' ;
21- } elseif ($ attribute ['type ' ] === 'java.util.LinkedHashMap ' ) {
22- return 'map ' ;
23- } else {
24- return '' ;
13+ switch ($ type ) {
14+ case 'java.lang.String ' :
15+ case 'java.lang.LargeString ' :
16+ return 'string ' ;
17+ case 'java.lang.Integer ' :
18+ return 'integer ' ;
19+ case 'java.lang.Boolean ' :
20+ return 'boolean ' ;
21+ case 'java.util.ArrayList ' :
22+ case 'java.util.LargeArrayList ' :
23+ return 'array ' ;
24+ case 'java.util.LinkedHashMap ' :
25+ return 'map ' ;
26+ default :
27+ return '' ;
2528 }
2629 }
2730
@@ -34,44 +37,77 @@ public static function printServiceName($name, $loginURL = null)
3437 return "<a class='customLink' href=' " . htmlspecialchars ($ loginURL ) . "'> " . htmlspecialchars ($ name ) . "</a> " ;
3538 }
3639
37- public static function printAttributeValue ($ attribute , $ service , $ attr )
40+ public static function printAttributeValue ($ type , $ value )
3841 {
39- $ value = $ attribute ['value ' ];
40- if (empty ($ value ) && $ attribute ['type ' ] !== 'java.lang.Boolean ' ) {
42+ if (empty ($ value ) && $ type !== 'java.lang.Boolean ' ) {
4143 return "<td class='center'>―</td> " ;
4244 }
43- $ string = '' ;
44- if ($ attribute ['type ' ] === 'java.lang.String ' || $ attribute ['type ' ] === 'java.lang.LargeString ' ) {
45- if (filter_var ($ value , FILTER_VALIDATE_URL )) {
46- $ string = '<a class="customLink" href=" ' . $ value . '"> ' . $ value . '</a> ' ;
47- } else {
48- $ string = $ value ;
49- }
50- } elseif ($ attribute ['type ' ] === 'java.lang.Integer ' ) {
51- $ string = $ value ;
52- } elseif ($ attribute ['type ' ] === 'java.lang.Boolean ' ) {
53- if ($ value !== null && $ value ) {
54- $ string = '✔ ' ;
55- } else {
56- $ string = '✕ ' ;
57- }
58- } elseif ($ attribute ['type ' ] === 'java.util.ArrayList ' || $ attribute ['type ' ] === 'java.lang.LargeArrayList ' ) {
59- $ string = '<ul> ' ;
60- foreach ($ value as $ v ) {
61- $ string .= '<li> ' . $ v . '</li> ' ;
62- }
63- $ string .= '</ul> ' ;
64- } elseif ($ attribute ['type ' ] === 'java.util.LinkedHashMap ' ) {
65- $ string = '<ul> ' ;
66- foreach ($ value as $ k => $ v ) {
67- $ string .= '<li> ' . $ k . ' → ' . $ v . '</li> ' ;
68- }
69- $ string .= '</ul> ' ;
45+
46+ switch ($ type ) {
47+ case 'java.lang.String ' :
48+ case 'java.lang.LargeString ' :
49+ if (filter_var ($ value , FILTER_VALIDATE_URL )) {
50+ $ string = '<a class="customLink" href=" ' . htmlspecialchars ($ value ) . '"> '
51+ . htmlspecialchars ($ value ) . '</a> ' ;
52+ } else {
53+ $ string = htmlspecialchars ($ value );
54+ }
55+ break ;
56+ case 'java.lang.Integer ' :
57+ $ string = htmlspecialchars ($ value );
58+ break ;
59+ case 'java.lang.Boolean ' :
60+ if ($ value !== null && $ value ) {
61+ $ string = '✔ ' ;
62+ } else {
63+ $ string = '✕ ' ;
64+ }
65+ break ;
66+ case 'java.util.ArrayList ' :
67+ case 'java.lang.LargeArrayList ' :
68+ $ string = '<ul> ' ;
69+ foreach ($ value as $ v ) {
70+ $ string .= '<li> ' . htmlspecialchars ($ v ) . '</li> ' ;
71+ }
72+ $ string .= '</ul> ' ;
73+ break ;
74+ case 'java.util.LinkedHashMap ' :
75+ $ string = '<ul> ' ;
76+ foreach ($ value as $ k => $ v ) {
77+ $ string .= '<li> ' . htmlspecialchars ($ k ) . ' → ' . htmlspecialchars ($ v ) . '</li> ' ;
78+ }
79+ $ string .= '</ul> ' ;
80+ break ;
81+ default :
82+ $ string = '' ;
7083 }
7184 if (!empty ($ string )) {
72- return '<td class=" ' . self ::getClass ($ service [ ' facilityAttributes ' ][ $ attr ] ) . '"> ' . $ string . '</td> ' ;
85+ return '<td class=" ' . self ::getClass ($ type ) . '"> ' . $ string . '</td> ' ;
7386 } else {
7487 return '<td/> ' ;
7588 }
7689 }
90+
91+ public static function getPreferredTranslation ($ translations , $ language = 'en ' )
92+ {
93+ if (is_string ($ translations )) {
94+ return $ translations ;
95+ }
96+
97+ if (isset ($ translations [$ language ])) {
98+ return $ translations [$ language ];
99+ }
100+
101+ if (isset ($ translations ['en ' ])) {
102+ return $ translations ['en ' ];
103+ }
104+
105+ if (count ($ translations ) > 0 ) {
106+ $ languages = array_keys ($ translations );
107+ return $ translations [$ languages [0 ]];
108+ }
109+
110+ // we don't have anything to return
111+ throw new \Exception ('Nothing to return from translation. ' );
112+ }
77113}
0 commit comments