Conditions | 157 |
Total Lines | 978 |
Code Lines | 662 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
34 | public function __form() |
||
35 | { |
||
36 | $formHasErrors = (is_array($this->_errors) && !empty($this->_errors)); |
||
37 | |||
38 | if ($formHasErrors) { |
||
39 | $this->pageAlert( |
||
40 | __('An error occurred while processing this form. See below for details.'), |
||
41 | Alert::ERROR |
||
42 | ); |
||
43 | |||
44 | // These alerts are only valid if the form doesn't have errors |
||
45 | } elseif (isset($this->_context[2])) { |
||
46 | $time = Widget::Time(); |
||
47 | |||
48 | switch ($this->_context[2]) { |
||
49 | case 'saved': |
||
50 | $message = __('Data Source updated at %s.', array($time->generate())); |
||
51 | break; |
||
52 | case 'created': |
||
53 | $message = __('Data Source created at %s.', array($time->generate())); |
||
54 | } |
||
55 | |||
56 | $this->pageAlert( |
||
57 | $message |
||
58 | . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' |
||
59 | . __('Create another?') |
||
60 | . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' |
||
61 | . __('View all Data Sources') |
||
62 | . '</a>', |
||
63 | Alert::SUCCESS |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::DATASOURCE); |
||
68 | $canonical_link = null; |
||
69 | $isEditing = false; |
||
70 | $about = $handle = null; |
||
71 | $fields = array( |
||
72 | 'name' => null, |
||
73 | 'source' => null, |
||
74 | 'filter'=> null, |
||
75 | 'required_url_param' => null, |
||
76 | 'negate_url_param' => null, |
||
77 | 'param' => null, |
||
78 | ); |
||
79 | |||
80 | if (isset($_POST['fields'])) { |
||
81 | $fields = $_POST['fields']; |
||
82 | |||
83 | if ( |
||
84 | !in_array($fields['source'], array('authors', 'navigation', 'static_xml')) |
||
85 | && !empty($fields['filter']) && is_array($fields['filter']) |
||
86 | ) { |
||
87 | $filters = array(); |
||
88 | foreach ($fields['filter'] as $f) { |
||
89 | foreach ($f as $key => $val) { |
||
90 | $filters[$key] = $val; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | $fields['filter'][$fields['source']] = $filters; |
||
95 | } |
||
96 | |||
97 | if (!isset($fields['xml_elements']) || !is_array($fields['xml_elements'])) { |
||
98 | $fields['xml_elements'] = array(); |
||
99 | } |
||
100 | |||
101 | if ($this->_context[0] == 'edit') { |
||
102 | $isEditing = true; |
||
103 | } |
||
104 | } elseif ($this->_context[0] == 'edit') { |
||
105 | $isEditing = true; |
||
106 | $handle = $this->_context[1]; |
||
107 | $existing = DatasourceManager::create($handle, array(), false); |
||
108 | $order = isset($existing->dsParamORDER) ? stripslashes($existing->dsParamORDER) : 'asc'; |
||
109 | $canonical_link = '/blueprints/datasources/edit/' . $handle . '/'; |
||
110 | |||
111 | if (!$existing->allowEditorToParse()) { |
||
112 | redirect(SYMPHONY_URL . '/blueprints/datasources/info/' . $handle . '/'); |
||
113 | } |
||
114 | |||
115 | $about = General::array_map_recursive('stripslashes', $existing->about()); |
||
116 | $fields['name'] = $about['name']; |
||
117 | |||
118 | $fields['order'] = ($order == 'rand') ? 'random' : $order; |
||
119 | $fields['param'] = isset($existing->dsParamPARAMOUTPUT) ? array_map('stripslashes', $existing->dsParamPARAMOUTPUT) : null; |
||
120 | $fields['required_url_param'] = isset($existing->dsParamREQUIREDPARAM) ? stripslashes(trim($existing->dsParamREQUIREDPARAM)) : null; |
||
121 | $fields['negate_url_param'] = isset($existing->dsParamNEGATEPARAM) ? stripslashes(trim($existing->dsParamNEGATEPARAM)) : null; |
||
122 | |||
123 | if (isset($existing->dsParamINCLUDEDELEMENTS) && is_array($existing->dsParamINCLUDEDELEMENTS)) { |
||
124 | $fields['xml_elements'] = array_map('stripslashes', $existing->dsParamINCLUDEDELEMENTS); |
||
125 | } else { |
||
126 | $fields['xml_elements'] = array(); |
||
127 | } |
||
128 | |||
129 | $fields['sort'] = isset($existing->dsParamSORT) ? stripslashes($existing->dsParamSORT) : null; |
||
130 | $fields['paginate_results'] = isset($existing->dsParamPAGINATERESULTS) ? stripslashes($existing->dsParamPAGINATERESULTS) : 'yes'; |
||
131 | $fields['page_number'] = isset($existing->dsParamSTARTPAGE) ? stripslashes($existing->dsParamSTARTPAGE) : '1'; |
||
132 | $fields['group'] = isset($existing->dsParamGROUP) ? stripslashes($existing->dsParamGROUP) : null; |
||
133 | $fields['html_encode'] = isset($existing->dsParamHTMLENCODE) ? stripslashes($existing->dsParamHTMLENCODE) : 'no'; |
||
134 | $fields['associated_entry_counts'] = isset($existing->dsParamASSOCIATEDENTRYCOUNTS) ? stripslashes($existing->dsParamASSOCIATEDENTRYCOUNTS) : 'no'; |
||
135 | $fields['redirect_on_empty'] = isset($existing->dsParamREDIRECTONEMPTY) ? stripslashes($existing->dsParamREDIRECTONEMPTY) : 'no'; |
||
136 | $fields['redirect_on_forbidden'] = isset($existing->dsParamREDIRECTONFORBIDDEN) ? stripslashes($existing->dsParamREDIRECTONFORBIDDEN) : 'no'; |
||
137 | $fields['redirect_on_required'] = isset($existing->dsParamREDIRECTONREQUIRED) ? stripslashes($existing->dsParamREDIRECTONREQUIRED) : 'no'; |
||
138 | |||
139 | if (!isset($existing->dsParamFILTERS) || !is_array($existing->dsParamFILTERS)) { |
||
140 | $existing->dsParamFILTERS = array(); |
||
141 | } |
||
142 | |||
143 | if (!empty($existing->dsParamFILTERS)) { |
||
144 | $existing->dsParamFILTERS = array_map('stripslashes', $existing->dsParamFILTERS); |
||
145 | } |
||
146 | |||
147 | $fields['source'] = stripslashes($existing->getSource()); |
||
148 | |||
149 | $provided = false; |
||
150 | |||
151 | if (!empty($providers)) { |
||
152 | foreach ($providers as $providerClass => $provider) { |
||
153 | if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { |
||
154 | $fields = array_merge($fields, $existing->settings()); |
||
155 | $provided = true; |
||
156 | break; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | if ($provided === false) { |
||
162 | switch ($fields['source']) { |
||
163 | case 'authors': |
||
164 | $fields['filter']['author'] = $existing->dsParamFILTERS; |
||
165 | break; |
||
166 | case 'navigation': |
||
167 | $fields['filter']['navigation'] = $existing->dsParamFILTERS; |
||
168 | break; |
||
169 | case 'static_xml': |
||
170 | // Symphony 2.3+ |
||
171 | if (isset($existing->dsParamSTATIC)) { |
||
172 | $fields['static_xml'] = stripslashes(trim($existing->dsParamSTATIC)); |
||
173 | |||
174 | // Handle Symphony 2.2.2 to 2.3 DS's |
||
175 | // This is deprecated and will be removed in Symphony 3.0.0 |
||
176 | } elseif (isset($existing->dsSTATIC)) { |
||
177 | $fields['static_xml'] = stripslashes(trim($existing->dsSTATIC)); |
||
178 | |||
179 | // Handle pre Symphony 2.2.1 Static DS's |
||
180 | // This is deprecated and will be removed in Symphony 3.0.0 |
||
181 | } else { |
||
182 | $fields['static_xml'] = trim($existing->grab()); |
||
183 | } |
||
184 | break; |
||
185 | default: |
||
186 | $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; |
||
187 | $fields['max_records'] = stripslashes($existing->dsParamLIMIT); |
||
188 | break; |
||
189 | } |
||
190 | } |
||
191 | } else { |
||
192 | $fields['max_records'] = '20'; |
||
193 | $fields['page_number'] = '1'; |
||
194 | $fields['order'] = 'desc'; |
||
195 | } |
||
196 | |||
197 | $name = null; |
||
198 | // Handle name on edited changes, or from reading an edited datasource |
||
199 | if (isset($about['name'])) { |
||
200 | $name = $about['name']; |
||
201 | } elseif (isset($fields['name'])) { |
||
202 | $name = $fields['name']; |
||
203 | } |
||
204 | |||
205 | $this->setPageType('form'); |
||
206 | $this->setTitle(__(($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s'), array($name, __('Data Sources'), __('Symphony')))); |
||
207 | if ($canonical_link) { |
||
208 | $this->addElementToHead(new XMLElement('link', null, array( |
||
209 | 'rel' => 'canonical', |
||
210 | 'href' => SYMPHONY_URL . $canonical_link, |
||
211 | ))); |
||
212 | } |
||
213 | $this->appendSubheading(($isEditing ? $name : __('Untitled'))); |
||
214 | $this->insertBreadcrumbs(array( |
||
215 | Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/'), |
||
216 | )); |
||
217 | |||
218 | // Sources |
||
219 | $sources = new XMLElement('div', null, array('class' => 'apply actions')); |
||
220 | $div = new XMLElement('div'); |
||
221 | $label = Widget::Label(__('Source'), null, 'apply-label-left'); |
||
222 | $sources->appendChild($label); |
||
223 | $sources->appendChild($div); |
||
224 | |||
225 | $sections = SectionManager::fetch(null, 'ASC', 'name'); |
||
226 | |||
227 | if (!is_array($sections)) { |
||
228 | $sections = array(); |
||
229 | } |
||
230 | |||
231 | $field_groups = array(); |
||
232 | |||
233 | foreach ($sections as $section) { |
||
234 | $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); |
||
235 | } |
||
236 | |||
237 | $options = array( |
||
238 | array('label' => __('System'), 'data-label' => 'system', 'options' => array( |
||
239 | array('authors', ($fields['source'] == 'authors'), __('Authors'), null, null, array('data-context' => 'authors')), |
||
240 | array('navigation', ($fields['source'] == 'navigation'), __('Navigation'), null, null, array('data-context' => 'navigation')), |
||
241 | )), |
||
242 | array('label' => __('Custom XML'), 'data-label' => 'custom-xml', 'options' => array( |
||
243 | array('static_xml', ($fields['source'] == 'static_xml'), __('Static XML'), null, null, array('data-context' => 'static-xml')), |
||
244 | )), |
||
245 | ); |
||
246 | |||
247 | // Loop over the datasource providers |
||
248 | if (!empty($providers)) { |
||
249 | $p = array('label' => __('From extensions'), 'data-label' => 'from_extensions', 'options' => array()); |
||
250 | |||
251 | foreach ($providers as $providerClass => $provider) { |
||
252 | $p['options'][] = array( |
||
253 | $providerClass, ($fields['source'] == $providerClass), $provider, null, null, array('data-context' => Lang::createHandle($provider)) |
||
254 | ); |
||
255 | } |
||
256 | |||
257 | $options[] = $p; |
||
258 | } |
||
259 | |||
260 | // Add Sections |
||
261 | if (is_array($sections) && !empty($sections)) { |
||
262 | array_unshift($options, array('label' => __('Sections'), 'data-label' => 'sections', 'options' => array())); |
||
263 | |||
264 | foreach ($sections as $s) { |
||
265 | $options[0]['options'][] = array($s->get('id'), ($fields['source'] == $s->get('id')), General::sanitize($s->get('name'))); |
||
266 | } |
||
267 | } |
||
268 | |||
269 | $div->appendChild(Widget::Select('source', $options, array('id' => 'ds-context'))); |
||
270 | $this->Context->prependChild($sources); |
||
271 | |||
272 | $this->Form->appendChild( |
||
273 | Widget::Input('fields[source]', null, 'hidden', array('id' => 'ds-source')) |
||
274 | ); |
||
275 | |||
276 | // Name |
||
277 | $fieldset = new XMLElement('fieldset'); |
||
278 | $fieldset->setAttribute('class', 'settings'); |
||
279 | $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); |
||
280 | |||
281 | $group = new XMLElement('div'); |
||
282 | |||
283 | $label = Widget::Label(__('Name')); |
||
284 | $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); |
||
285 | |||
286 | if (isset($this->_errors['name'])) { |
||
287 | $group->appendChild(Widget::Error($label, $this->_errors['name'])); |
||
288 | } else { |
||
289 | $group->appendChild($label); |
||
290 | } |
||
291 | |||
292 | $fieldset->appendChild($group); |
||
293 | $this->Form->appendChild($fieldset); |
||
294 | |||
295 | // Conditions |
||
296 | $fieldset = new XMLElement('fieldset'); |
||
297 | $this->setContext($fieldset, array('sections', 'system')); |
||
298 | $fieldset->appendChild(new XMLElement('legend', __('Execution Conditions'))); |
||
299 | $p = new XMLElement('p', __('Leaving these fields empty will always execute the data source.')); |
||
300 | $p->setAttribute('class', 'help'); |
||
301 | $fieldset->appendChild($p); |
||
302 | |||
303 | $group = new XMLElement('div'); |
||
304 | $group->setAttribute('class', 'two columns'); |
||
305 | |||
306 | $label = Widget::Label(__('Required Parameter')); |
||
307 | $label->setAttribute('class', 'column ds-param'); |
||
308 | $label->appendChild(new XMLElement('i', __('Optional'))); |
||
309 | $input = Widget::Input('fields[required_url_param]', General::sanitize(trim($fields['required_url_param'])), 'text', array( |
||
310 | 'placeholder' => __('$param'), |
||
311 | 'data-search-types' => 'parameters', |
||
312 | 'data-trigger' => '$' |
||
313 | )); |
||
314 | $label->appendChild($input); |
||
315 | $group->appendChild($label); |
||
316 | |||
317 | $label = Widget::Label(__('Forbidden Parameter')); |
||
318 | $label->setAttribute('class', 'column ds-param'); |
||
319 | $label->appendChild(new XMLElement('i', __('Optional'))); |
||
320 | $input = Widget::Input('fields[negate_url_param]', General::sanitize(trim($fields['negate_url_param'])), 'text', array( |
||
321 | 'placeholder' => __('$param'), |
||
322 | 'data-search-types' => 'parameters', |
||
323 | 'data-trigger' => '$' |
||
324 | )); |
||
325 | $label->appendChild($input); |
||
326 | $group->appendChild($label); |
||
327 | |||
328 | $fieldset->appendChild($group); |
||
329 | |||
330 | $this->Form->appendChild($fieldset); |
||
331 | |||
332 | $fieldset = new XMLElement('fieldset'); |
||
333 | $this->setContext($fieldset, array('sections', 'system')); |
||
334 | $fieldset->appendChild(new XMLElement('legend', __('Error Conditions'))); |
||
335 | $p = new XMLElement('p', __('Meeting one of these conditions will cause a <code>404 Not Found</code> response.')); |
||
336 | $p->setAttribute('class', 'help'); |
||
337 | $fieldset->appendChild($p); |
||
338 | $group = new XMLElement('div'); |
||
339 | |||
340 | $label = Widget::Checkbox('fields[redirect_on_required]', isset($fields['redirect_on_required']) ? $fields['redirect_on_required'] : null, __('The required parameter is missing')); |
||
341 | $group->appendChild($label); |
||
342 | |||
343 | $label = Widget::Checkbox('fields[redirect_on_forbidden]', isset($fields['redirect_on_forbidden']) ? $fields['redirect_on_forbidden'] : null, __('The forbidden parameter is present')); |
||
344 | $group->appendChild($label); |
||
345 | |||
346 | $label = Widget::Checkbox('fields[redirect_on_empty]', isset($fields['redirect_on_empty']) ? $fields['redirect_on_empty'] : null, __('No results are found')); |
||
347 | $group->appendChild($label); |
||
348 | |||
349 | $fieldset->appendChild($group); |
||
350 | |||
351 | $this->Form->appendChild($fieldset); |
||
352 | |||
353 | // Filters |
||
354 | $fieldset = new XMLElement('fieldset'); |
||
355 | $this->setContext($fieldset, array('sections', 'system')); |
||
356 | $fieldset->appendChild(new XMLElement('legend', __('Filters'))); |
||
357 | $p = new XMLElement('p', |
||
358 | __('Use %s syntax to filter by page parameters. A default value can be set using %s.', array( |
||
359 | '<code>{' . __('$param') . '}</code>', |
||
360 | '<code>{' . __('$param:default') . '}</code>' |
||
361 | )) |
||
362 | ); |
||
363 | $p->setAttribute('class', 'help'); |
||
364 | $fieldset->appendChild($p); |
||
365 | |||
366 | foreach ($field_groups as $section_id => $section_data) { |
||
367 | $div = new XMLElement('div'); |
||
368 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
369 | $div->setAttribute('data-context', 'section-' . $section_id); |
||
370 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
371 | |||
372 | $ol = new XMLElement('ol'); |
||
373 | $ol->setAttribute('class', 'suggestable'); |
||
374 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
375 | $ol->setAttribute('data-add', __('Add filter')); |
||
376 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
377 | |||
378 | // Add system:id filter |
||
379 | if ( |
||
380 | isset($fields['filter'][$section_id]['system:id']) |
||
381 | || isset($fields['filter'][$section_id]['id']) |
||
382 | ) { |
||
383 | $id = isset($fields['filter'][$section_id]['system:id']) |
||
384 | ? $fields['filter'][$section_id]['system:id'] |
||
385 | : $fields['filter'][$section_id]['id']; |
||
386 | |||
387 | $li = new XMLElement('li'); |
||
388 | $li->setAttribute('class', 'unique'); |
||
389 | $li->setAttribute('data-type', 'system:id'); |
||
390 | $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); |
||
391 | $label = Widget::Label(__('Value')); |
||
392 | $input = Widget::Input('fields[filter]['.$section_id.'][system:id]', General::sanitize($id)); |
||
393 | $input->setAttribute('data-search-types', 'parameters'); |
||
394 | $input->setAttribute('data-trigger', '{$'); |
||
395 | $label->appendChild($input); |
||
396 | $li->appendChild($label); |
||
397 | $ol->appendChild($li); |
||
398 | } |
||
399 | |||
400 | $li = new XMLElement('li'); |
||
401 | $li->setAttribute('class', 'unique template'); |
||
402 | $li->setAttribute('data-type', 'system:id'); |
||
403 | $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); |
||
404 | $label = Widget::Label(__('Value')); |
||
405 | $input = Widget::Input('fields[filter]['.$section_id.'][system:id]'); |
||
406 | $input->setAttribute('data-search-types', 'parameters'); |
||
407 | $input->setAttribute('data-trigger', '{$'); |
||
408 | $label->appendChild($input); |
||
409 | $li->appendChild($label); |
||
410 | $ol->appendChild($li); |
||
411 | |||
412 | // Add system:date filter |
||
413 | if ( |
||
414 | isset($fields['filter'][$section_id]['system:creation-date']) |
||
415 | || isset($fields['filter'][$section_id]['system:date']) |
||
416 | ) { |
||
417 | $creation_date = isset($fields['filter'][$section_id]['system:creation-date']) |
||
418 | ? $fields['filter'][$section_id]['system:creation-date'] |
||
419 | : $fields['filter'][$section_id]['system:date']; |
||
420 | |||
421 | $li = new XMLElement('li'); |
||
422 | $li->setAttribute('class', 'unique'); |
||
423 | $li->setAttribute('data-type', 'system:creation-date'); |
||
424 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); |
||
425 | $label = Widget::Label(__('Value')); |
||
426 | $input = Widget::Input('fields[filter]['.$section_id.'][system:creation-date]', General::sanitize($creation_date)); |
||
427 | $input->setAttribute('data-search-types', 'parameters'); |
||
428 | $input->setAttribute('data-trigger', '{$'); |
||
429 | $label->appendChild($input); |
||
430 | $li->appendChild($label); |
||
431 | $ol->appendChild($li); |
||
432 | } |
||
433 | |||
434 | $li = new XMLElement('li'); |
||
435 | $li->setAttribute('class', 'unique template'); |
||
436 | $li->setAttribute('data-type', 'system:creation-date'); |
||
437 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); |
||
438 | $label = Widget::Label(__('Value')); |
||
439 | $input = Widget::Input('fields[filter]['.$section_id.'][system:creation-date]'); |
||
440 | $input->setAttribute('data-search-types', 'parameters'); |
||
441 | $input->setAttribute('data-trigger', '{$'); |
||
442 | $label->appendChild($input); |
||
443 | $li->appendChild($label); |
||
444 | $ol->appendChild($li); |
||
445 | |||
446 | if (isset($fields['filter'][$section_id]['system:modification-date'])) { |
||
447 | $li = new XMLElement('li'); |
||
448 | $li->setAttribute('class', 'unique'); |
||
449 | $li->setAttribute('data-type', 'system:modification-date'); |
||
450 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); |
||
451 | $label = Widget::Label(__('Value')); |
||
452 | $input = Widget::Input('fields[filter]['.$section_id.'][system:modification-date]', General::sanitize($fields['filter'][$section_id]['system:modification-date'])); |
||
453 | $input->setAttribute('data-search-types', 'parameters'); |
||
454 | $input->setAttribute('data-trigger', '{$'); |
||
455 | $label->appendChild($input); |
||
456 | $li->appendChild($label); |
||
457 | $ol->appendChild($li); |
||
458 | } |
||
459 | |||
460 | $li = new XMLElement('li'); |
||
461 | $li->setAttribute('class', 'unique template'); |
||
462 | $li->setAttribute('data-type', 'system:modification-date'); |
||
463 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); |
||
464 | $label = Widget::Label(__('Value')); |
||
465 | $input = Widget::Input('fields[filter]['.$section_id.'][system:modification-date]'); |
||
466 | $input->setAttribute('data-search-types', 'parameters'); |
||
467 | $input->setAttribute('data-trigger', '{$'); |
||
468 | $label->appendChild($input); |
||
469 | $li->appendChild($label); |
||
470 | $ol->appendChild($li); |
||
471 | |||
472 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
473 | foreach ($section_data['fields'] as $field) { |
||
474 | if (!$field->canFilter()) { |
||
475 | continue; |
||
476 | } |
||
477 | |||
478 | if (isset($fields['filter'][$section_id], $fields['filter'][$section_id][$field->get('id')])) { |
||
479 | $wrapper = new XMLElement('li'); |
||
480 | $wrapper->setAttribute('class', 'unique'); |
||
481 | $wrapper->setAttribute('data-type', $field->get('element_name')); |
||
482 | $errors = isset($this->_errors[$field->get('id')]) |
||
483 | ? $this->_errors[$field->get('id')] |
||
484 | : array(); |
||
485 | |||
486 | $field->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_id][$field->get('id')], $errors, $section_id); |
||
487 | $ol->appendChild($wrapper); |
||
488 | } |
||
489 | |||
490 | $wrapper = new XMLElement('li'); |
||
491 | $wrapper->setAttribute('class', 'unique template'); |
||
492 | $wrapper->setAttribute('data-type', $field->get('element_name')); |
||
493 | $field->displayDatasourceFilterPanel($wrapper, null, null, $section_id); |
||
494 | $ol->appendChild($wrapper); |
||
495 | } |
||
496 | } |
||
497 | |||
498 | $div->appendChild($ol); |
||
499 | |||
500 | $fieldset->appendChild($div); |
||
501 | } |
||
502 | |||
503 | $div = new XMLElement('div'); |
||
504 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
505 | $div->setAttribute('data-context', 'authors'); |
||
506 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
507 | |||
508 | $ol = new XMLElement('ol'); |
||
509 | $ol->setAttribute('class', 'suggestable'); |
||
510 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
511 | $ol->setAttribute('data-add', __('Add filter')); |
||
512 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
513 | |||
514 | $this->__appendAuthorFilter($ol, __('ID'), 'id', isset($fields['filter']['author']['id']) ? $fields['filter']['author']['id'] : null, !isset($fields['filter']['author']['id'])); |
||
515 | $this->__appendAuthorFilter($ol, __('Username'), 'username', isset($fields['filter']['author']['username']) ? $fields['filter']['author']['username'] : null, !isset($fields['filter']['author']['username'])); |
||
516 | $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', isset($fields['filter']['author']['first_name']) ? $fields['filter']['author']['first_name'] : null, !isset($fields['filter']['author']['first_name'])); |
||
517 | $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', isset($fields['filter']['author']['last_name']) ? $fields['filter']['author']['last_name'] : null, !isset($fields['filter']['author']['last_name'])); |
||
518 | $this->__appendAuthorFilter($ol, __('Email'), 'email', isset($fields['filter']['author']['email']) ? $fields['filter']['author']['email'] : null, !isset($fields['filter']['author']['email'])); |
||
519 | $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', isset($fields['filter']['author']['user_type']) ? $fields['filter']['author']['user_type'] : null, !isset($fields['filter']['author']['user_type'])); |
||
520 | |||
521 | $div->appendChild($ol); |
||
522 | |||
523 | $fieldset->appendChild($div); |
||
524 | |||
525 | $div = new XMLElement('div'); |
||
526 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
527 | $div->setAttribute('data-context', 'navigation'); |
||
528 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
529 | |||
530 | $ol = new XMLElement('ol'); |
||
531 | $ol->setAttribute('class', 'suggestable'); |
||
532 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
533 | $ol->setAttribute('data-add', __('Add filter')); |
||
534 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
535 | |||
536 | $ul = new XMLElement('ul'); |
||
537 | $ul->setAttribute('class', 'tags'); |
||
538 | $ul->setAttribute('data-interactive', 'data-interactive'); |
||
539 | |||
540 | $pages = PageManager::fetch(false, array('*'), array(), 'title ASC'); |
||
541 | |||
542 | foreach ($pages as $page) { |
||
543 | $ul->appendChild(new XMLElement('li', preg_replace('/\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); |
||
544 | } |
||
545 | |||
546 | if (isset($fields['filter']['navigation']['parent'])) { |
||
547 | $li = new XMLElement('li'); |
||
548 | $li->setAttribute('class', 'unique'); |
||
549 | $li->setAttribute('data-type', 'parent'); |
||
550 | $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); |
||
551 | $label = Widget::Label(__('Value')); |
||
552 | $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); |
||
553 | $li->appendChild($label); |
||
554 | $li->appendChild($ul); |
||
555 | $ol->appendChild($li); |
||
556 | } |
||
557 | |||
558 | $li = new XMLElement('li'); |
||
559 | $li->setAttribute('class', 'unique template'); |
||
560 | $li->setAttribute('data-type', 'parent'); |
||
561 | $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); |
||
562 | $label = Widget::Label(__('Value')); |
||
563 | $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); |
||
564 | $li->appendChild($label); |
||
565 | $li->appendChild($ul); |
||
566 | $ol->appendChild($li); |
||
567 | |||
568 | $ul = new XMLElement('ul'); |
||
569 | $ul->setAttribute('class', 'tags'); |
||
570 | $ul->setAttribute('data-interactive', 'data-interactive'); |
||
571 | |||
572 | if ($types = PageManager::fetchAvailablePageTypes()) { |
||
573 | foreach ($types as $type) { |
||
574 | $ul->appendChild(new XMLElement('li', General::sanitize($type))); |
||
575 | } |
||
576 | } |
||
577 | |||
578 | if (isset($fields['filter']['navigation']['type'])) { |
||
579 | $li = new XMLElement('li'); |
||
580 | $li->setAttribute('class', 'unique'); |
||
581 | $li->setAttribute('data-type', 'type'); |
||
582 | $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); |
||
583 | $label = Widget::Label(__('Value')); |
||
584 | $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); |
||
585 | $li->appendChild($label); |
||
586 | $li->appendChild($ul); |
||
587 | $ol->appendChild($li); |
||
588 | } |
||
589 | |||
590 | $li = new XMLElement('li'); |
||
591 | $li->setAttribute('class', 'unique template'); |
||
592 | $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); |
||
593 | $li->setAttribute('data-type', 'type'); |
||
594 | $label = Widget::Label(__('Value')); |
||
595 | $label->appendChild(Widget::Input('fields[filter][navigation][type]')); |
||
596 | $li->appendChild($label); |
||
597 | $li->appendChild($ul); |
||
598 | $ol->appendChild($li); |
||
599 | |||
600 | $div->appendChild($ol); |
||
601 | |||
602 | $fieldset->appendChild($div); |
||
603 | $this->Form->appendChild($fieldset); |
||
604 | |||
605 | // Sorting |
||
606 | $fieldset = new XMLElement('fieldset'); |
||
607 | $this->setContext($fieldset, array('sections', 'system')); |
||
608 | $fieldset->appendChild(new XMLElement('legend', __('Sorting'))); |
||
609 | |||
610 | $p = new XMLElement('p', |
||
611 | __('Use %s syntax to order by page parameters.', array( |
||
612 | '<code>{' . __('$param') . '}</code>' |
||
613 | )) |
||
614 | ); |
||
615 | $p->setAttribute('class', 'help'); |
||
616 | $fieldset->appendChild($p); |
||
617 | |||
618 | $div = new XMLElement('div'); |
||
619 | |||
620 | $label = Widget::Label(__('Sort By')); |
||
621 | |||
622 | $options = array( |
||
623 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array( |
||
624 | array('id', ($fields['source'] == 'authors' && $fields['sort'] == 'id'), __('Author ID')), |
||
625 | array('username', ($fields['source'] == 'authors' && $fields['sort'] == 'username'), __('Username')), |
||
626 | array('first-name', ($fields['source'] == 'authors' && $fields['sort'] == 'first-name'), __('First Name')), |
||
627 | array('last-name', ($fields['source'] == 'authors' && $fields['sort'] == 'last-name'), __('Last Name')), |
||
628 | array('email', ($fields['source'] == 'authors' && $fields['sort'] == 'email'), __('Email')), |
||
629 | array('status', ($fields['source'] == 'authors' && $fields['sort'] == 'status'), __('Status')), |
||
630 | ) |
||
631 | ), |
||
632 | |||
633 | array('label' => __('Navigation'), 'data-label' => 'navigation', 'options' => array( |
||
634 | array('id', ($fields['source'] == 'navigation' && $fields['sort'] == 'id'), __('Page ID')), |
||
635 | array('handle', ($fields['source'] == 'navigation' && $fields['sort'] == 'handle'), __('Handle')), |
||
636 | array('sortorder', ($fields['source'] == 'navigation' && $fields['sort'] == 'sortorder'), __('Sort Order')), |
||
637 | ) |
||
638 | ), |
||
639 | ); |
||
640 | |||
641 | foreach ($field_groups as $section_id => $section_data) { |
||
642 | $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array( |
||
643 | array('system:id', ($fields['source'] == $section_id && $fields['sort'] == 'system:id'), __('System ID')), |
||
644 | array('system:creation-date', ($fields['source'] == $section_id && ($fields['sort'] == 'system:creation-date' || $fields['sort'] == 'system:date')), __('System Creation Date')), |
||
645 | array('system:modification-date', ($fields['source'] == $section_id && $fields['sort'] == 'system:modification-date'), __('System Modification Date')), |
||
646 | )); |
||
647 | |||
648 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
649 | foreach ($section_data['fields'] as $input) { |
||
650 | if (!$input->isSortable()) { |
||
651 | continue; |
||
652 | } |
||
653 | |||
654 | $optgroup['options'][] = array( |
||
655 | $input->get('element_name'), |
||
656 | ($fields['source'] == $section_id && $input->get('element_name') == $fields['sort']), |
||
657 | $input->get('label') |
||
658 | ); |
||
659 | } |
||
660 | } |
||
661 | |||
662 | $options[] = $optgroup; |
||
663 | } |
||
664 | |||
665 | $label->appendChild(Widget::Select('fields[sort]', $options)); |
||
666 | $div->appendChild($label); |
||
667 | |||
668 | $label = Widget::Label(__('Sort Order')); |
||
669 | $label->setAttribute('class', 'ds-param'); |
||
670 | |||
671 | $input = Widget::Input('fields[order]', General::sanitize(trim($fields['order'])), 'text', array( |
||
672 | 'placeholder' => __('{$param}'), |
||
673 | 'data-search-types' => 'parameters', |
||
674 | 'data-trigger' => '{$' |
||
675 | )); |
||
676 | $label->appendChild($input); |
||
677 | $div->appendChild($label); |
||
678 | |||
679 | $orders = new XMLElement('ul'); |
||
680 | $orders->setAttribute('class', 'tags singular'); |
||
681 | $orders->setAttribute('data-interactive', 'data-interactive'); |
||
682 | $orders->appendChild(new XMLElement('li', 'asc')); |
||
683 | $orders->appendChild(new XMLElement('li', 'desc')); |
||
684 | $orders->appendChild(new XMLElement('li', 'random')); |
||
685 | $div->appendChild($orders); |
||
686 | |||
687 | $fieldset->appendChild($div); |
||
688 | $this->Form->appendChild($fieldset); |
||
689 | |||
690 | // Grouping |
||
691 | $fieldset = new XMLElement('fieldset'); |
||
692 | $this->setContext($fieldset, array('sections', 'authors')); |
||
693 | $fieldset->appendChild(new XMLElement('legend', __('Grouping'))); |
||
694 | |||
695 | $label = Widget::Label(__('Group By')); |
||
696 | $options = array( |
||
697 | array('', null, __('None')), |
||
698 | ); |
||
699 | |||
700 | foreach ($field_groups as $section_id => $section_data) { |
||
701 | $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); |
||
702 | |||
703 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
704 | foreach ($section_data['fields'] as $input) { |
||
705 | if (!$input->allowDatasourceOutputGrouping()) { |
||
706 | continue; |
||
707 | } |
||
708 | |||
709 | $optgroup['options'][] = array($input->get('id'), ($fields['source'] == $section_id && $fields['group'] == $input->get('id')), $input->get('label')); |
||
710 | } |
||
711 | } |
||
712 | |||
713 | $options[] = $optgroup; |
||
714 | } |
||
715 | |||
716 | $label->appendChild(Widget::Select('fields[group]', $options)); |
||
717 | $fieldset->appendChild($label); |
||
718 | |||
719 | $this->Form->appendChild($fieldset); |
||
720 | |||
721 | // Pagination |
||
722 | $fieldset = new XMLElement('fieldset'); |
||
723 | $this->setContext($fieldset, array('sections')); |
||
724 | $fieldset->appendChild(new XMLElement('legend', __('Pagination'))); |
||
725 | |||
726 | $p = new XMLElement('p', |
||
727 | __('Use %s syntax to limit by page parameters.', array( |
||
728 | '<code>{' . __('$param') . '}</code>' |
||
729 | )) |
||
730 | ); |
||
731 | $p->setAttribute('class', 'help'); |
||
732 | $fieldset->appendChild($p); |
||
733 | |||
734 | $group = new XMLElement('div'); |
||
735 | $group->setAttribute('class', 'two columns pagination'); |
||
736 | |||
737 | $label = Widget::Label(__('Entries per Page')); |
||
738 | $label->setAttribute('class', 'column ds-param'); |
||
739 | $input = Widget::Input('fields[max_records]', isset($fields['max_records']) ? General::sanitize(trim($fields['max_records'])) : '10', 'text', array( |
||
740 | 'placeholder' => __('{$param}'), |
||
741 | 'data-search-types' => 'parameters', |
||
742 | 'data-trigger' => '{$' |
||
743 | )); |
||
744 | $label->appendChild($input); |
||
745 | if (isset($this->_errors['max_records'])) { |
||
746 | $group->appendChild(Widget::Error($label, $this->_errors['max_records'])); |
||
747 | } else { |
||
748 | $group->appendChild($label); |
||
749 | } |
||
750 | |||
751 | $label = Widget::Label(__('Page Number')); |
||
752 | $label->setAttribute('class', 'column ds-param'); |
||
753 | $input = Widget::Input('fields[page_number]', General::sanitize(trim($fields['page_number'])), 'text', array( |
||
754 | 'placeholder' => __('{$param}'), |
||
755 | 'data-search-types' => 'parameters', |
||
756 | 'data-trigger' => '{$' |
||
757 | )); |
||
758 | $label->appendChild($input); |
||
759 | if (isset($this->_errors['page_number'])) { |
||
760 | $group->appendChild(Widget::Error($label, $this->_errors['page_number'])); |
||
761 | } else { |
||
762 | $group->appendChild($label); |
||
763 | } |
||
764 | |||
765 | $fieldset->appendChild($group); |
||
766 | |||
767 | $label = Widget::Checkbox('fields[paginate_results]', isset($fields['paginate_results']) ? $fields['paginate_results'] : null, __('Enable pagination')); |
||
768 | $fieldset->appendChild($label); |
||
769 | $this->Form->appendChild($fieldset); |
||
770 | |||
771 | // Content |
||
772 | $fieldset = new XMLElement('fieldset'); |
||
773 | $this->setContext($fieldset, array('sections', 'authors')); |
||
774 | $fieldset->appendChild(new XMLElement('legend', __('Content'))); |
||
775 | |||
776 | // XML |
||
777 | $group = new XMLElement('div', null, array('class' => 'two columns')); |
||
778 | |||
779 | $label = Widget::Label(__('Included Elements')); |
||
780 | $label->setAttribute('class', 'column'); |
||
781 | |||
782 | $options = array( |
||
783 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array( |
||
784 | array('username', ($fields['source'] == 'authors' && in_array('username', $fields['xml_elements'])), 'username'), |
||
785 | array('name', ($fields['source'] == 'authors' && in_array('name', $fields['xml_elements'])), 'name'), |
||
786 | array('email', ($fields['source'] == 'authors' && in_array('email', $fields['xml_elements'])), 'email'), |
||
787 | array('author-token', ($fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements'])), 'author-token'), |
||
788 | array('default-area', ($fields['source'] == 'authors' && in_array('default-area', $fields['xml_elements'])), 'default-area'), |
||
789 | )), |
||
790 | ); |
||
791 | |||
792 | foreach ($field_groups as $section_id => $section_data) { |
||
793 | $optgroup = array( |
||
794 | 'label' => General::sanitize($section_data['section']->get('name')), |
||
795 | 'data-label' => 'section-' . $section_data['section']->get('id'), |
||
796 | 'options' => array( |
||
797 | array( |
||
798 | 'system:pagination', |
||
799 | ($fields['source'] == $section_id && in_array('system:pagination', $fields['xml_elements'])), |
||
800 | 'system: pagination' |
||
801 | ), |
||
802 | array( |
||
803 | 'system:date', |
||
804 | ($fields['source'] == $section_id && in_array('system:date', $fields['xml_elements'])), |
||
805 | 'system: date' |
||
806 | ) |
||
807 | ) |
||
808 | ); |
||
809 | |||
810 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
811 | foreach ($section_data['fields'] as $field) { |
||
812 | $elements = $field->fetchIncludableElements(); |
||
813 | |||
814 | if (is_array($elements) && !empty($elements)) { |
||
815 | foreach ($elements as $name) { |
||
816 | $selected = false; |
||
817 | |||
818 | if ($fields['source'] == $section_id && in_array($name, $fields['xml_elements'])) { |
||
819 | $selected = true; |
||
820 | } |
||
821 | |||
822 | $optgroup['options'][] = array($name, $selected, $name); |
||
823 | } |
||
824 | } |
||
825 | } |
||
826 | } |
||
827 | |||
828 | $options[] = $optgroup; |
||
829 | } |
||
830 | |||
831 | $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple'))); |
||
832 | $group->appendChild($label); |
||
833 | |||
834 | // Support multiple parameters |
||
835 | if (!isset($fields['param'])) { |
||
836 | $fields['param'] = array(); |
||
837 | } elseif (!is_array($fields['param'])) { |
||
838 | $fields['param'] = array($fields['param']); |
||
839 | } |
||
840 | |||
841 | $label = Widget::Label(__('Parameters')); |
||
842 | $label->setAttribute('class', 'column'); |
||
843 | $prefix = '$ds-' . (isset($this->_context[1]) ? Lang::createHandle($fields['name']) : __('untitled')) . '.'; |
||
844 | |||
845 | $options = array( |
||
846 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array()) |
||
847 | ); |
||
848 | |||
849 | foreach (array('id', 'username', 'name', 'email', 'user_type') as $p) { |
||
850 | $options[0]['options'][] = array( |
||
851 | $p, |
||
852 | ($fields['source'] == 'authors' && in_array($p, $fields['param'])), |
||
853 | $prefix . $p, |
||
854 | null, |
||
855 | null, |
||
856 | array( |
||
857 | 'data-handle' => $p |
||
858 | ) |
||
859 | ); |
||
860 | } |
||
861 | |||
862 | foreach ($field_groups as $section_id => $section_data) { |
||
863 | $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); |
||
864 | |||
865 | foreach (array('id', 'creation-date', 'modification-date', 'author') as $p) { |
||
866 | $option = array( |
||
867 | 'system:' . $p, |
||
868 | ($fields['source'] == $section_id && in_array('system:' . $p, $fields['param'])), |
||
869 | $prefix . 'system-' . $p, |
||
870 | null, |
||
871 | null, |
||
872 | array( |
||
873 | 'data-handle' => 'system-' . $p |
||
874 | ) |
||
875 | ); |
||
876 | |||
877 | // Handle 'system:date' as an output paramater (backwards compatibility) |
||
878 | if ($p === 'creation-date') { |
||
879 | if ($fields['source'] == $section_id && in_array('system:date', $fields['param'])) { |
||
880 | $option[1] = true; |
||
881 | } |
||
882 | } |
||
883 | |||
884 | $optgroup['options'][] = $option; |
||
885 | } |
||
886 | |||
887 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
888 | foreach ($section_data['fields'] as $input) { |
||
889 | if (!$input->allowDatasourceParamOutput()) { |
||
890 | continue; |
||
891 | } |
||
892 | |||
893 | $optgroup['options'][] = array( |
||
894 | $input->get('element_name'), |
||
895 | ($fields['source'] == $section_id && in_array($input->get('element_name'), $fields['param'])), |
||
896 | $prefix . $input->get('element_name'), |
||
897 | null, |
||
898 | null, |
||
899 | array( |
||
900 | 'data-handle' => $input->get('element_name') |
||
901 | ) |
||
902 | ); |
||
903 | } |
||
904 | } |
||
905 | |||
906 | $options[] = $optgroup; |
||
907 | } |
||
908 | |||
909 | $label->appendChild(Widget::Select('fields[param][]', $options, array('multiple' => 'multiple'))); |
||
910 | $group->appendChild($label); |
||
911 | |||
912 | $fieldset->appendChild($group); |
||
913 | |||
914 | // Associations |
||
915 | $label = Widget::Checkbox('fields[associated_entry_counts]', isset($fields['associated_entry_counts']) ? $fields['associated_entry_counts'] : null, __('Include a count of entries in associated sections')); |
||
916 | $this->setContext($label, array('sections')); |
||
917 | $fieldset->appendChild($label); |
||
918 | |||
919 | // Encoding |
||
920 | $label = Widget::Checkbox('fields[html_encode]', isset($fields['html_encode']) ? $fields['html_encode'] : null, __('HTML-encode text')); |
||
921 | $this->setContext($label, array('sections')); |
||
922 | $fieldset->appendChild($label); |
||
923 | |||
924 | $this->Form->appendChild($fieldset); |
||
925 | |||
926 | // Static XML |
||
927 | if (!isset($fields['static_xml'])) { |
||
928 | $fields['static_xml'] = null; |
||
929 | } |
||
930 | |||
931 | $fieldset = new XMLElement('fieldset'); |
||
932 | $this->setContext($fieldset, array('static-xml')); |
||
933 | $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); |
||
934 | $p = new XMLElement('p', __('Enter valid XML, exclude XML declaration')); |
||
935 | $p->setAttribute('class', 'help'); |
||
936 | $fieldset->appendChild($p); |
||
937 | |||
938 | $label = Widget::Label(); |
||
939 | $static_xml = htmlspecialchars( |
||
940 | $fields['static_xml'], |
||
941 | ENT_XML1|ENT_COMPAT, |
||
942 | 'UTF-8' |
||
943 | ); |
||
944 | $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, $static_xml, array('class' => 'code', 'placeholder' => '<static>content</static>'))); |
||
945 | |||
946 | if (isset($this->_errors['static_xml'])) { |
||
947 | $fieldset->appendChild(Widget::Error($label, $this->_errors['static_xml'])); |
||
948 | } else { |
||
949 | $fieldset->appendChild($label); |
||
950 | } |
||
951 | |||
952 | $this->Form->appendChild($fieldset); |
||
953 | |||
954 | // Connections |
||
955 | $fieldset = new XMLElement('fieldset'); |
||
956 | $fieldset->setAttribute('class', 'settings'); |
||
957 | $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages'))); |
||
958 | $p = new XMLElement('p', __('The data will only be available on the selected pages.')); |
||
959 | $p->setAttribute('class', 'help'); |
||
960 | $fieldset->appendChild($p); |
||
961 | |||
962 | $div = new XMLElement('div'); |
||
963 | $label = Widget::Label(__('Pages')); |
||
964 | |||
965 | $pages = PageManager::fetch(); |
||
966 | $ds_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); |
||
967 | $connections = ResourceManager::getAttachedPages(ResourceManager::RESOURCE_TYPE_DS, $ds_handle); |
||
968 | $selected = array(); |
||
969 | |||
970 | foreach ($connections as $connection) { |
||
971 | $selected[] = $connection['id']; |
||
972 | } |
||
973 | |||
974 | $options = array(); |
||
975 | |||
976 | foreach ($pages as $page) { |
||
977 | $options[] = array( |
||
978 | $page['id'], |
||
979 | in_array($page['id'], $selected), |
||
980 | General::sanitize(PageManager::resolvePageTitle($page['id'])) |
||
981 | ); |
||
982 | } |
||
983 | |||
984 | $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple'))); |
||
985 | $div->appendChild($label); |
||
986 | |||
987 | $fieldset->appendChild($div); |
||
988 | $this->Form->appendChild($fieldset); |
||
989 | |||
990 | |||
991 | // Call the provided datasources to let them inject their filters |
||
992 | // @todo Ideally when a new Datasource is chosen an AJAX request will fire |
||
993 | // to get the HTML from the extension. This is hardcoded for now into |
||
994 | // creating a 'big' page and then hiding the fields with JS |
||
995 | if (!empty($providers)) { |
||
996 | foreach ($providers as $providerClass => $provider) { |
||
997 | call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); |
||
998 | } |
||
999 | } |
||
1000 | |||
1001 | $div = new XMLElement('div'); |
||
1002 | $div->setAttribute('class', 'actions'); |
||
1003 | $div->appendChild(Widget::Input('action[save]', ($isEditing ? __('Save Changes') : __('Create Data Source')), 'submit', array('accesskey' => 's'))); |
||
1004 | |||
1005 | if ($isEditing) { |
||
1006 | $button = new XMLElement('button', __('Delete')); |
||
1007 | $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this data source'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this data source?'))); |
||
1008 | $div->appendChild($button); |
||
1009 | } |
||
1010 | |||
1011 | $this->Form->appendChild($div); |
||
1012 | } |
||
1679 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.