Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • A
  • Actions
  • Alert
  • AlterCSSClassNamesEvent
  • AssetsCollector
  • Button
  • CSSCollector
  • Dataset
  • Date
  • DateRange
  • DateTime
  • Decorator
  • Document
  • DropdownMenu
  • Element
  • File
  • Form
  • Group
  • Helpers
  • HTMLString
  • Iterator
  • JSCollector
  • ListView
  • ListViewColumn
  • Modal
  • Pager
  • Popover
  • PopoverWidget
  • Ranger
  • RecursiveIterator
  • Salutation
  • Searchbox
  • Section
  • SplitButton
  • Text
  • Widget

Interfaces

  • CSSClassNames
  • DecoratorInterface
  • HTMLStringInterface
  • Validator

Traits

  • CSSClassNamesProperty

Exceptions

  • ElementIsEmpty

Functions

  • _array_flatten_callback
  • array_flatten
  • array_insert
  • check_session
  • dump
  • escape
  • escape_all
  • format
  • format_size
  • get_accessible_file
  • get_document
  • normalize
  • render_css_class
  • render_exception
  • retrieve_form
  • retrieve_form_errors
  • shorten
  • stable_sort
  • store_form
  • store_form_errors
  • strip
  • t
  1 <?php
  2 
  3 /*
  4  * This file is part of the Brickrouge package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Brickrouge;
 13 
 14 class Pager extends Element
 15 {
 16     const T_COUNT = '#pager-count';
 17     const T_GAP = '#pager-gap';
 18     const T_LIMIT = '#pager-limit';
 19     const T_NO_ARROWS = '#pager-no-arrows';
 20     const T_POSITION = '#pager-position';
 21     const T_SEPARATOR = '#pager-separator';
 22     const T_URLBASE = '#pager-urlbase';
 23     const T_USING = '#pager-using';
 24     const T_WITH = '#pager-with';
 25     const BROWSE_PREVIOUS_LABEL = '#pagination-browse-previous-label';
 26     const BROWSE_NEXT_LABEL = '#pagination-browse-next-label';
 27 
 28     public function __construct($type, $tags)
 29     {
 30         parent::__construct
 31         (
 32             $type, $tags + array
 33             (
 34                 self::T_LIMIT => 5,
 35 //              self::T_SEPARATOR => '<span class="separator">,</span>',
 36                 self::T_GAP => '<span class="gap"> … </span>',
 37                 self::T_USING => 'page',
 38 
 39                 'class' => 'pagination'
 40             )
 41         );
 42     }
 43 
 44     protected $urlbase;
 45 
 46     public function render_inner_html()
 47     {
 48         $limit = $this[self::T_LIMIT];
 49         $count = $this[self::T_COUNT];
 50 
 51         $pages = ceil($count / $limit);
 52 
 53         $this->urlbase = $this->getURLBase();
 54 
 55         $gap = $this[self::T_GAP];
 56         $separator = $this[self::T_SEPARATOR];
 57 
 58         #
 59         #
 60         #
 61 
 62         // FIXME-20081113: prévoir index par offset
 63 
 64         $on_page = $this[self::T_POSITION] + 1;
 65 
 66         $rc = '';
 67 
 68         if ($pages > 10)
 69         {
 70             $init_page_max = min($pages, 3);
 71 
 72             for ($i = 1 ; $i < $init_page_max + 1 ; $i++)
 73             {
 74                 if ($i == $on_page)
 75                 {
 76                     $rc .= $this->getPosition($i);
 77                 }
 78                 else
 79                 {
 80                     $rc .= $this->getLink($i - 1);
 81                 }
 82 
 83                 if ($i < $init_page_max)
 84                 {
 85                     $rc .= $separator;
 86                 }
 87             }
 88 
 89             if ($pages > 3)
 90             {
 91                 if (($on_page > 1) && ($on_page < $pages))
 92                 {
 93                     $rc .= ($on_page > 5) ? $gap : $separator;
 94 
 95                     $init_page_min = ($on_page > 4) ? $on_page : 5;
 96                     $init_page_max = ($on_page < $pages - 4) ? $on_page : $pages - 4;
 97 
 98                     for ($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
 99                     {
100                         $rc .= ($i == $on_page) ? $this->getPosition($i) : $this->getLink($i - 1);
101 
102                         if ($i < $init_page_max + 1)
103                         {
104                             $rc .= $separator;
105                         }
106                     }
107 
108                     $rc .= ($on_page < $pages - 4) ? $gap : $separator;
109                 }
110                 else
111                 {
112                     $rc .= $gap;
113                 }
114 
115                 for ($i = $pages - 2 ; $i < $pages + 1 ; $i++)
116                 {
117                     $rc .= ($i == $on_page) ? $this->getPosition($i) : $this->getLink($i - 1);
118 
119                     if ($i < $pages)
120                     {
121                         $rc .= $separator;
122                     }
123                 }
124             }
125         }
126         else
127         {
128             for ($i = 1 ; $i < $pages + 1 ; $i++)
129             {
130                 $rc .= ($i == $on_page) ? $this->getPosition($i) : $this->getLink($i - 1);
131 
132                 if ($i < $pages)
133                 {
134                     $rc .= $separator;
135                 }
136             }
137         }
138 
139         if (!$this[self::T_NO_ARROWS])
140         {
141             #
142             # add next (>) link
143             #
144 
145             $next_text = $this[self::BROWSE_NEXT_LABEL];
146             $previous_text = $this[self::BROWSE_PREVIOUS_LABEL];
147 
148             if (!$next_text)
149             {
150                 $next_text = t('Next', array(), array('scope' => 'pagination.label', 'default' => 'Next →'));
151             }
152 
153             if (!$previous_text)
154             {
155                 $previous_text = t('Previous', array(), array('scope' => 'pagination.label', 'default' => '← Previous'));
156             }
157 
158 //          if ($this->reverse_arrows ? ($on_page > 1) : ($on_page < $pages))
159             if ($on_page < $pages)
160             {
161                 $rc .= $this->getLink($on_page, $next_text, 'next');
162 //              $rc .= $this->getLink($this->reverse_arrows ? $on_page - 2 : $on_page, '&gt;', 'next');
163             }
164             else
165             {
166                 $rc .= '<li class="next disabled"><a href="#">' . $next_text . '</a></li>';
167             }
168 
169 
170             #
171             # add prev (<) link
172             #
173 
174 //          if ($this->reverse_arrows ? ($on_page < $pages) : ($on_page > 1))
175             if ($on_page > 1)
176             {
177                 $rc = $this->getLink($on_page - 2, $previous_text, 'previous') . $rc;
178 //              $rc = $this->getLink($this->reverse_arrows ? $on_page : $on_page - 2, '&lt;', 'previous') . $rc;
179             }
180             else
181             {
182                 $rc = '<li class="previous disabled"><a href="#">' . $previous_text . '</a></li>' . $rc;
183             }
184         }
185 
186         return '<ul>' . $rc . '</ul>';
187     }
188 
189     public function __toString()
190     {
191         $limit = $this[self::T_LIMIT];
192 
193         if (!$limit)
194         {
195             return '';
196         }
197 
198         $count = $this[self::T_COUNT];
199 
200         $pages = ceil($count / $limit);
201 
202         if ($pages < 2)
203         {
204             return '';
205         }
206 
207         return parent::__toString();
208     }
209     /*
210     **
211 
212     IMPLEMENTS
213 
214     **
215     */
216 
217     protected function getURLBase()
218     {
219         $rc = $this[self::T_URLBASE];
220 
221         $with = $this[self::T_WITH];
222 
223         if ($with)
224         {
225             if (is_string($with))
226             {
227                 $parts = explode(',', $with);
228                 $parts = array_map('trim', $parts);
229                 $parts = array_flip($parts);
230 
231                 foreach ($parts as $name => &$part)
232                 {
233                     $part = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
234                 }
235             }
236             else
237             {
238                 $parts = (array) $with;
239             }
240         }
241         else
242         {
243             $parts = array();
244         }
245 
246         #
247         # add the 'using' part
248         #
249 
250         $using = $this[self::T_USING] ?: 'page';
251 
252         unset($parts[$using]);
253 
254         $parts[$using] = ''; // so that 'using' is at the end of the string
255 
256         #
257         # build the query
258         #
259 
260         $rc .= '?' . http_build_query
261         (
262             $parts, '', '&amp;'
263         );
264 
265         return $rc;
266     }
267 
268     protected function getURL($n)
269     {
270         return $this->urlbase . $n;
271     }
272 
273     protected function getLink($n, $label=null, $class='page')
274     {
275         $rc = '<li' . ($class ? ' class="' . $class . '"' : '') . '><a href="' . $this->getURL($n) . '">';
276         $rc .= $label ? $label : ($n + 1);
277         $rc .= '</a></li>';
278 
279         return $rc;
280     }
281 
282     protected function getPosition($n)
283     {
284         return '<li class="page active"><a href="#">' . $n . '</a></li>';
285     }
286 }
Autodoc API documentation generated by ApiGen 2.8.0