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