00001 <?php
00002
00032 class views_handler_argument extends views_handler {
00033 var $validator = NULL;
00034 var $argument = NULL;
00035 var $value = NULL;
00036
00041 var $name_table;
00042
00049 var $name_field;
00050
00054 function construct() {
00055 parent::construct();
00056
00057 if (!empty($this->definition['name field'])) {
00058 $this->name_field = $this->definition['name field'];
00059 }
00060 if (!empty($this->definition['name table'])) {
00061 $this->name_table = $this->definition['name table'];
00062 }
00063 }
00064
00065 function init(&$view, &$options) {
00066 parent::init($view, $options);
00067
00068
00069 if (!empty($options['wildcard']) && !isset($options['exception']['value'])) {
00070 $this->options['exception']['value'] = $options['wildcard'];
00071 }
00072 if (!empty($options['wildcard_substitution']) && !isset($options['exception']['title'])) {
00073
00074 $this->options['exception']['title_enable'] = 1;
00075 $this->options['exception']['title'] = $options['wildcard_substitution'];
00076 }
00077
00078 if (!isset($options['summary']['format']) && !empty($options['style_plugin'])) {
00079 $this->options['summary']['format'] = $options['style_plugin'];
00080 }
00081
00082 if (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc') {
00083 $this->options['default_action'] = 'summary';
00084 $this->options['summary']['sort_order'] = 'asc';
00085 $this->options['summary']['number_of_records'] = 0;
00086 $this->options['summary_options'] = $options['style_options'];
00087 }
00088 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc') {
00089 $this->options['default_action'] = 'summary';
00090 $this->options['summary']['sort_order'] = 'desc';
00091 $this->options['summary']['number_of_records'] = 0;
00092 $this->options['summary_options'] = $options['style_options'];
00093 }
00094 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc by count') {
00095 $this->options['default_action'] = 'summary';
00096 $this->options['summary']['sort_order'] = 'asc';
00097 $this->options['summary']['number_of_records'] = 1;
00098 $this->options['summary_options'] = $options['style_options'];
00099 }
00100 elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc by count') {
00101 $this->options['default_action'] = 'summary';
00102 $this->options['summary']['sort_order'] = 'desc';
00103 $this->options['summary']['number_of_records'] = 1;
00104 $this->options['summary_options'] = $options['style_options'];
00105 }
00106
00107 if (!empty($options['title']) && !isset($options['title_enable'])) {
00108 $this->options['title_enable'] = 1;
00109 }
00110 if (!empty($options['breadcrumb']) && !isset($options['breadcrumb_enable'])) {
00111 $this->options['breadcrumb_enable'] = 1;
00112 }
00113
00114 if (!empty($options['validate_type']) && !isset($options['validate']['type'])) {
00115 $this->options['validate']['type'] = $options['validate_type'];
00116 $this->options['specify_validation'] = 1;
00117 }
00118 if (!empty($options['validate_fail']) && !isset($options['validate']['fail'])) {
00119 $this->options['validate']['fail'] = $options['validate_fail'];
00120 $this->options['specify_validation'] = 1;
00121 }
00122 }
00123
00131 function set_breadcrumb(&$breadcrumb) { }
00132
00138 function uses_breadcrumb() {
00139 $info = $this->default_actions($this->options['default_action']);
00140 return !empty($info['breadcrumb']);
00141 }
00142
00143 function is_exception($arg = NULL) {
00144 if (!isset($arg)) {
00145 $arg = isset($this->argument) ? $this->argument : NULL;
00146 }
00147 return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg;
00148 }
00149
00150 function exception_title() {
00151
00152 if (empty($this->options['exception']['title_enable'])) {
00153 return $this->get_title();
00154 }
00155 return $this->options['exception']['title'];
00156 }
00157
00163 function needs_style_plugin() {
00164 $info = $this->default_actions($this->options['default_action']);
00165 $validate_info = $this->default_actions($this->options['validate']['fail']);
00166 return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
00167 }
00168
00169 function option_definition() {
00170 $options = parent::option_definition();
00171
00172 $options['default_action'] = array('default' => 'ignore');
00173 $options['exception'] = array(
00174 'contains' => array(
00175 'value' => array('default' => 'all'),
00176 'title_enable' => array('default' => 0),
00177 'title' => array('default' => t('All'), 'translatable' => TRUE),
00178 ),
00179 );
00180 $options['title_enable'] = array('default' => 0);
00181 $options['title'] = array('default' => '', 'translatable' => TRUE);
00182 $options['breadcrumb_enable'] = array('default' => 0);
00183 $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE);
00184 $options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
00185 $options['default_argument_options'] = array('default' => array(), 'export' => FALSE);
00186 $options['default_argument_skip_url'] = array('default' => FALSE);
00187 $options['summary_options'] = array('default' => array(), 'export' => FALSE);
00188 $options['summary'] = array(
00189 'contains' => array(
00190 'sort_order' => array('default' => 'asc'),
00191 'number_of_records' => array('default' => 0),
00192 'format' => array('default' => 'default_summary', 'export' => 'export_summary'),
00193 ),
00194 );
00195 $options['specify_validation'] = array('default' => 0);
00196 $options['validate'] = array(
00197 'contains' => array(
00198 'type' => array('default' => 'none', 'export' => 'export_validation'),
00199 'fail' => array('default' => 'not found'),
00200 ),
00201 );
00202 $options['validate_options'] = array('default' => array(), 'export' => FALSE);
00203
00204 return $options;
00205 }
00206
00207 function options_form(&$form, &$form_state) {
00208 parent::options_form($form, $form_state);
00209
00210 $argument_text = $this->view->display_handler->get_argument_text();
00211
00212 $form['#pre_render'][] = 'views_ui_pre_render_move_argument_options';
00213
00214 $form['description'] = array(
00215 '#markup' => $argument_text['description'],
00216 '#theme_wrappers' => array('container'),
00217 '#attributes' => array('class' => array('description')),
00218 );
00219
00220 $form['no_argument'] = array(
00221 '#type' => 'fieldset',
00222 '#title' => $argument_text['filter value not present'],
00223 );
00224
00225
00226 $form['no_argument']['clearfix'] = array(
00227 '#weight' => 1000,
00228 '#markup' => '<div class="clearfix"></div>',
00229 );
00230 $form['default_action'] = array(
00231 '#type' => 'radios',
00232 '#process' => array('views_ui_process_container_radios'),
00233 '#default_value' => $this->options['default_action'],
00234 '#fieldset' => 'no_argument',
00235 );
00236
00237 $form['exception'] = array(
00238 '#type' => 'fieldset',
00239 '#title' => t('Exceptions'),
00240 '#collapsible' => TRUE,
00241 '#collapsed' => TRUE,
00242 '#fieldset' => 'no_argument',
00243 );
00244 $form['exception']['value'] = array(
00245 '#type' => 'textfield',
00246 '#title' => t('Exception value'),
00247 '#size' => 20,
00248 '#default_value' => $this->options['exception']['value'],
00249 '#description' => t('If this value is received, the filter will be ignored; i.e, "all values"'),
00250 );
00251 $form['exception']['title_enable'] = array(
00252 '#type' => 'checkbox',
00253 '#title' => t('Override title'),
00254 '#default_value' => $this->options['exception']['title_enable'],
00255 );
00256 $form['exception']['title'] = array(
00257 '#type' => 'textfield',
00258 '#title' => t('Override title'),
00259 '#title_display' => 'invisible',
00260 '#size' => 20,
00261 '#default_value' => $this->options['exception']['title'],
00262 '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
00263 '#dependency' => array(
00264 'edit-options-exception-title-enable' => array('1'),
00265 ),
00266 );
00267
00268 $options = array();
00269 $defaults = $this->default_actions();
00270 $validate_options = array();
00271 foreach ($defaults as $id => $info) {
00272 $options[$id] = $info['title'];
00273 if (empty($info['default only'])) {
00274 $validate_options[$id] = $info['title'];
00275 }
00276 if (!empty($info['form method'])) {
00277 $this->{$info['form method']}($form, $form_state);
00278 }
00279 }
00280 $form['default_action']['#options'] = $options;
00281
00282 $form['argument_present'] = array(
00283 '#type' => 'fieldset',
00284 '#title' => $argument_text['filter value present'],
00285 );
00286 $form['title_enable'] = array(
00287 '#type' => 'checkbox',
00288 '#title' => t('Override title'),
00289 '#default_value' => $this->options['title_enable'],
00290 '#fieldset' => 'argument_present',
00291 );
00292 $form['title'] = array(
00293 '#type' => 'textfield',
00294 '#title' => t('Provide title'),
00295 '#title_display' => 'invisible',
00296 '#default_value' => $this->options['title'],
00297 '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
00298 '#dependency' => array(
00299 'edit-options-title-enable' => array('1'),
00300 ),
00301 '#fieldset' => 'argument_present',
00302 );
00303
00304 $form['breadcrumb_enable'] = array(
00305 '#type' => 'checkbox',
00306 '#title' => t('Override breadcrumb'),
00307 '#default_value' => $this->options['breadcrumb_enable'],
00308 '#fieldset' => 'argument_present',
00309 );
00310 $form['breadcrumb'] = array(
00311 '#type' => 'textfield',
00312 '#title' => t('Provide breadcrumb'),
00313 '#title_display' => 'invisible',
00314 '#default_value' => $this->options['breadcrumb'],
00315 '#description' => t('Enter a breadcrumb name you would like to use. See "Title" for percent substitutions.'),
00316 '#dependency' => array(
00317 'edit-options-breadcrumb-enable' => array('1'),
00318 ),
00319 '#fieldset' => 'argument_present',
00320 );
00321
00322 $form['specify_validation'] = array(
00323 '#type' => 'checkbox',
00324 '#title' => t('Specify validation criteria'),
00325 '#default_value' => $this->options['specify_validation'],
00326 '#fieldset' => 'argument_present',
00327 );
00328
00329 $form['validate'] = array(
00330 '#type' => 'container',
00331 '#fieldset' => 'argument_present',
00332 );
00333
00334
00335 $form['validate']['type'] = array(
00336 '#type' => 'select',
00337 '#title' => t('Validator'),
00338 '#default_value' => $this->options['validate']['type'],
00339 '#dependency' => array(
00340 'edit-options-specify-validation' => array('1'),
00341 ),
00342 );
00343
00344 $validate_types = array('none' => t('- Basic validation -'));
00345 $plugins = views_fetch_plugin_data('argument validator');
00346 foreach ($plugins as $id => $info) {
00347 if (!empty($info['no ui'])) {
00348 continue;
00349 }
00350
00351 $valid = TRUE;
00352 if (!empty($info['type'])) {
00353 $valid = FALSE;
00354 if (empty($this->definition['validate type'])) {
00355 continue;
00356 }
00357 foreach ((array) $info['type'] as $type) {
00358 if ($type == $this->definition['validate type']) {
00359 $valid = TRUE;
00360 break;
00361 }
00362 }
00363 }
00364
00365
00366 if ($valid) {
00367 $plugin = $this->get_plugin('argument validator', $id);
00368 if ($plugin) {
00369 if ($plugin->access() || $this->options['validate']['type'] == $id) {
00370 $form['validate']['options'][$id] = array(
00371 '#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
00372 '#suffix' => '</div>',
00373 '#type' => 'item',
00374 '#input' => TRUE,
00375 '#dependency' => array(
00376 'edit-options-specify-validation' => array('1'),
00377 'edit-options-validate-type' => array($id),
00378 ),
00379 '#dependency_count' => 2,
00380 '#id' => 'edit-options-validate-options-' . $id,
00381 );
00382 $plugin->options_form($form['validate']['options'][$id], $form_state);
00383 $validate_types[$id] = $info['title'];
00384 }
00385 }
00386 }
00387 }
00388
00389 asort($validate_types);
00390 $form['validate']['type']['#options'] = $validate_types;
00391
00392 $form['validate']['fail'] = array(
00393 '#type' => 'select',
00394 '#title' => t('Action to take if filter value does not validate'),
00395 '#default_value' => $this->options['validate']['fail'],
00396 '#options' => $validate_options,
00397 '#dependency' => array(
00398 'edit-options-specify-validation' => array('1'),
00399 ),
00400 '#fieldset' => 'argument_present',
00401 );
00402 }
00403
00404 function options_validate(&$form, &$form_state) {
00405 if (empty($form_state['values']['options'])) {
00406 return;
00407 }
00408
00409
00410 $default_id = $form_state['values']['options']['default_argument_type'];
00411 $plugin = $this->get_plugin('argument default', $default_id);
00412 if ($plugin) {
00413 $plugin->options_validate($form['argument_default'][$default_id], $form_state, $form_state['values']['options']['argument_default'][$default_id]);
00414 }
00415
00416
00417 $summary_id = $form_state['values']['options']['summary']['format'];
00418 $plugin = $this->get_plugin('style', $summary_id);
00419 if ($plugin) {
00420 $plugin->options_validate($form['summary']['options'][$summary_id], $form_state, $form_state['values']['options']['summary']['options'][$summary_id]);
00421 }
00422
00423 $validate_id = $form_state['values']['options']['validate']['type'];
00424 $plugin = $this->get_plugin('argument validator', $validate_id);
00425 if ($plugin) {
00426 $plugin->options_validate($form['validate']['options'][$default_id], $form_state, $form_state['values']['options']['validate']['options'][$validate_id]);
00427 }
00428
00429 }
00430
00431 function options_submit(&$form, &$form_state) {
00432 if (empty($form_state['values']['options'])) {
00433 return;
00434 }
00435
00436
00437 $default_id = $form_state['values']['options']['default_argument_type'];
00438 $plugin = $this->get_plugin('argument default', $default_id);
00439 if ($plugin) {
00440 $options = &$form_state['values']['options']['argument_default'][$default_id];
00441 $plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
00442
00443 $form_state['values']['options']['default_argument_options'] = $options;
00444 }
00445
00446
00447 $summary_id = $form_state['values']['options']['summary']['format'];
00448 $plugin = $this->get_plugin('style', $summary_id);
00449 if ($plugin) {
00450 $options = &$form_state['values']['options']['summary']['options'][$summary_id];
00451 $plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options);
00452
00453 $form_state['values']['options']['summary_options'] = $options;
00454 }
00455
00456 $validate_id = $form_state['values']['options']['validate']['type'];
00457 $plugin = $this->get_plugin('argument validator', $validate_id);
00458 if ($plugin) {
00459 $options = &$form_state['values']['options']['validate']['options'][$validate_id];
00460 $plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options);
00461
00462 $form_state['values']['options']['validate_options'] = $options;
00463 }
00464
00465
00466 $options =& $form_state['values']['options'];
00467 if (empty($options['title_enable'])) {
00468 $options['title'] = '';
00469 }
00470 }
00471
00478 function default_actions($which = NULL) {
00479 $defaults = array(
00480 'ignore' => array(
00481 'title' => t('Display all results for the specified field'),
00482 'method' => 'default_ignore',
00483 'breadcrumb' => TRUE,
00484 ),
00485 'default' => array(
00486 'title' => t('Provide default value'),
00487 'method' => 'default_default',
00488 'form method' => 'default_argument_form',
00489 'has default argument' => TRUE,
00490 'default only' => TRUE,
00491 'breadcrumb' => TRUE,
00492 ),
00493 'not found' => array(
00494 'title' => t('Hide view'),
00495 'method' => 'default_not_found',
00496 'hard fail' => TRUE,
00497 ),
00498 'summary' => array(
00499 'title' => t('Display a summary'),
00500 'method' => 'default_summary',
00501 'form method' => 'default_summary_form',
00502 'style plugin' => TRUE,
00503 'breadcrumb' => TRUE,
00504 ),
00505 'empty' => array(
00506 'title' => t('Display contents of "No results found"'),
00507 'method' => 'default_empty',
00508 'breadcrumb' => TRUE,
00509 ),
00510 );
00511
00512 if ($this->view->display_handler->has_path()) {
00513 $defaults['not found']['title'] = t('Show "Page not found"');
00514 }
00515
00516 if ($which) {
00517 if (!empty($defaults[$which])) {
00518 return $defaults[$which];
00519 }
00520 }
00521 else {
00522 return $defaults;
00523 }
00524 }
00525
00530 function default_argument_form(&$form, &$form_state) {
00531 $plugins = views_fetch_plugin_data('argument default');
00532 $options = array();
00533
00534 $form['default_argument_skip_url'] = array(
00535 '#type' => 'checkbox',
00536 '#title' => t('Skip default argument for view URL'),
00537 '#default_value' => $this->options['default_argument_skip_url'],
00538 '#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.')
00539 );
00540
00541 $form['default_argument_type'] = array(
00542 '#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
00543 '#suffix' => '</div>',
00544 '#type' => 'select',
00545 '#id' => 'edit-options-default-argument-type',
00546 '#title' => t('Type'),
00547 '#default_value' => $this->options['default_argument_type'],
00548
00549 '#dependency' => array('radio:options[default_action]' => array('default')),
00550
00551
00552 '#argument_option' => 'default',
00553 );
00554
00555 foreach ($plugins as $id => $info) {
00556 if (!empty($info['no ui'])) {
00557 continue;
00558 }
00559 $plugin = $this->get_plugin('argument default', $id);
00560 if ($plugin) {
00561 if ($plugin->access() || $this->options['default_argument_type'] == $id) {
00562 $form['argument_default']['#argument_option'] = 'default';
00563 $form['argument_default'][$id] = array(
00564 '#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
00565 '#suffix' => '</div>',
00566 '#id' => 'edit-options-argument-default-options-' . $id,
00567 '#type' => 'item',
00568 '#dependency' => array(
00569 'radio:options[default_action]' => array('default'),
00570 'edit-options-default-argument-type' => array($id)
00571 ),
00572 '#dependency_count' => 2,
00573 );
00574 $options[$id] = $info['title'];
00575 $plugin->options_form($form['argument_default'][$id], $form_state);
00576 }
00577 }
00578 }
00579
00580 asort($options);
00581 $form['default_argument_type']['#options'] = $options;
00582 }
00583
00588 function default_summary_form(&$form, &$form_state) {
00589 $style_plugins = views_fetch_plugin_data('style');
00590 $summary_plugins = array();
00591 $format_options = array();
00592 foreach ($style_plugins as $key => $plugin) {
00593 if (isset($plugin['type']) && $plugin['type'] == 'summary') {
00594 $summary_plugins[$key] = $plugin;
00595 $format_options[$key] = $plugin['title'];
00596 }
00597 }
00598
00599 $form['summary'] = array(
00600
00601
00602 '#argument_option' => 'summary',
00603 );
00604 $form['summary']['sort_order'] = array(
00605 '#type' => 'radios',
00606 '#title' => t('Sort order'),
00607 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
00608 '#default_value' => $this->options['summary']['sort_order'],
00609 '#dependency' => array('radio:options[default_action]' => array('summary')),
00610 );
00611 $form['summary']['number_of_records'] = array(
00612 '#type' => 'radios',
00613 '#title' => t('Sort by'),
00614 '#default_value' => $this->options['summary']['number_of_records'],
00615 '#options' => array(
00616 0 => $this->get_sort_name(),
00617 1 => t('Number of records')
00618 ),
00619 '#dependency' => array('radio:options[default_action]' => array('summary')),
00620 );
00621
00622 $form['summary']['format'] = array(
00623 '#type' => 'radios',
00624 '#title' => t('Format'),
00625 '#options' => $format_options,
00626 '#default_value' => $this->options['summary']['format'],
00627 '#dependency' => array('radio:options[default_action]' => array('summary')),
00628 );
00629
00630 foreach ($summary_plugins as $id => $info) {
00631 if (empty($info['uses options'])) {
00632 continue;
00633 }
00634 $plugin = $this->get_plugin('style', $id);
00635 if ($plugin) {
00636 $form['summary']['options'][$id] = array(
00637 '#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
00638 '#suffix' => '</div>',
00639 '#id' => 'edit-options-summary-options-' . $id,
00640 '#type' => 'item',
00641 '#input' => TRUE,
00642 '#dependency' => array(
00643 'radio:options[default_action]' => array('summary'),
00644 'radio:options[summary][format]' => array($id),
00645 ),
00646 '#dependency_count' => 2,
00647 );
00648 $options[$id] = $info['title'];
00649 $plugin->options_form($form['summary']['options'][$id], $form_state);
00650 }
00651 }
00652 }
00653
00663 function default_action($info = NULL) {
00664 if (!isset($info)) {
00665 $info = $this->default_actions($this->options['default_action']);
00666 }
00667
00668 if (!$info) {
00669 return FALSE;
00670 }
00671
00672 if (!empty($info['method args'])) {
00673 return call_user_func_array(array(&$this, $info['method']), $info['method args']);
00674 }
00675 else {
00676 return $this->{$info['method']}();
00677 }
00678 }
00679
00683 function validate_fail() {
00684 $info = $this->default_actions($this->options['validate']['fail']);
00685 return $this->default_action($info);
00686 }
00693 function default_ignore() {
00694 return TRUE;
00695 }
00696
00703 function default_not_found() {
00704
00705 $this->view->build_info['fail'] = TRUE;
00706 return FALSE;
00707 }
00708
00715 function default_empty() {
00716
00717 $this->view->built = TRUE;
00718 $this->view->executed = TRUE;
00719 $this->view->result = array();
00720 return FALSE;
00721 }
00722
00727 function default_default() {
00728 return TRUE;
00729 }
00730
00734 function has_default_argument() {
00735 $info = $this->default_actions($this->options['default_action']);
00736 return !empty($info['has default argument']);
00737 }
00738
00742 function get_default_argument() {
00743 $plugin = $this->get_plugin('argument default');
00744 if ($plugin) {
00745 return $plugin->get_argument();
00746 }
00747 }
00748
00755 function process_summary_arguments(&$args) {
00756 if ($this->options['validate']['type'] != 'none') {
00757 if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) {
00758 $this->validator->process_summary_arguments($args);
00759 }
00760 }
00761 }
00762
00769 function default_summary() {
00770 $this->view->build_info['summary'] = TRUE;
00771 $this->view->build_info['summary_level'] = $this->options['id'];
00772
00773
00774
00775 $this->view->plugin_name = $this->options['summary']['format'];
00776 $this->view->style_options = $this->options['summary_options'];
00777
00778
00779
00780 $this->query->clear_fields();
00781 $this->summary_query();
00782
00783 $by = $this->options['summary']['number_of_records'] ? 'num_records' : NULL;
00784 $this->summary_sort($this->options['summary']['sort_order'], $by);
00785
00786
00787
00788 $this->view->build_sort = $this->view->build_fields = FALSE;
00789 return TRUE;
00790 }
00791
00804 function summary_query() {
00805 $this->ensure_my_table();
00806
00807 $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
00808
00809 $this->summary_name_field();
00810 return $this->summary_basics();
00811 }
00812
00817 function summary_name_field() {
00818
00819
00820
00821 if (isset($this->name_table)) {
00822
00823
00824 if ($this->table_alias != $this->name_table) {
00825 $j = views_get_table_join($this->name_table, $this->table);
00826 if ($j) {
00827 $join = clone $j;
00828 $join->left_table = $this->table_alias;
00829 $this->name_table_alias = $this->query->add_table($this->name_table, $this->relationship, $join);
00830 }
00831 }
00832 else {
00833 $this->name_table_alias = $this->query->ensure_table($this->name_table, $this->relationship);
00834 }
00835 }
00836 else {
00837 $this->name_table_alias = $this->table_alias;
00838 }
00839
00840 if (isset($this->name_field)) {
00841 $this->name_alias = $this->query->add_field($this->name_table_alias, $this->name_field);
00842 }
00843 else {
00844 $this->name_alias = $this->base_alias;
00845 }
00846 }
00847
00852 function summary_basics($count_field = TRUE) {
00853
00854 $distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct));
00855
00856 $count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records',
00857 array('count' => TRUE, 'distinct' => $distinct));
00858 $this->query->add_groupby($this->name_alias);
00859
00860 if ($count_field) {
00861 $this->query->set_count_field($this->table_alias, $this->real_field);
00862 }
00863
00864 $this->count_alias = $count_alias;
00865 }
00866
00874 function summary_sort($order, $by = NULL) {
00875 $this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias));
00876 }
00877
00886 function summary_argument($data) {
00887 return $data->{$this->base_alias};
00888 }
00889
00897 function summary_name($data) {
00898 $value = $data->{$this->name_alias};
00899 if (empty($value) && !empty($this->definition['empty field name'])) {
00900 $value = $this->definition['empty field name'];
00901 }
00902 return check_plain($value);
00903 }
00904
00910 function query($group_by = FALSE) {
00911 $this->ensure_my_table();
00912 $this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
00913 }
00914
00920 function title() {
00921 return check_plain($this->argument);
00922 }
00923
00928 function get_title() {
00929 if (isset($this->validated_title)) {
00930 return $this->validated_title;
00931 }
00932 else {
00933 return $this->title();
00934 }
00935 }
00936
00940 function validate_arg($arg) {
00941
00942
00943 if (isset($this->argument_validated)) {
00944 return $this->argument_validated;
00945 }
00946
00947 if ($this->is_exception($arg)) {
00948 return $this->argument_validated = TRUE;
00949 }
00950
00951 if ($this->options['validate']['type'] == 'none') {
00952 return $this->argument_validated = $this->validate_argument_basic($arg);
00953 }
00954
00955 $plugin = $this->get_plugin('argument validator');
00956 if ($plugin) {
00957 return $this->argument_validated = $plugin->validate_argument($arg);
00958 }
00959
00960
00961 return $this->argument_validated = $this->validate_argument_basic($arg);
00962 }
00963
00971 function validate_argument($arg) {
00972 $validate_info = $this->default_actions($this->options['validate']['fail']);
00973 if (empty($validate_info['hard fail'])) {
00974 return TRUE;
00975 }
00976
00977 $rc = $this->validate_arg($arg);
00978
00979
00980
00981 $validate_info = $this->default_actions($this->options['validate']['fail']);
00982 if (empty($validate_info['hard fail'])) {
00983 return TRUE;
00984 }
00985
00986 return $rc;
00987 }
00988
00996 function validate_argument_basic($arg) {
00997 if (!isset($arg) || $arg === '') {
00998 return FALSE;
00999 }
01000
01001 if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) {
01002 return FALSE;
01003 }
01004
01005 return TRUE;
01006 }
01007
01013 function set_argument($arg) {
01014 $this->argument = $arg;
01015 return $this->validate_arg($arg);
01016 }
01017
01021 function get_value() {
01022
01023 if (isset($this->argument)) {
01024 return $this->argument;
01025 }
01026
01027
01028 $value = NULL;
01029
01030 $position = 0;
01031 foreach ($this->view->argument as $id => $argument) {
01032 if ($id == $this->options['id']) {
01033 break;
01034 }
01035 $position++;
01036 }
01037
01038 $arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL;
01039 $this->position = $position;
01040
01041
01042
01043 $argument = clone $this;
01044 if (!isset($arg) && $argument->has_default_argument()) {
01045 $arg = $argument->get_default_argument();
01046
01047
01048 $this->is_default = TRUE;
01049 }
01050
01051 if ($argument->set_argument($arg)) {
01052 $value = $argument->argument;
01053 }
01054 unset($argument);
01055 return $value;
01056 }
01057
01064 function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
01065 $output = '';
01066 $name = $this->options['summary'][$option];
01067 $options = $this->options['summary_options'];
01068
01069 $plugin = views_get_plugin('style', $name);
01070 if ($plugin) {
01071 $plugin->init($this->view, $this->view->display_handler->display, $options);
01072
01073 $output .= $indent . $prefix . "['summary']['$option'] = '$name';\n";
01074
01075
01076 $output .= $plugin->export_options($indent, $prefix . "['summary_options']");
01077 }
01078
01079 return $output;
01080 }
01081
01088 function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
01089 $output = '';
01090 $name = $this->options['validate'][$option];
01091 $options = $this->options['validate_options'];
01092
01093 $plugin = views_get_plugin('argument validator', $name);
01094 if ($plugin) {
01095 $plugin->init($this->view, $this->display, $options);
01096
01097 $output .= $indent . $prefix . "['validate']['$option'] = '$name';\n";
01098
01099
01100 $output .= $plugin->export_options($indent, $prefix . "['validate_options']");
01101 }
01102
01103 return $output;
01104 }
01105
01112 function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
01113 $output = '';
01114 if ($option == 'default_argument_type') {
01115 $type = 'argument default';
01116 $option_name = 'default_argument_options';
01117 }
01118
01119 $plugin = $this->get_plugin($type);
01120 $name = $this->options[$option];
01121
01122 if ($plugin) {
01123
01124 $output .= $indent . $prefix . "['$option'] = '$name';\n";
01125
01126
01127 $output .= $plugin->export_options($indent, $prefix . "['$option_name']");
01128 }
01129
01130 return $output;
01131 }
01132
01136 function get_plugin($type = 'argument default', $name = NULL) {
01137 $options = array();
01138 switch ($type) {
01139 case 'argument default':
01140 $plugin_name = $this->options['default_argument_type'];
01141 $options_name = 'default_argument_options';
01142 break;
01143 case 'argument validator':
01144 $plugin_name = $this->options['validate']['type'];
01145 $options_name = 'validate_options';
01146 break;
01147 case 'style':
01148 $plugin_name = $this->options['summary']['format'];
01149 $options_name = 'summary_options';
01150 }
01151
01152 if (!$name) {
01153 $name = $plugin_name;
01154 }
01155
01156
01157
01158 if ($name == $plugin_name) {
01159 $options = $this->options[$options_name];
01160 }
01161
01162 $plugin = views_get_plugin($type, $name);
01163 if ($plugin) {
01164
01165 if ($type == 'style') {
01166 $plugin->init($this->view, $this->view->display_handler->display, $options);
01167 }
01168 else {
01169 $plugin->init($this->view, $this, $options);
01170 }
01171 return $plugin;
01172 }
01173 }
01174
01181 function get_sort_name() {
01182 return t('Default sort', array(), array('context' => 'Sort order'));
01183 }
01184 }
01185
01191 class views_handler_argument_broken extends views_handler_argument {
01192 function ui_name($short = FALSE) {
01193 return t('Broken/missing handler');
01194 }
01195
01196 function ensure_my_table() { }
01197 function query($group_by = FALSE) { }
01198 function options_form(&$form, &$form_state) {
01199 $form['markup'] = array(
01200 '#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
01201 );
01202 }
01203
01207 function broken() { return TRUE; }
01208 }
01209