1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die();
10
11 12 13 14 15 16
17 class FOFConfigDomainViews implements FOFConfigDomainInterface
18 {
19 20 21 22 23 24 25 26
27 public function parseDomain(SimpleXMLElement $xml, array &$ret)
28 {
29
30 $ret['views'] = array();
31
32
33 $viewData = $xml->xpath('view');
34
35
36
37 if (empty($viewData))
38 {
39 return;
40 }
41
42 foreach ($viewData as $aView)
43 {
44 $key = (string) $aView['name'];
45
46
47 $ret['views'][$key]['acl'] = array();
48 $aclData = $aView->xpath('acl/task');
49
50 if (!empty($aclData))
51 {
52 foreach ($aclData as $acl)
53 {
54 $k = (string) $acl['name'];
55 $ret['views'][$key]['acl'][$k] = (string) $acl;
56 }
57 }
58
59
60 $ret['views'][$key]['taskmap'] = array();
61 $taskmapData = $aView->xpath('taskmap/task');
62
63 if (!empty($taskmapData))
64 {
65 foreach ($taskmapData as $map)
66 {
67 $k = (string) $map['name'];
68 $ret['views'][$key]['taskmap'][$k] = (string) $map;
69 }
70 }
71
72
73 $ret['views'][$key]['config'] = array();
74 $optionData = $aView->xpath('config/option');
75
76 if (!empty($optionData))
77 {
78 foreach ($optionData as $option)
79 {
80 $k = (string) $option['name'];
81 $ret['views'][$key]['config'][$k] = (string) $option;
82 }
83 }
84
85
86 $ret['views'][$key]['toolbar'] = array();
87 $toolBars = $aView->xpath('toolbar');
88
89 if (!empty($toolBars))
90 {
91 foreach ($toolBars as $toolBar)
92 {
93 $taskName = isset($toolBar['task']) ? (string) $toolBar['task'] : '*';
94
95
96 if (isset($toolBar['title']))
97 {
98 $ret['views'][$key]['toolbar'][$taskName]['title'] = array(
99 'value' => (string) $toolBar['title']
100 );
101 }
102
103
104 $toolbarData = $toolBar->xpath('button');
105
106 if (!empty($toolbarData))
107 {
108 foreach ($toolbarData as $button)
109 {
110 $k = (string) $button['type'];
111 $ret['views'][$key]['toolbar'][$taskName][$k] = current($button->attributes());
112 $ret['views'][$key]['toolbar'][$taskName][$k]['value'] = (string) $button;
113 }
114 }
115 }
116 }
117 }
118 }
119
120 121 122 123 124 125 126 127 128
129 public function get(&$configuration, $var, $default)
130 {
131 $parts = explode('.', $var);
132
133 $view = $parts[0];
134 $method = 'get' . ucfirst($parts[1]);
135
136 if (!method_exists($this, $method))
137 {
138 return $default;
139 }
140
141 array_shift($parts);
142 array_shift($parts);
143
144 $ret = $this->$method($view, $configuration, $parts, $default);
145
146 return $ret;
147 }
148
149 150 151 152 153 154 155 156 157 158
159 protected function getTaskmap($view, &$configuration, $params, $default = array())
160 {
161 $taskmap = array();
162
163 if (isset($configuration['views']['*']) && isset($configuration['views']['*']['taskmap']))
164 {
165 $taskmap = $configuration['views']['*']['taskmap'];
166 }
167
168 if (isset($configuration['views'][$view]) && isset($configuration['views'][$view]['taskmap']))
169 {
170 $taskmap = array_merge($taskmap, $configuration['views'][$view]['taskmap']);
171 }
172
173 if (empty($taskmap))
174 {
175 return $default;
176 }
177
178 return $taskmap;
179 }
180
181 182 183 184 185 186 187 188 189 190 191
192 protected function getAcl($view, &$configuration, $params, $default = '')
193 {
194 $aclmap = array();
195
196 if (isset($configuration['views']['*']) && isset($configuration['views']['*']['acl']))
197 {
198 $aclmap = $configuration['views']['*']['acl'];
199 }
200
201 if (isset($configuration['views'][$view]) && isset($configuration['views'][$view]['acl']))
202 {
203 $aclmap = array_merge($aclmap, $configuration['views'][$view]['acl']);
204 }
205
206 $acl = $default;
207
208 if (isset($aclmap['*']))
209 {
210 $acl = $aclmap['*'];
211 }
212
213 if (isset($aclmap[$params[0]]))
214 {
215 $acl = $aclmap[$params[0]];
216 }
217
218 return $acl;
219 }
220
221 222 223 224 225 226 227 228 229 230 231
232 protected function getConfig($view, &$configuration, $params, $default = null)
233 {
234 $ret = $default;
235
236 if (isset($configuration['views']['*'])
237 && isset($configuration['views']['*']['config'])
238 && isset($configuration['views']['*']['config'][$params[0]]))
239 {
240 $ret = $configuration['views']['*']['config'][$params[0]];
241 }
242
243 if (isset($configuration['views'][$view])
244 && isset($configuration['views'][$view]['config'])
245 && isset($configuration['views'][$view]['config'][$params[0]]))
246 {
247 $ret = $configuration['views'][$view]['config'][$params[0]];
248 }
249
250 return $ret;
251 }
252
253 254 255 256 257 258 259 260 261 262
263 protected function getToolbar($view, &$configuration, $params, $default = '')
264 {
265 $toolbar = array();
266
267 if (isset($configuration['views']['*'])
268 && isset($configuration['views']['*']['toolbar'])
269 && isset($configuration['views']['*']['toolbar']['*']))
270 {
271 $toolbar = $configuration['views']['*']['toolbar']['*'];
272 }
273
274 if (isset($configuration['views']['*'])
275 && isset($configuration['views']['*']['toolbar'])
276 && isset($configuration['views']['*']['toolbar'][$params[0]]))
277 {
278 $toolbar = array_merge($toolbar, $configuration['views']['*']['toolbar'][$params[0]]);
279 }
280
281 if (isset($configuration['views'][$view])
282 && isset($configuration['views'][$view]['toolbar'])
283 && isset($configuration['views'][$view]['toolbar']['*']))
284 {
285 $toolbar = array_merge($toolbar, $configuration['views'][$view]['toolbar']['*']);
286 }
287
288 if (isset($configuration['views'][$view])
289 && isset($configuration['views'][$view]['toolbar'])
290 && isset($configuration['views'][$view]['toolbar'][$params[0]]))
291 {
292 $toolbar = array_merge($toolbar, $configuration['views'][$view]['toolbar'][$params[0]]);
293 }
294
295 if (empty($toolbar))
296 {
297 return $default;
298 }
299
300 return $toolbar;
301 }
302 }
303