Projet

Général

Profil

Paste
Télécharger (5,24 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / system / pager.func.php @ 7547bb19

1
<?php
2
/**
3
 * @file
4
 * Stub file for bootstrap_pager().
5
 */
6

    
7
/**
8
 * Returns HTML for a query pager.
9
 *
10
 * Menu callbacks that display paged query results should call theme('pager') to
11
 * retrieve a pager control so that users can view other results. Format a list
12
 * of nearby pages with additional query results.
13
 *
14
 * @param array $variables
15
 *   An associative array containing:
16
 *   - tags: An array of labels for the controls in the pager.
17
 *   - element: An optional integer to distinguish between multiple pagers on
18
 *     one page.
19
 *   - parameters: An associative array of query string parameters to append to
20
 *     the pager links.
21
 *   - quantity: The number of pages in the list.
22
 *
23
 * @return string
24
 *   The constructed HTML.
25
 *
26
 * @see theme_pager()
27
 *
28
 * @ingroup theme_functions
29
 */
30
function bootstrap_pager($variables) {
31
  $output = "";
32
  $items = array();
33
  $tags = $variables['tags'];
34
  $element = $variables['element'];
35
  $parameters = $variables['parameters'];
36
  $quantity = $variables['quantity'];
37

    
38
  global $pager_page_array, $pager_total;
39

    
40
  // Calculate various markers within this pager piece:
41
  // Middle is used to "center" pages around the current page.
42
  $pager_middle = ceil($quantity / 2);
43
  // Current is the page we are currently paged to.
44
  $pager_current = $pager_page_array[$element] + 1;
45
  // First is the first page listed by this pager piece (re quantity).
46
  $pager_first = $pager_current - $pager_middle + 1;
47
  // Last is the last page listed by this pager piece (re quantity).
48
  $pager_last = $pager_current + $quantity - $pager_middle;
49
  // Max is the maximum page number.
50
  $pager_max = $pager_total[$element];
51

    
52
  // Prepare for generation loop.
53
  $i = $pager_first;
54
  if ($pager_last > $pager_max) {
55
    // Adjust "center" if at end of query.
56
    $i = $i + ($pager_max - $pager_last);
57
    $pager_last = $pager_max;
58
  }
59
  if ($i <= 0) {
60
    // Adjust "center" if at start of query.
61
    $pager_last = $pager_last + (1 - $i);
62
    $i = 1;
63
  }
64

    
65
  // End of generation loop preparation.
66
  $li_first = theme('pager_first', array(
67
    'text' => (isset($tags[0]) ? $tags[0] : t('first')),
68
    'element' => $element,
69
    'parameters' => $parameters,
70
  ));
71
  $li_previous = theme('pager_previous', array(
72
    'text' => (isset($tags[1]) ? $tags[1] : t('previous')),
73
    'element' => $element,
74
    'interval' => 1,
75
    'parameters' => $parameters,
76
  ));
77
  $li_next = theme('pager_next', array(
78
    'text' => (isset($tags[3]) ? $tags[3] : t('next')),
79
    'element' => $element,
80
    'interval' => 1,
81
    'parameters' => $parameters,
82
  ));
83
  $li_last = theme('pager_last', array(
84
    'text' => (isset($tags[4]) ? $tags[4] : t('last')),
85
    'element' => $element,
86
    'parameters' => $parameters,
87
  ));
88
  if ($pager_total[$element] > 1) {
89

    
90
    // Only show "first" link if set on components' theme setting
91
    if ($li_first && bootstrap_setting('pager_first_and_last')) {
92
      $items[] = array(
93
        'class' => array('pager-first'),
94
        'data' => $li_first,
95
      );
96
    }
97
    if ($li_previous) {
98
      $items[] = array(
99
        'class' => array('prev'),
100
        'data' => $li_previous,
101
      );
102
    }
103
    // When there is more than one page, create the pager list.
104
    if ($i != $pager_max) {
105
      if ($i > 1) {
106
        $items[] = array(
107
          'class' => array('pager-ellipsis', 'disabled'),
108
          'data' => '<span>…</span>',
109
        );
110
      }
111
      // Now generate the actual pager piece.
112
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
113
        if ($i < $pager_current) {
114
          $items[] = array(
115
            // 'class' => array('pager-item'),
116
            'data' => theme('pager_previous', array(
117
              'text' => $i,
118
              'element' => $element,
119
              'interval' => ($pager_current - $i),
120
              'parameters' => $parameters,
121
            )),
122
          );
123
        }
124
        if ($i == $pager_current) {
125
          $items[] = array(
126
            // Add the active class.
127
            'class' => array('active'),
128
            'data' => "<span>$i</span>",
129
          );
130
        }
131
        if ($i > $pager_current) {
132
          $items[] = array(
133
            'data' => theme('pager_next', array(
134
              'text' => $i,
135
              'element' => $element,
136
              'interval' => ($i - $pager_current),
137
              'parameters' => $parameters,
138
            )),
139
          );
140
        }
141
      }
142
      if ($i < $pager_max) {
143
        $items[] = array(
144
          'class' => array('pager-ellipsis', 'disabled'),
145
          'data' => '<span>…</span>',
146
        );
147
      }
148
    }
149
    // End generation.
150
    if ($li_next) {
151
      $items[] = array(
152
        'class' => array('next'),
153
        'data' => $li_next,
154
      );
155
    }
156
    // // Only show "last" link if set on components' theme setting
157
    if ($li_last && bootstrap_setting('pager_first_and_last')) {
158
      $items[] = array(
159
       'class' => array('pager-last'),
160
       'data' => $li_last,
161
      );
162
    }
163

    
164
    $build = array(
165
      '#theme_wrappers' => array('container__pager'),
166
      '#attributes' => array(
167
        'class' => array(
168
          'text-center',
169
        ),
170
      ),
171
      'pager' => array(
172
        '#theme' => 'item_list',
173
        '#items' => $items,
174
        '#attributes' => array(
175
          'class' => array('pagination'),
176
        ),
177
      ),
178
    );
179
    return drupal_render($build);
180
  }
181
  return $output;
182
}