1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240 |
- <?php
- class views_handler_argument extends views_handler {
- var $validator = NULL;
- var $argument = NULL;
- var $value = NULL;
-
- var $name_table;
-
- var $name_field;
-
- function construct() {
- parent::construct();
- if (!empty($this->definition['name field'])) {
- $this->name_field = $this->definition['name field'];
- }
- if (!empty($this->definition['name table'])) {
- $this->name_table = $this->definition['name table'];
- }
- }
- function init(&$view, &$options) {
- parent::init($view, $options);
-
- if (!empty($options['wildcard']) && !isset($options['exception']['value'])) {
- $this->options['exception']['value'] = $options['wildcard'];
- }
- if (!empty($options['wildcard_substitution']) && !isset($options['exception']['title'])) {
-
- $this->options['exception']['title_enable'] = 1;
- $this->options['exception']['title'] = $options['wildcard_substitution'];
- }
- if (!isset($options['summary']['format']) && !empty($options['style_plugin'])) {
- $this->options['summary']['format'] = $options['style_plugin'];
- }
-
- $options['style_options'] = isset($options['style_options']) ? $options['style_options'] : array();
- if (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc') {
- $this->options['default_action'] = 'summary';
- $this->options['summary']['sort_order'] = 'asc';
- $this->options['summary']['number_of_records'] = 0;
- $this->options['summary_options'] = $options['style_options'];
- }
- elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc') {
- $this->options['default_action'] = 'summary';
- $this->options['summary']['sort_order'] = 'desc';
- $this->options['summary']['number_of_records'] = 0;
- $this->options['summary_options'] = $options['style_options'];
- }
- elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary asc by count') {
- $this->options['default_action'] = 'summary';
- $this->options['summary']['sort_order'] = 'asc';
- $this->options['summary']['number_of_records'] = 1;
- $this->options['summary_options'] = $options['style_options'];
- }
- elseif (!isset($options['summary']['sort_order']) && !empty($options['default_action']) && $options['default_action'] == 'summary desc by count') {
- $this->options['default_action'] = 'summary';
- $this->options['summary']['sort_order'] = 'desc';
- $this->options['summary']['number_of_records'] = 1;
- $this->options['summary_options'] = $options['style_options'];
- }
- if (!empty($options['title']) && !isset($options['title_enable'])) {
- $this->options['title_enable'] = 1;
- }
- if (!empty($options['breadcrumb']) && !isset($options['breadcrumb_enable'])) {
- $this->options['breadcrumb_enable'] = 1;
- }
- if (!empty($options['validate_type']) && !isset($options['validate']['type'])) {
- $this->options['validate']['type'] = $options['validate_type'];
- $this->options['specify_validation'] = 1;
- }
- if (!empty($options['validate_fail']) && !isset($options['validate']['fail'])) {
- $this->options['validate']['fail'] = $options['validate_fail'];
- $this->options['specify_validation'] = 1;
- }
- }
-
- function set_breadcrumb(&$breadcrumb) { }
-
- function uses_breadcrumb() {
- $info = $this->default_actions($this->options['default_action']);
- return !empty($info['breadcrumb']);
- }
- function is_exception($arg = NULL) {
- if (!isset($arg)) {
- $arg = isset($this->argument) ? $this->argument : NULL;
- }
- return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg;
- }
- function exception_title() {
-
- if (empty($this->options['exception']['title_enable'])) {
- return $this->get_title();
- }
- return $this->options['exception']['title'];
- }
-
- function needs_style_plugin() {
- $info = $this->default_actions($this->options['default_action']);
- $validate_info = $this->default_actions($this->options['validate']['fail']);
- return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
- }
- function option_definition() {
- $options = parent::option_definition();
- $options['default_action'] = array('default' => 'ignore');
- $options['exception'] = array(
- 'contains' => array(
- 'value' => array('default' => 'all'),
- 'title_enable' => array('default' => FALSE, 'bool' => TRUE),
- 'title' => array('default' => 'All', 'translatable' => TRUE),
- ),
- );
- $options['title_enable'] = array('default' => FALSE, 'bool' => TRUE);
- $options['title'] = array('default' => '', 'translatable' => TRUE);
- $options['breadcrumb_enable'] = array('default' => FALSE, 'bool' => TRUE);
- $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE);
- $options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
- $options['default_argument_options'] = array('default' => array(), 'export' => FALSE);
- $options['default_argument_skip_url'] = array('default' => FALSE, 'bool' => TRUE);
- $options['summary_options'] = array('default' => array(), 'export' => FALSE);
- $options['summary'] = array(
- 'contains' => array(
- 'sort_order' => array('default' => 'asc'),
- 'number_of_records' => array('default' => 0),
- 'format' => array('default' => 'default_summary', 'export' => 'export_summary'),
- ),
- );
- $options['specify_validation'] = array('default' => FALSE, 'bool' => TRUE);
- $options['validate'] = array(
- 'contains' => array(
- 'type' => array('default' => 'none', 'export' => 'export_validation'),
- 'fail' => array('default' => 'not found'),
- ),
- );
- $options['validate_options'] = array('default' => array(), 'export' => FALSE);
- return $options;
- }
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $argument_text = $this->view->display_handler->get_argument_text();
- $form['#pre_render'][] = 'views_ui_pre_render_move_argument_options';
- $form['description'] = array(
- '#markup' => $argument_text['description'],
- '#theme_wrappers' => array('container'),
- '#attributes' => array('class' => array('description')),
- );
- $form['no_argument'] = array(
- '#type' => 'fieldset',
- '#title' => $argument_text['filter value not present'],
- );
-
-
- $form['no_argument']['clearfix'] = array(
- '#weight' => 1000,
- '#markup' => '<div class="clearfix"></div>',
- );
- $form['default_action'] = array(
- '#type' => 'radios',
- '#process' => array('views_ui_process_container_radios'),
- '#default_value' => $this->options['default_action'],
- '#fieldset' => 'no_argument',
- );
- $form['exception'] = array(
- '#type' => 'fieldset',
- '#title' => t('Exceptions'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#fieldset' => 'no_argument',
- );
- $form['exception']['value'] = array(
- '#type' => 'textfield',
- '#title' => t('Exception value'),
- '#size' => 20,
- '#default_value' => $this->options['exception']['value'],
- '#description' => t('If this value is received, the filter will be ignored; i.e, "all values"'),
- );
- $form['exception']['title_enable'] = array(
- '#type' => 'checkbox',
- '#title' => t('Override title'),
- '#default_value' => $this->options['exception']['title_enable'],
- );
- $form['exception']['title'] = array(
- '#type' => 'textfield',
- '#title' => t('Override title'),
- '#title_display' => 'invisible',
- '#size' => 20,
- '#default_value' => $this->options['exception']['title'],
- '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
- '#dependency' => array(
- 'edit-options-exception-title-enable' => array('1'),
- ),
- );
- $options = array();
- $defaults = $this->default_actions();
- $validate_options = array();
- foreach ($defaults as $id => $info) {
- $options[$id] = $info['title'];
- if (empty($info['default only'])) {
- $validate_options[$id] = $info['title'];
- }
- if (!empty($info['form method'])) {
- $this->{$info['form method']}($form, $form_state);
- }
- }
- $form['default_action']['#options'] = $options;
- $form['argument_present'] = array(
- '#type' => 'fieldset',
- '#title' => $argument_text['filter value present'],
- );
- $form['title_enable'] = array(
- '#type' => 'checkbox',
- '#title' => t('Override title'),
- '#default_value' => $this->options['title_enable'],
- '#fieldset' => 'argument_present',
- );
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => t('Provide title'),
- '#title_display' => 'invisible',
- '#default_value' => $this->options['title'],
- '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
- '#dependency' => array(
- 'edit-options-title-enable' => array('1'),
- ),
- '#fieldset' => 'argument_present',
- );
- $form['breadcrumb_enable'] = array(
- '#type' => 'checkbox',
- '#title' => t('Override breadcrumb'),
- '#default_value' => $this->options['breadcrumb_enable'],
- '#fieldset' => 'argument_present',
- );
- $form['breadcrumb'] = array(
- '#type' => 'textfield',
- '#title' => t('Provide breadcrumb'),
- '#title_display' => 'invisible',
- '#default_value' => $this->options['breadcrumb'],
- '#description' => t('Enter a breadcrumb name you would like to use. See "Title" for percent substitutions.'),
- '#dependency' => array(
- 'edit-options-breadcrumb-enable' => array('1'),
- ),
- '#fieldset' => 'argument_present',
- );
- $form['specify_validation'] = array(
- '#type' => 'checkbox',
- '#title' => t('Specify validation criteria'),
- '#default_value' => $this->options['specify_validation'],
- '#fieldset' => 'argument_present',
- );
- $form['validate'] = array(
- '#type' => 'container',
- '#fieldset' => 'argument_present',
- );
-
-
- $form['validate']['type'] = array(
- '#type' => 'select',
- '#title' => t('Validator'),
- '#default_value' => $this->options['validate']['type'],
- '#dependency' => array(
- 'edit-options-specify-validation' => array('1'),
- ),
- );
- $validate_types = array('none' => t('- Basic validation -'));
- $plugins = views_fetch_plugin_data('argument validator');
- foreach ($plugins as $id => $info) {
- if (!empty($info['no ui'])) {
- continue;
- }
- $valid = TRUE;
- if (!empty($info['type'])) {
- $valid = FALSE;
- if (empty($this->definition['validate type'])) {
- continue;
- }
- foreach ((array) $info['type'] as $type) {
- if ($type == $this->definition['validate type']) {
- $valid = TRUE;
- break;
- }
- }
- }
-
- if ($valid) {
- $plugin = $this->get_plugin('argument validator', $id);
- if ($plugin) {
- if ($plugin->access() || $this->options['validate']['type'] == $id) {
- $form['validate']['options'][$id] = array(
- '#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
- '#suffix' => '</div>',
- '#type' => 'item',
-
- '#input' => TRUE,
- '#dependency' => array(
- 'edit-options-specify-validation' => array('1'),
- 'edit-options-validate-type' => array($id),
- ),
- '#dependency_count' => 2,
- '#id' => 'edit-options-validate-options-' . $id,
- );
- $plugin->options_form($form['validate']['options'][$id], $form_state);
- $validate_types[$id] = $info['title'];
- }
- }
- }
- }
- asort($validate_types);
- $form['validate']['type']['#options'] = $validate_types;
- $form['validate']['fail'] = array(
- '#type' => 'select',
- '#title' => t('Action to take if filter value does not validate'),
- '#default_value' => $this->options['validate']['fail'],
- '#options' => $validate_options,
- '#dependency' => array(
- 'edit-options-specify-validation' => array('1'),
- ),
- '#fieldset' => 'argument_present',
- );
- }
- function options_validate(&$form, &$form_state) {
- if (empty($form_state['values']['options'])) {
- return;
- }
-
- $default_id = $form_state['values']['options']['default_argument_type'];
- $plugin = $this->get_plugin('argument default', $default_id);
- if ($plugin) {
- $plugin->options_validate($form['argument_default'][$default_id], $form_state, $form_state['values']['options']['argument_default'][$default_id]);
- }
-
- $summary_id = $form_state['values']['options']['summary']['format'];
- $plugin = $this->get_plugin('style', $summary_id);
- if ($plugin) {
- $plugin->options_validate($form['summary']['options'][$summary_id], $form_state, $form_state['values']['options']['summary']['options'][$summary_id]);
- }
- $validate_id = $form_state['values']['options']['validate']['type'];
- $plugin = $this->get_plugin('argument validator', $validate_id);
- if ($plugin) {
- $plugin->options_validate($form['validate']['options'][$default_id], $form_state, $form_state['values']['options']['validate']['options'][$validate_id]);
- }
- }
- function options_submit(&$form, &$form_state) {
- if (empty($form_state['values']['options'])) {
- return;
- }
-
- $default_id = $form_state['values']['options']['default_argument_type'];
- $plugin = $this->get_plugin('argument default', $default_id);
- if ($plugin) {
- $options = &$form_state['values']['options']['argument_default'][$default_id];
- $plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
-
- $form_state['values']['options']['default_argument_options'] = $options;
- }
-
- $summary_id = $form_state['values']['options']['summary']['format'];
- $plugin = $this->get_plugin('style', $summary_id);
- if ($plugin) {
- $options = &$form_state['values']['options']['summary']['options'][$summary_id];
- $plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options);
-
- $form_state['values']['options']['summary_options'] = $options;
- }
- $validate_id = $form_state['values']['options']['validate']['type'];
- $plugin = $this->get_plugin('argument validator', $validate_id);
- if ($plugin) {
- $options = &$form_state['values']['options']['validate']['options'][$validate_id];
- $plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options);
-
- $form_state['values']['options']['validate_options'] = $options;
- }
-
- $options =& $form_state['values']['options'];
- if (empty($options['title_enable'])) {
- $options['title'] = '';
- }
- }
-
- function default_actions($which = NULL) {
- $defaults = array(
- 'ignore' => array(
- 'title' => t('Display all results for the specified field'),
- 'method' => 'default_ignore',
- 'breadcrumb' => TRUE,
- ),
- 'default' => array(
- 'title' => t('Provide default value'),
- 'method' => 'default_default',
- 'form method' => 'default_argument_form',
- 'has default argument' => TRUE,
- 'default only' => TRUE,
- 'breadcrumb' => TRUE,
- ),
- 'not found' => array(
- 'title' => t('Hide view'),
- 'method' => 'default_not_found',
- 'hard fail' => TRUE,
- ),
- 'summary' => array(
- 'title' => t('Display a summary'),
- 'method' => 'default_summary',
- 'form method' => 'default_summary_form',
- 'style plugin' => TRUE,
- 'breadcrumb' => TRUE,
- ),
- 'empty' => array(
- 'title' => t('Display contents of "No results found"'),
- 'method' => 'default_empty',
- 'breadcrumb' => TRUE,
- ),
- 'access denied' => array(
- 'title' => t('Display "Access Denied"'),
- 'method' => 'default_access_denied',
- 'breadcrumb' => FALSE,
- ),
- );
- if ($this->view->display_handler->has_path()) {
- $defaults['not found']['title'] = t('Show "Page not found"');
- }
- if ($which) {
- if (!empty($defaults[$which])) {
- return $defaults[$which];
- }
- }
- else {
- return $defaults;
- }
- }
-
- function default_argument_form(&$form, &$form_state) {
- $plugins = views_fetch_plugin_data('argument default');
- $options = array();
- $form['default_argument_skip_url'] = array(
- '#type' => 'checkbox',
- '#title' => t('Skip default argument for view URL'),
- '#default_value' => $this->options['default_argument_skip_url'],
- '#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.')
- );
- $form['default_argument_type'] = array(
- '#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
- '#suffix' => '</div>',
- '#type' => 'select',
- '#id' => 'edit-options-default-argument-type',
- '#title' => t('Type'),
- '#default_value' => $this->options['default_argument_type'],
- '#dependency' => array('radio:options[default_action]' => array('default')),
-
-
- '#argument_option' => 'default',
- );
- foreach ($plugins as $id => $info) {
- if (!empty($info['no ui'])) {
- continue;
- }
- $plugin = $this->get_plugin('argument default', $id);
- if ($plugin) {
- if ($plugin->access() || $this->options['default_argument_type'] == $id) {
- $form['argument_default']['#argument_option'] = 'default';
- $form['argument_default'][$id] = array(
- '#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
- '#suffix' => '</div>',
- '#id' => 'edit-options-argument-default-options-' . $id,
- '#type' => 'item',
-
- '#input' => TRUE,
- '#dependency' => array(
- 'radio:options[default_action]' => array('default'),
- 'edit-options-default-argument-type' => array($id)
- ),
- '#dependency_count' => 2,
- );
- $options[$id] = $info['title'];
- $plugin->options_form($form['argument_default'][$id], $form_state);
- }
- }
- }
- asort($options);
- $form['default_argument_type']['#options'] = $options;
- }
-
- function default_summary_form(&$form, &$form_state) {
- $style_plugins = views_fetch_plugin_data('style');
- $summary_plugins = array();
- $format_options = array();
- foreach ($style_plugins as $key => $plugin) {
- if (isset($plugin['type']) && $plugin['type'] == 'summary') {
- $summary_plugins[$key] = $plugin;
- $format_options[$key] = $plugin['title'];
- }
- }
- $form['summary'] = array(
-
-
- '#argument_option' => 'summary',
- );
- $form['summary']['sort_order'] = array(
- '#type' => 'radios',
- '#title' => t('Sort order'),
- '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
- '#default_value' => $this->options['summary']['sort_order'],
- '#dependency' => array('radio:options[default_action]' => array('summary')),
- );
- $form['summary']['number_of_records'] = array(
- '#type' => 'radios',
- '#title' => t('Sort by'),
- '#default_value' => $this->options['summary']['number_of_records'],
- '#options' => array(
- 0 => $this->get_sort_name(),
- 1 => t('Number of records')
- ),
- '#dependency' => array('radio:options[default_action]' => array('summary')),
- );
- $form['summary']['format'] = array(
- '#type' => 'radios',
- '#title' => t('Format'),
- '#options' => $format_options,
- '#default_value' => $this->options['summary']['format'],
- '#dependency' => array('radio:options[default_action]' => array('summary')),
- );
- foreach ($summary_plugins as $id => $info) {
- if (empty($info['uses options'])) {
- continue;
- }
- $plugin = $this->get_plugin('style', $id);
- if ($plugin) {
- $form['summary']['options'][$id] = array(
- '#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
- '#suffix' => '</div>',
- '#id' => 'edit-options-summary-options-' . $id,
- '#type' => 'item',
- '#input' => TRUE,
- '#dependency' => array(
- 'radio:options[default_action]' => array('summary'),
- 'radio:options[summary][format]' => array($id),
- ),
- '#dependency_count' => 2,
- );
- $options[$id] = $info['title'];
- $plugin->options_form($form['summary']['options'][$id], $form_state);
- }
- }
- }
-
- function default_action($info = NULL) {
- if (!isset($info)) {
- $info = $this->default_actions($this->options['default_action']);
- }
- if (!$info) {
- return FALSE;
- }
- if (!empty($info['method args'])) {
- return call_user_func_array(array(&$this, $info['method']), $info['method args']);
- }
- else {
- return $this->{$info['method']}();
- }
- }
-
- function validate_fail() {
- $info = $this->default_actions($this->options['validate']['fail']);
- return $this->default_action($info);
- }
-
- function default_ignore() {
- return TRUE;
- }
-
- function default_not_found() {
-
- $this->view->build_info['fail'] = TRUE;
- return FALSE;
- }
-
- function default_access_denied() {
- $this->view->build_info['denied'] = TRUE;
- return FALSE;
- }
-
- function default_empty() {
-
- $this->view->built = TRUE;
- $this->view->executed = TRUE;
- $this->view->result = array();
- return FALSE;
- }
-
- function default_default() {
- return TRUE;
- }
-
- function has_default_argument() {
- $info = $this->default_actions($this->options['default_action']);
- return !empty($info['has default argument']);
- }
-
- function get_default_argument() {
- $plugin = $this->get_plugin('argument default');
- if ($plugin) {
- return $plugin->get_argument();
- }
- }
-
- function process_summary_arguments(&$args) {
- if ($this->options['validate']['type'] != 'none') {
- if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) {
- $this->validator->process_summary_arguments($args);
- }
- }
- }
-
- function default_summary() {
- $this->view->build_info['summary'] = TRUE;
- $this->view->build_info['summary_level'] = $this->options['id'];
-
-
- $this->view->plugin_name = $this->options['summary']['format'];
- $this->view->style_options = $this->options['summary_options'];
-
-
- $this->query->clear_fields();
- $this->summary_query();
- $by = $this->options['summary']['number_of_records'] ? 'num_records' : NULL;
- $this->summary_sort($this->options['summary']['sort_order'], $by);
-
-
- $this->view->build_sort = $this->view->build_fields = FALSE;
- return TRUE;
- }
-
- function summary_query() {
- $this->ensure_my_table();
-
- $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
- $this->summary_name_field();
- return $this->summary_basics();
- }
-
- function summary_name_field() {
-
-
- if (isset($this->name_table)) {
-
-
- if ($this->table_alias != $this->name_table) {
- $j = views_get_table_join($this->name_table, $this->table);
- if ($j) {
- $join = clone $j;
- $join->left_table = $this->table_alias;
- $this->name_table_alias = $this->query->add_table($this->name_table, $this->relationship, $join);
- }
- }
- else {
- $this->name_table_alias = $this->query->ensure_table($this->name_table, $this->relationship);
- }
- }
- else {
- $this->name_table_alias = $this->table_alias;
- }
- if (isset($this->name_field)) {
- $this->name_alias = $this->query->add_field($this->name_table_alias, $this->name_field);
- }
- else {
- $this->name_alias = $this->base_alias;
- }
- }
-
- function summary_basics($count_field = TRUE) {
-
- $distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct));
- $count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records',
- array('count' => TRUE, 'distinct' => $distinct));
- $this->query->add_groupby($this->name_alias);
- if ($count_field) {
- $this->query->set_count_field($this->table_alias, $this->real_field);
- }
- $this->count_alias = $count_alias;
- }
-
- function summary_sort($order, $by = NULL) {
- $this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias));
- }
-
- function summary_argument($data) {
- return $data->{$this->base_alias};
- }
-
- function summary_name($data) {
- $value = $data->{$this->name_alias};
- if (empty($value) && !empty($this->definition['empty field name'])) {
- $value = $this->definition['empty field name'];
- }
- return check_plain($value);
- }
-
- function query($group_by = FALSE) {
- $this->ensure_my_table();
- $this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
- }
-
- function title() {
- return check_plain($this->argument);
- }
-
- function get_title() {
- if (isset($this->validated_title)) {
- return $this->validated_title;
- }
- else {
- return $this->title();
- }
- }
-
- function validate_arg($arg) {
-
-
- if (isset($this->argument_validated)) {
- return $this->argument_validated;
- }
- if ($this->is_exception($arg)) {
- return $this->argument_validated = TRUE;
- }
- if ($this->options['validate']['type'] == 'none') {
- return $this->argument_validated = $this->validate_argument_basic($arg);
- }
- $plugin = $this->get_plugin('argument validator');
- if ($plugin) {
- return $this->argument_validated = $plugin->validate_argument($arg);
- }
-
- return $this->argument_validated = $this->validate_argument_basic($arg);
- }
-
- function validate_argument($arg) {
- $validate_info = $this->default_actions($this->options['validate']['fail']);
- if (empty($validate_info['hard fail'])) {
- return TRUE;
- }
- $rc = $this->validate_arg($arg);
-
-
- $validate_info = $this->default_actions($this->options['validate']['fail']);
- if (empty($validate_info['hard fail'])) {
- return TRUE;
- }
- return $rc;
- }
-
- function validate_argument_basic($arg) {
- if (!isset($arg) || $arg === '') {
- return FALSE;
- }
- if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) {
- return FALSE;
- }
- return TRUE;
- }
-
- function set_argument($arg) {
- $this->argument = $arg;
- return $this->validate_arg($arg);
- }
-
- function get_value() {
-
- if (isset($this->argument)) {
- return $this->argument;
- }
-
- $value = NULL;
-
- $position = 0;
- foreach ($this->view->argument as $id => $argument) {
- if ($id == $this->options['id']) {
- break;
- }
- $position++;
- }
- $arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL;
- $this->position = $position;
-
-
- $argument = clone $this;
- if (!isset($arg) && $argument->has_default_argument()) {
- $arg = $argument->get_default_argument();
-
- $this->is_default = TRUE;
- }
-
- if ($argument->set_argument($arg)) {
- $value = $argument->argument;
- }
- unset($argument);
- return $value;
- }
-
- function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- $name = $this->options['summary'][$option];
- $options = $this->options['summary_options'];
- $plugin = views_get_plugin('style', $name);
- if ($plugin) {
- $plugin->init($this->view, $this->view->display_handler->display, $options);
-
- $output .= $indent . $prefix . "['summary']['$option'] = '$name';\n";
-
- $output .= $plugin->export_options($indent, $prefix . "['summary_options']");
- }
- return $output;
- }
-
- function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- $name = $this->options['validate'][$option];
- $options = $this->options['validate_options'];
- $plugin = views_get_plugin('argument validator', $name);
- if ($plugin) {
- $plugin->init($this->view, $this->display, $options);
-
- $output .= $indent . $prefix . "['validate']['$option'] = '$name';\n";
-
- $output .= $plugin->export_options($indent, $prefix . "['validate_options']");
- }
- return $output;
- }
-
- function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- if ($option == 'default_argument_type') {
- $type = 'argument default';
- $option_name = 'default_argument_options';
- }
- $plugin = $this->get_plugin($type);
- $name = $this->options[$option];
- if ($plugin) {
-
- $output .= $indent . $prefix . "['$option'] = '$name';\n";
-
- $output .= $plugin->export_options($indent, $prefix . "['$option_name']");
- }
- return $output;
- }
-
- function get_plugin($type = 'argument default', $name = NULL) {
- $options = array();
- switch ($type) {
- case 'argument default':
- $plugin_name = $this->options['default_argument_type'];
- $options_name = 'default_argument_options';
- break;
- case 'argument validator':
- $plugin_name = $this->options['validate']['type'];
- $options_name = 'validate_options';
- break;
- case 'style':
- $plugin_name = $this->options['summary']['format'];
- $options_name = 'summary_options';
- }
- if (!$name) {
- $name = $plugin_name;
- }
-
-
- if ($name == $plugin_name) {
- $options = $this->options[$options_name];
- }
- $plugin = views_get_plugin($type, $name);
- if ($plugin) {
-
- if ($type == 'style') {
- $plugin->init($this->view, $this->view->display_handler->display, $options);
- }
- else {
- $plugin->init($this->view, $this, $options);
- }
- return $plugin;
- }
- }
-
- function get_sort_name() {
- return t('Default sort', array(), array('context' => 'Sort order'));
- }
- }
- class views_handler_argument_broken extends views_handler_argument {
- function ui_name($short = FALSE) {
- return t('Broken/missing handler');
- }
- function ensure_my_table() { }
- function query($group_by = FALSE) { }
- function options_form(&$form, &$form_state) {
- $form['markup'] = array(
- '#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>',
- );
- }
-
- function broken() { return TRUE; }
- }
|