You are here

class ViewsShowMorePlugin in Views Show More 7

Same name and namespace in other branches
  1. 7.2 views_plugin_pager_show_more.inc \ViewsShowMorePlugin

@file Extend Full Pager plugin to create show more pager.

Hierarchy

Expanded class hierarchy of ViewsShowMorePlugin

2 string references to 'ViewsShowMorePlugin'
views_show_more_views_ajax_data_alter in ./views_show_more.module
Implements hook_views_ajax_data_alter().
views_show_more_views_plugins in ./views_show_more.views.inc
Implements hook_views_plugins().

File

./views_plugin_pager_show_more.inc, line 8
Extend Full Pager plugin to create show more pager.

View source
class ViewsShowMorePlugin extends views_plugin_pager_full {

  /**
   * Summary title overwrite.
   */
  function summary_title() {
    $count = !empty($this->options['offset']) ? $this->options['offset'] : $this->options['items_per_page'];
    return format_plural($count, 'Initial @skip item, ', 'Initial @skip items, ', array(
      '@skip' => $count,
    )) . format_plural($this->options['items_per_page'], 'Per click @count item', 'Per click @count items', array(
      '@count' => $this->options['items_per_page'],
    ));
  }

  /**
   * Options definition overwrite.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['result_display_method'] = array(
      'default' => 'append',
    );
    $options['show_more_text'] = array(
      'default' => t('Show more'),
      'translatable' => TRUE,
    );
    $options['show_more_empty_text'] = array(
      'default' => '',
      'translatable' => TRUE,
    );
    $options['effects'] = array(
      'contains' => array(
        'type' => array(
          'default' => 'none',
        ),
        'speed_type' => array(
          'default' => '',
        ),
        'speed' => array(
          'default' => '',
        ),
        'speed_value' => array(
          'default' => '',
        ),
      ),
    );
    $options['advance'] = array(
      'contains' => array(
        'content_selector' => array(
          'default' => '',
        ),
        'pager_selector' => array(
          'default' => '',
        ),
      ),
    );
    return $options;
  }

  /**
   * Options form overwrite.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $exclude = array(
      'total_pages',
      'quantity',
      'expose',
      'tags',
    );
    foreach ($exclude as $ex) {
      unset($form[$ex]['#title']);
      unset($form[$ex]['#description']);
      $form[$ex]['#attributes'] = array(
        'class' => array(
          'element-invisible',
        ),
      );
    }
    $form['items_per_page']['#description'] = t('The number of items to display per show more click.');
    $form['offset']['#title'] = t('Initial items');
    $form['offset']['#description'] = t('The number of items to display initially. Enter 0 for use same as items per page (show more click).');

    // Result display method.
    $form['result_display_method'] = array(
      '#type' => 'select',
      '#title' => t('Result display method'),
      '#description' => t('<strong>Append</strong> result display method append the new content after the existing content on the page in ajax mode and in no-ajax mode replace the content by page refresh. <strong>Replace</strong> result display method replace the content with new content both in ajax and no-ajax mode. In no-ajax mode it refresh the page.'),
      '#options' => array(
        'append' => t('Append'),
        'html' => t('Replace'),
      ),
      '#default_value' => $this->options['result_display_method'] ? $this->options['result_display_method'] : 'append',
      '#weight' => -1,
    );

    // Option for users to specify the text used on the 'show more' button.
    $form['show_more_text'] = array(
      '#type' => 'textfield',
      '#title' => t('Show more pager link text'),
      '#description' => t('Text for the button which used to load more items. Like "Show More".'),
      '#default_value' => $this->options['show_more_text'] ? $this->options['show_more_text'] : t('Show more'),
      '#weight' => -1,
    );

    // Option for users to specify the text used on the 'show more' button
    // when no mor result is found.
    $form['show_more_empty_text'] = array(
      '#type' => 'textfield',
      '#title' => t('Show more pager link text when empty'),
      '#description' => t('Empty text when no more items exist to load. Like "No more results".'),
      '#default_value' => $this->options['show_more_empty_text'] ? $this->options['show_more_empty_text'] : '',
      '#weight' => -1,
    );

    // Affect the way that Views Load More adds new rows.
    $form['effects'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#title' => t('Animation'),
      '#input' => TRUE,
    );
    $form['effects']['type'] = array(
      '#type' => 'select',
      '#options' => array(
        'none' => t('None'),
        'fade' => t('FadeIn'),
        'scroll' => t('Scroll to New Content'),
        'scroll_fade' => t('Scroll to New Content & FadeIn'),
      ),
      '#default_vaue' => 'none',
      '#title' => t('Animation Type'),
      '#default_value' => $this->options['effects']['type'],
    );
    $form['effects']['speed_type'] = array(
      '#type' => 'select',
      '#options' => array(
        'slow' => t('Slow'),
        'fast' => t('Fast'),
        'custom' => t('Custom'),
      ),
      '#states' => array(
        'visible' => array(
          '#edit-pager-options-effects-type' => array(
            array(
              'value' => 'fade',
            ),
            array(
              'value' => 'scroll',
            ),
            array(
              'value' => 'scroll_fade',
            ),
          ),
        ),
      ),
      '#title' => t('Animation Speed'),
      '#default_value' => $this->options['effects']['speed_type'],
    );
    $form['effects']['speed_value'] = array(
      '#type' => 'textfield',
      '#title' => t('Animation speed in ms'),
      '#states' => array(
        'visible' => array(
          '#edit-pager-options-effects-speed-type' => array(
            'value' => 'custom',
          ),
        ),
      ),
      '#default_value' => $this->options['effects']['speed_value'],
      '#element_validate' => array(
        'element_validate_integer_positive',
      ),
    );

    // Advanced options, override default selectors.
    $form['advance'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#title' => t('Advanced Options'),
      '#input' => TRUE,
    );

    // Option to specify the content_selector, which is the wrapping div for
    // views rows. This allows the JS to both find new rows on next pages and
    // know where to put them in the page.
    $form['advance']['content_selector'] = array(
      '#type' => 'textfield',
      '#title' => t('Content jquery selector'),
      '#description' => t('jQuery selector for the rows wrapper, relative to the view container. Use when you override the views markup. Views Show More pager requires a wrapping element for the rows.  Default <strong><code>&gt; .view-content</code></strong>.'),
      '#default_value' => $this->options['advance']['content_selector'],
    );

    // Option to specify the pager_selector, which is the pager relative to the
    // view container.
    $form['advance']['pager_selector'] = array(
      '#type' => 'textfield',
      '#title' => t('Pager jquery selector'),
      '#description' => t('jQuery selector for the pager, relative to the view container. Use when you override the pager markup. Default <strong><code>.pager-show-more</code></strong>.'),
      '#default_value' => $this->options['advance']['pager_selector'],
    );
  }

  /**
   * Options form validate.
   */
  function options_validate(&$form, &$form_state) {
    $effect_speed = $form_state['values']['pager_options']['effects']['speed_type'];
    $effect_speed_val = $form_state['values']['pager_options']['effects']['speed_value'];
    if ($effect_speed == 'custom') {
      if ($effect_speed_val == '') {
        form_set_error('pager_options][effects][speed_value', t('Animation speed is required.'));
      }
      else {
        $form_state['values']['pager_options']['effects']['speed'] = $effect_speed_val;
      }
    }
    else {
      $form_state['values']['pager_options']['effects']['speed'] = $effect_speed;
    }
  }

  /**
   * Query overwrite.
   */
  function query() {
    parent::query();
    $others_page = $this->options['items_per_page'];
    $limit = !empty($this->options['offset']) ? $this->options['offset'] : $others_page;
    $offset = 0;

    // Change limit & offset for others.
    if ($this->current_page != 0) {
      $offset = $limit + ($this->current_page - 1) * $others_page;
      $limit = $others_page;
    }
    $this->view->query
      ->set_limit($limit);
    $this->view->query
      ->set_offset($offset);
  }

  /**
   * Render overwrite.
   */
  function render($input) {
    $pager_theme = views_theme_functions('pager_show_more', $this->view, $this->display);
    $output = theme($pager_theme, array(
      'parameters' => $input,
      'element' => $this->options['id'],
      'result_display_method' => $this->options['result_display_method'],
      'show_more_text' => $this->options['show_more_text'],
      'show_more_empty_text' => $this->options['show_more_empty_text'],
    ));
    return $output;
  }

  /**
   * Get pager total count.
   */
  function get_pager_total() {
    if ($items_per_page = intval($this
      ->get_items_per_page())) {
      if ($initial_items = intval($this
        ->get_offset())) {
        return 1 + ceil(($this->total_items - $initial_items) / $items_per_page);
      }
      else {
        return ceil($this->total_items / $items_per_page);
      }
    }
    else {
      return 1;
    }
  }

  /**
   * Execute the count query, which will be done just prior to the query
   * itself being executed.
   */
  function execute_count_query(&$count_query) {
    $this->total_items = $count_query
      ->execute()
      ->fetchField();
    $this
      ->update_page_info();
    return $this->total_items;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsShowMorePlugin::execute_count_query function Execute the count query, which will be done just prior to the query itself being executed. Overrides views_plugin_pager::execute_count_query
ViewsShowMorePlugin::get_pager_total function Get pager total count. Overrides views_plugin_pager_full::get_pager_total
ViewsShowMorePlugin::options_form function Options form overwrite. Overrides views_plugin_pager_full::options_form
ViewsShowMorePlugin::options_validate function Options form validate. Overrides views_plugin_pager_full::options_validate
ViewsShowMorePlugin::option_definition function Options definition overwrite. Overrides views_plugin_pager_full::option_definition
ViewsShowMorePlugin::query function Query overwrite. Overrides views_plugin_pager_full::query
ViewsShowMorePlugin::render function Render overwrite. Overrides views_plugin_pager_full::render
ViewsShowMorePlugin::summary_title function Summary title overwrite. Overrides views_plugin_pager_full::summary_title
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_pager::$current_page public property
views_plugin_pager::$total_items public property
views_plugin_pager::exposed_form_submit public function
views_plugin_pager::get_current_page public function Get the current page.
views_plugin_pager::get_items_per_page public function Get how many items per page this pager will display. 1
views_plugin_pager::get_offset public function Get the page offset, or how many items to skip.
views_plugin_pager::get_pager_id public function Get the pager id, if it exists.
views_plugin_pager::get_total_items public function Get the total number of items.
views_plugin_pager::has_more_records public function Determine if there are more records available.
views_plugin_pager::init public function Initialize the plugin. 1
views_plugin_pager::options_submit public function Provide the default form form for submitting options. Overrides views_plugin::options_submit
views_plugin_pager::post_execute public function Perform any needed actions just after the query executing. 1
views_plugin_pager::pre_execute public function Perform any needed actions just prior to the query executing.
views_plugin_pager::pre_render public function Perform any needed actions just before rendering.
views_plugin_pager::set_items_per_page public function Set how many items per page this pager will display.
views_plugin_pager::set_offset public function Set the page offset, or how many items to skip.
views_plugin_pager::use_count_query public function Determine if a pager needs a count query. 2
views_plugin_pager::use_pager public function Determine if this pager actually uses a pager. 2
views_plugin_pager_full::exposed_form_alter public function Overrides views_plugin_pager::exposed_form_alter
views_plugin_pager_full::exposed_form_validate public function Overrides views_plugin_pager::exposed_form_validate
views_plugin_pager_full::items_per_page_exposed public function Overrides views_plugin_pager::items_per_page_exposed
views_plugin_pager_full::offset_exposed public function Overrides views_plugin_pager::offset_exposed
views_plugin_pager_full::set_current_page public function Set the current page. Overrides views_plugin_pager::set_current_page
views_plugin_pager_full::update_page_info public function Update global paging info. Overrides views_plugin_pager::update_page_info
views_plugin_pager_full::uses_exposed public function Overrides views_plugin_pager::uses_exposed