You are here

class views_plugin_pager_load_more in Views Load More 6.3

Same name and namespace in other branches
  1. 6 views_plugin_pager_load_more.inc \views_plugin_pager_load_more
  2. 7 views_plugin_pager_load_more.inc \views_plugin_pager_load_more

The plugin to handle full pager.

Hierarchy

Expanded class hierarchy of views_plugin_pager_load_more

2 string references to 'views_plugin_pager_load_more'
views_load_more_ajax_data_alter in ./views_load_more.module
Implementation of hook_ajax_data_alter().
views_load_more_views_plugins in ./views_load_more.views.inc
Implements hook_views_plugins

File

./views_plugin_pager_load_more.inc, line 12
Defines the load more pager plugin for Views.

View source
class views_plugin_pager_load_more extends views_plugin_pager_full {

  // Identifies changes to the exposed items per page value.
  private $exposed_limit_changed = FALSE;
  function summary_title() {
    if (!empty($this->options['offset'])) {
      return format_plural($this->options['items_per_page'], 'More pager, @count item, skip @skip', 'More pager, @count items, skip @skip', array(
        '@count' => $this->options['items_per_page'],
        '@skip' => $this->options['offset'],
      ));
    }
    return format_plural($this->options['items_per_page'], 'More pager, @count item', 'More pager, @count items', array(
      '@count' => $this->options['items_per_page'],
    ));
  }

  /**
   * Describes the options available from this Views plugin.
   */
  function option_definition() {

    // @TODO: Add waypoint support.
    $options = parent::option_definition();
    $options['load_more'] = array();
    $options['load_more']['link_text'] = array(
      'default' => 'Load More',
      'translatable' => TRUE,
    );
    $options['load_more']['pager_class'] = array(
      'default' => '',
      'translatable' => FALSE,
    );
    $options['load_more']['items_first_page'] = array(
      'default' => $this->options['items_per_page'],
    );
    return $options;
  }

  /**
   * Validates options set by the user.
   */
  function options_validate(&$form, &$form_state) {

    // Validate the "Load More" anchor text, if any is set.
    if (!empty($form_state['values']['pager_options']['load_more']['link_text'])) {

      // Obtain an HTML-free version of the link text.
      $link_text = filter_xss($form_state['values']['pager_options']['load_more']['link_text'], array());

      // If the cleaned link text doesn't match its source, HTML may exist.
      if (!$link_text || $link_text != $form_state['values']['pager_options']['load_more']['link_text']) {
        form_set_error('pager_options][load_more][link_text', t('The "Load More" anchor text should not contain HTML.'));
      }
    }

    // Validate the 'first page' result count.
    if (!empty($form_state['values']['pager_options']['load_more']['items_first_page'])) {

      // Ensure the user has entered a whole number.
      if (!is_numeric($form_state['values']['pager_options']['load_more']['items_first_page'])) {
        form_set_error('pager_options][load_more][items_first_page', t('Please enter a number.'));
      }
      elseif ($form_state['values']['pager_options']['load_more']['items_first_page'] <= 0 || !is_int((int) $form_state['values']['pager_options']['load_more']['items_first_page'])) {
        form_set_error('pager_options][load_more][items_first_page', t('Please enter a whole number greater than 0.'));
      }
    }

    // Check if a link class was supplied.
    if (!empty($form_state['values']['pager_options']['load_more']['pager_class'])) {

      // Obtain an HTML-free version of the link class.
      $pager_class = filter_xss($form_state['values']['pager_options']['load_more']['pager_class'], array());

      // If the cleaned link class doesn't match its source, HTML may exist.
      if (!$pager_class || $pager_class != $form_state['values']['pager_options']['load_more']['pager_class']) {
        form_set_error('pager_options][load_more][link_text', t('The "Load More" pager class should not contain HTML.'));
      }
    }
  }

  /**
   * Provides a form for setting options for this plugin.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['load_more'] = array(
      '#tree' => TRUE,
      '#weight' => -10,
    );

    // Give the user an option to change the anchor text.
    $form['load_more']['link_text'] = array(
      '#type' => 'textfield',
      '#title' => t('"Load More" Link Text'),
      '#description' => t('The link title that will be used for the "Load More" anchor. HTML is not permitted.'),
      '#default_value' => $this->options['load_more']['link_text'],
    );

    // Give the user an option to change the pager class.
    $form['load_more']['pager_class'] = array(
      '#type' => 'textfield',
      '#title' => t('"Load More" Pager class'),
      '#description' => t('Sets a custom class name on the "Load More" pager wrapper. HTML is not permitted.'),
      '#default_value' => $this->options['load_more']['pager_class'],
    );

    // Give the user an option to change the number of results on the first page.
    $form['load_more']['items_first_page'] = array(
      '#type' => 'textfield',
      '#title' => t('"Load More" Initial Count'),
      '#description' => t('The number of items to display on the first page. Subsequent pages will use the "items per page" setting.'),
      '#default_value' => $this->options['load_more']['items_first_page'],
    );

    // I'm not sure why someone might combine the exposed limit filter and a views_load_more pager, but it could happen.
    // @todo: If exposed limits were possible, how do we need to approach them?

    /***
       $form['expose']['items_per_page']['#disabled'] = TRUE;
       $form['expose']['items_per_page']['#default_value'] = 0;
       $form['expose']['items_per_page']['#description'] = t('The exposed Items per page settings are not compatible with a "Load More" pager.');
       $form['expose']['items_per_page_options_all']['#access'] = FALSE;
       $form['expose']['items_per_page_options_all']['#default_value'] = 0;
       $form['expose']['items_per_page_options_all_label']['#access'] = FALSE;
       /***/
  }

  /**
   * Modify the query.
   */
  function query() {

    // Let the full pager plugin process offsets, limits and pagination.
    parent::query();

    // Check if we want to display a different number of items on the first page of results.
    if (!empty($this->options['load_more']['items_first_page'])) {

      // Set the limit for the first page.
      if ($this->current_page == 0) {

        // Adjust the maximum number of items we'll load.
        $this->view->query
          ->set_limit($this->options['load_more']['items_first_page']);
      }
      else {

        // Ensure the current offset is known. If this value is empty or null, we need to force it to 0.
        $current_offset = (int) $this->view->query->offset;

        // Adjust the offset to account for our first page.
        $this->view->query
          ->set_offset($current_offset + $this->options['load_more']['items_first_page']);
      }
    }
  }

  /**
   * Processes this plugin for output.
   */
  function render($input) {

    // Find all the theme hook suggestions for the pager.
    $pager_theme = views_theme_functions('views_load_more_pager', $this->view, $this->display);

    // Collect some information about the view.
    // This will be passed into Drupal.settings.views_load_more
    // so javascript can act on the view.
    $settings = array(
      'css_class' => !empty($this->display->display_options['css_class']) ? $this
        ->_build_classname($this->display->display_options['css_class']) : '.view-content',
      'row_class' => !empty($this->display->display_options['style_options']['row_class']) ? $this
        ->_build_classname($this->display->display_options['style_options']['row_class']) : '.views-row',
      'pager_class' => !empty($this->options['load_more']['pager_class']) ? $this
        ->_build_classname($this->options['load_more']['pager_class']) : '.load-more-pager',
      'style_plugin' => $this->view->plugin_name,
      'total_items' => (int) $this->total_items,
    );

    // Get the number of items per page.
    $items_per_page = $this->options['items_per_page'];

    // If the number of items per page is different for the first page,
    // Adjust the pager's settings appropriately.
    if ($this->current_page == 0 && !empty($this->options['load_more']['items_first_page'])) {
      $items_per_page = $this->options['load_more']['items_first_page'];
    }
    return theme($pager_theme, $this->options['load_more']['link_text'], $items_per_page, $this->options['id'], $input, 9, $settings);
  }

  /**
   * Builds the classname selectors provided by options.
   * @param $class
   *  The classname string provided by an option.
   * @return
   *  Creates a css selector string out of the classname option provided.
   * @retval string
   */
  function _build_classname($class) {
    if (empty($class)) {
      return '';
    }
    $classnames = explode(' ', $class);
    return implode('.', $classnames);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_object::$definition property Handler's definition
views_object::$options property Except for displays, options for the object will be held here. 1
views_object::construct function Views handlers use a special construct function so that we can more easily construct them with variable arguments. 6
views_object::destroy function 2
views_object::export_option function 1
views_object::export_options function
views_object::options function Set default options on this object. Called by the constructor in a complex chain to deal with backward compatibility. 1
views_object::set_default_options function Set default options. For backward compatibility, it sends the options array; this is a feature that will likely disappear at some point.
views_object::set_definition function Let the handler know what its full definition is.
views_object::unpack_options function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable function Unpack a single option definition.
views_object::unpack_translatables function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults function
views_plugin::$display property The current used views display.
views_plugin::$plugin_type property The plugin type of this plugin, for example style or query.
views_plugin::$view property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions function Provide a list of additional theme functions for the theme information page
views_plugin::theme_functions function Provide a full list of possible theme templates used by this style.
views_plugin::validate function Validate that the plugin is correct and can be saved. 2
views_plugin_pager::$current_page property
views_plugin_pager::$total_items property
views_plugin_pager::execute_count_query function Execute the count query, which will be done just prior to the query itself being executed. 1
views_plugin_pager::exposed_form_submit function
views_plugin_pager::get_current_page function Get the current page.
views_plugin_pager::get_items_per_page function Get how many items per page this pager will display. 1
views_plugin_pager::get_offset function Get the page offset, or how many items to skip.
views_plugin_pager::get_pager_id function Get the pager id, if it exists
views_plugin_pager::get_total_items function Get the total number of items.
views_plugin_pager::has_more_records function Determine if there are more records available.
views_plugin_pager::init function Initialize the plugin. 1
views_plugin_pager::options_submit function Provide the default form form for submitting options Overrides views_plugin::options_submit
views_plugin_pager::post_execute function Perform any needed actions just after the query executing. 1
views_plugin_pager::pre_execute function Perform any needed actions just prior to the query executing.
views_plugin_pager::pre_render function Perform any needed actions just before rendering.
views_plugin_pager::set_items_per_page function Set how many items per page this pager will display.
views_plugin_pager::set_offset function Set the page offset, or how many items to skip.
views_plugin_pager::use_count_query function Determine if a pager needs a count query. 2
views_plugin_pager::use_pager function Determine if this pager actually uses a pager. 2
views_plugin_pager_full::exposed_form_alter function Overrides views_plugin_pager::exposed_form_alter
views_plugin_pager_full::exposed_form_validate function Overrides views_plugin_pager::exposed_form_validate
views_plugin_pager_full::get_pager_total function
views_plugin_pager_full::items_per_page_exposed function Overrides views_plugin_pager::items_per_page_exposed
views_plugin_pager_full::offset_exposed function Overrides views_plugin_pager::offset_exposed
views_plugin_pager_full::set_current_page function Set the current page. Overrides views_plugin_pager::set_current_page
views_plugin_pager_full::update_page_info function Update global paging info. Overrides views_plugin_pager::update_page_info
views_plugin_pager_full::uses_exposed function Overrides views_plugin_pager::uses_exposed
views_plugin_pager_load_more::$exposed_limit_changed private property
views_plugin_pager_load_more::options_form function Provides a form for setting options for this plugin. Overrides views_plugin_pager_full::options_form
views_plugin_pager_load_more::options_validate function Validates options set by the user. Overrides views_plugin_pager_full::options_validate
views_plugin_pager_load_more::option_definition function Describes the options available from this Views plugin. Overrides views_plugin_pager_full::option_definition
views_plugin_pager_load_more::query function Modify the query. Overrides views_plugin_pager_full::query
views_plugin_pager_load_more::render function Processes this plugin for output. Overrides views_plugin_pager_full::render
views_plugin_pager_load_more::summary_title function Return a string to display as the clickable title for the pager plugin. Overrides views_plugin_pager_full::summary_title
views_plugin_pager_load_more::_build_classname function Builds the classname selectors provided by options.