You are here

protected function alpha_pagination_handler_pagination::getItems in Views Alpha Pagination 7

Retrieves the items used to populate the pagination item list.

Return value

array An associative array containing the result state as the value, keyed by the letter, number or "all".

1 call to alpha_pagination_handler_pagination::getItems()
alpha_pagination_handler_pagination::render in views/alpha_pagination_handler_pagination.inc
Render the alphabetic paginator

File

views/alpha_pagination_handler_pagination.inc, line 483
Definition of alpha_pagination_handler_pagination.

Class

alpha_pagination_handler_pagination
Views area handler to display an alphabetic pagination representive of the entire result set for this view and not just the limited number being displayed by the view's configuration

Code

protected function getItems() {

  // Bring in our global language variable.
  global $language;

  // Check to see if this query is cached. If it is, then just pull our
  // results set from it so that things can move quickly through here. We're
  // caching in the event the view has a very large result set.
  $cid = $this
    ->getCid();
  if (($cache = cache_get($cid)) && !empty($cache->data)) {
    return $cache->data;
  }

  // Construct the alphabet pagination items.
  $items = range('A', 'Z');

  // Add arabic alphabet when website's language is in arabic
  if ($language->language == 'ar') {
    $items = array(
      'ا',
      'ب',
      'ت',
      'ث',
      'ج',
      'ح',
      'خ',
      'د',
      'ذ',
      'ر',
      'ز',
      'س',
      'ش',
      'ص',
      'ض',
      'ط',
      'ظ',
      'ع',
      'غ',
      'ف',
      'ق',
      'ك',
      'ل',
      'م',
      'ن',
      'و',
      'ه',
      'ي',
    );
  }

  // Append or prepend numeric items.
  if (!empty($this->options['paginate_view_numbers'])) {
    if ($this->options['paginate_numeric_position'] === 'after') {
      $items = array_merge($items, range('0', '9'));
    }
    else {
      $items = array_merge(range('0', '9'), $items);
    }
  }

  // Append or prepend the "all" item.
  if (!empty($this->options['paginate_all_display'])) {
    if ($this->options['paginate_all_position'] === 'before') {
      $items = array_merge(array(
        'all',
      ), $items);
    }
    else {
      $items[] = 'all';
    }
  }

  // Initialize the results with FALSE values so each prefix is disabled by
  // default. They're later filled in as TRUE below when there is actual
  // entity prefixes that exist.
  $results = array_fill_keys($items, FALSE);

  // Retrieve the entity prefixes.
  if ($prefixes = $this
    ->getEntityPrefixes()) {

    // Ensure that "all" is TRUE if there are prefixes.
    if (isset($results['all'])) {
      $results['all'] = TRUE;
    }

    // Set prefixes to TRUE if it exists from the default list that was
    // constructed from view options above.
    foreach ($prefixes as $prefix) {
      if (isset($results[$prefix])) {
        $results[$prefix] = TRUE;
      }
    }
  }

  // Cache the results.
  cache_set($cid, $results, 'cache');
  return $results;
}