[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views/plugins/ -> views_plugin_style_summary_jump_menu.inc (source)

   1  <?php
   2  /**
   3   * @file
   4   * Contains the default summary style plugin, which displays items in an HTML list.
   5   */
   6  
   7  /**
   8   * The default style plugin for summaries.
   9   *
  10   * @ingroup views_style_plugins
  11   */
  12  class views_plugin_style_summary_jump_menu extends views_plugin_style {
  13    function option_definition() {
  14      $options = parent::option_definition();
  15  
  16      $options['base_path'] = array('default' => '');
  17      $options['count'] = array('default' => TRUE);
  18      $options['hide'] = array('default' => FALSE);
  19      $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
  20      $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
  21      $options['default_value'] = array('default' => FALSE);
  22  
  23      return $options;
  24    }
  25  
  26    function query() {
  27      // We can't have an offset without a limit, so provide a very large limit instead.
  28      if (!empty($this->display->handler->options['offset'])) {
  29        $this->view->set_items_per_page(999999);
  30      }
  31      else {
  32        $this->view->set_items_per_page(0);
  33        $this->view->set_use_pager(0);
  34      }
  35    }
  36  
  37    function options_form(&$form, &$form_state) {
  38      parent::options_form($form, $form_state);
  39      $form['base_path'] = array(
  40        '#type' => 'textfield',
  41        '#title' => t('Base path'),
  42        '#default_value' => $this->options['base_path'],
  43        '#description' => t('Define the base path for links in this summary
  44          view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
  45          Do not include beginning and ending forward slash. If this value
  46          is empty, views will use the first path found as the base path,
  47          in page displays, or / if no path could be found.'),
  48      );
  49      $form['count'] = array(
  50        '#type' => 'checkbox',
  51        '#default_value' => !empty($this->options['count']),
  52        '#title' => t('Display record count with link'),
  53      );
  54  
  55      $form['hide'] = array(
  56        '#type' => 'checkbox',
  57        '#title' => t('Hide the "Go" button.'),
  58        '#default_value' => !empty($this->options['hide']),
  59        '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'),
  60      );
  61  
  62      $form['text'] = array(
  63        '#type' => 'textfield',
  64        '#title' => t('Button text'),
  65        '#default_value' => $this->options['text'],
  66      );
  67  
  68      $form['choose'] = array(
  69        '#type' => 'textfield',
  70        '#title' => t('Choose text'),
  71        '#default_value' => $this->options['choose'],
  72        '#description' => t('The text that will appear as the selected option in the jump menu.'),
  73      );
  74  
  75      $form['default_value'] = array(
  76        '#type' => 'checkbox',
  77        '#title' => t('Select the current argument.'),
  78        '#default_value' => !empty($this->options['default_value']),
  79        '#description' => t('If checked, the current argument setting will be displayed as the default option in the jump menu, if applicable.'),
  80      );
  81    }
  82  
  83    function render() {
  84      $argument = $this->view->argument[$this->view->build_info['summary_level']];
  85  
  86      $url_options = array();
  87  
  88      if (!empty($this->view->exposed_raw_input)) {
  89        $url_options['query'] = $this->view->exposed_raw_input;
  90      }
  91  
  92      $options = array();
  93      $default_value = '';
  94      foreach ($this->view->result as $id => $row) {
  95        $args = $this->view->args;
  96        $args[$argument->position] = $argument->summary_argument($row);
  97        $base_path = NULL;
  98        if (!empty($argument->options['style_options']['base_path'])) {
  99          $base_path = $argument->options['style_options']['base_path'];
 100        }
 101        $path = url($this->view->get_url($args, $base_path), $url_options);
 102  
 103        $options[$path] = strip_tags($argument->summary_name($row));
 104        if (!empty($this->options['count'])) {
 105          $options[$path] .= ' (' . intval($row->{$argument->count_alias}) . ')';
 106        }
 107        if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
 108          $default_value = $path;
 109        }
 110      }
 111  
 112      ctools_include('jump-menu');
 113      $settings = array(
 114        'hide' => $this->options['hide'],
 115        'button' => $this->options['text'],
 116        'choose' => $this->options['choose'],
 117        'default_value' => $default_value,
 118      );
 119  
 120      return drupal_get_form('ctools_jump_menu', $options, $settings);
 121    }
 122  }
 123  


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7