Joostina CMS / CMF v2.* API
  • Docs
  • Package
  • Class
  • Tree
  • Todo
Overview

Packages

  • Components
    • Acls
      • Models
        • Admin
        • Site
    • BlogCategory
      • Models
        • Admin
        • Site
    • Blogs
      • Controllers
        • Admin
        • Site
      • Helpers
      • Models
        • Admin
        • Site
    • Coder
      • Controllers
        • Admin
      • Models
        • Admin
    • Comments
      • Controllers
        • Admin
        • Site
      • Helpers
      • Models
        • Admin
        • Site
    • CommentsCounter
      • Models
        • Admin
        • Site
    • Mainpage
      • Controllers
        • Site
    • News
      • Controllers
        • Admin
        • Site
      • Helpers
      • Models
        • Admin
        • Site
    • Pages
      • Controllers
        • Admin
        • Site
      • Models
        • Site
    • Search
      • Controllers
        • Site
    • Site
      • Controllers
        • Admin
        • Site
    • Sitemap
      • Controllers
        • Admin
        • Site
      • Models
        • Admin
        • Site
    • Test
      • Controllers
        • Site
    • Torrents
      • Controllers
        • Site
    • Users
      • Controllers
        • Admin
        • Site
      • Models
        • Admin
        • Site
  • Compression
  • Core
    • Libraries
      • Arhive
      • Array
      • Attached
      • Autoadmin
      • Autoloader
      • Benchmark
      • Breadcrumbs
      • Cache
      • Config
      • Cookie
      • Csrf
      • Database
        • Drivers
          • Interfaces
      • Datetime
      • Debug
      • Editor
      • Events
      • File
      • Filter
      • Flashmessage
      • Folder
      • Hit
      • Html
      • Image
      • Inflector
      • Inputfilter
      • Libraries
      • Mail
      • Module
      • Nestedset
      • Pager
      • Pages
      • Params
      • Randomizer
      • Request
      • RobotLoader
      • Route
      • Security
      • Session
      • Static
      • String
      • Text
      • Trash
      • Validate
  • Email
  • Extra
    • Libraries
      • Basket
  • Joostina
    • Controller
    • Core
    • Document
  • JSMin
  • Libraries
    • Extra
      • Basket
        • Models
          • Site
  • None
  • Plugins
    • Autoadmin
    • Editor
    • Sitemap
  • SimpleMail
  • Vendors
    • Libraries
      • Email

Classes

  • joosPager
  1: <?php defined('_JOOS_CORE') or exit();
  2: 
  3: /**
  4:  * Работа с постраничной навигацией
  5:  *
  6:  * @version    1.0
  7:  * @package    Core\Libraries
  8:  * @subpackage Pager
  9:  * @category   Libraries
 10:  * @author     Joostina Team <info@joostina.ru>
 11:  * @copyright  (C) 2007-2012 Joostina Team
 12:  * @license    MIT License http://www.opensource.org/licenses/mit-license.php
 13:  * Информация об авторах и лицензиях стороннего кода в составе Joostina CMS: docs/copyrights
 14:  *
 15:  * @todo    переписать joosPager на joosRoute и привести к общему виду
 16:  *
 17:  * @author     Leng Sheng Hong <darkredz@gmail.com>
 18:  * @link       http://www.doophp.com/
 19:  * @copyright  Copyright &copy; 2009 Leng Sheng Hong
 20:  * @license    http://www.doophp.com/license
 21:  *
 22:  * */
 23: class joosPager
 24: {
 25:     /**
 26:      * Contain the list of components to be used in view. (pages, jump menu, page_size, current_page, total_page)
 27:      *
 28:      * @var array
 29:      */
 30:     public $components;
 31:     /**
 32:      * Items to be displayed per page
 33:      *
 34:      * @var int
 35:      */
 36:     public $item_per_page = 10;
 37:     /**
 38:      * The current page number
 39:      *
 40:      * @var int
 41:      */
 42:     public $current_page = 1;
 43:     /**
 44:      * Maximum Pager length
 45:      *
 46:      * @var int
 47:      */
 48:     public $max_length = 10;
 49:     /**
 50:      * Total items to be split in the pagination
 51:      *
 52:      * @var int
 53:      */
 54:     public $total_item;
 55:     /**
 56:      * Total pages in the pagination
 57:      *
 58:      * @var int
 59:      */
 60:     public $total_page;
 61:     /**
 62:      * The pages HTML output
 63:      *
 64:      * @var string
 65:      */
 66:     public $output;
 67:     /**
 68:      * The URL prefix for all the pagination links
 69:      *
 70:      * @var string
 71:      */
 72:     public $base_url;
 73:     //----- for SQL use -----
 74:     /**
 75:      * Position of the record to begin the pagination LIMIT query
 76:      *
 77:      * @var string
 78:      */
 79:     public $low;
 80:     /**
 81:      * Position of the record to end the pagination LIMIT query
 82:      *
 83:      * @var string
 84:      */
 85:     public $high;
 86:     /**
 87:      * To be use with the pagination LIMIT query LIMIT $limit
 88:      *
 89:      * @var string
 90:      */
 91:     public $limit;
 92:     public $offset;
 93:     /**
 94:      * @var string
 95:      */
 96:     private $_output;
 97: 
 98:     public function __construct($base_url = '', $total_items = 120, $item_per_page = 10, $max_length = 11, $extra_url = '')
 99:     {
100:         $this->base_url = $base_url;
101:         $this->base_url = $extra_url ? $this->base_url . $extra_url : $this->base_url;
102:         $this->total_item = $total_items;
103:         $this->max_length = $max_length;
104:         $this->item_per_page = $item_per_page;
105:     }
106: 
107:     public function paginate($page, $item_per_page = 0)
108:     {
109:         if ($item_per_page === 0) {
110:             $item_per_page = $this->item_per_page;
111:         } else {
112:             $this->item_per_page = $item_per_page;
113:         }
114: 
115:         $this->total_page = ceil($this->total_item / $item_per_page);
116: 
117:         $this->current_page = (int) $page;
118: 
119:         if ($this->current_page < 1 || !is_numeric($this->current_page)) {
120:             $this->current_page = 1;
121:         }
122: 
123:         if ($this->current_page > $this->total_page) {
124:             $this->current_page = $this->total_page;
125:         }
126: 
127:         $prev_page = $this->current_page - 1;
128:         $next_page = $this->current_page + 1;
129: 
130:         $this->_output .= '';
131: 
132:         //-----------------------------------------------------------------------------------------------"НАЗАД"
133:         $_prev = "<a class=\"page_left\" href=\"{$this->base_url}/page/{$prev_page}\">&larr;</a>";
134:         $_class = ($this->current_page != 1) ? '' : ' class="disabled"';
135:         $this->components['prev'] = '<li' . $_class . '>' . $_prev . '</li>';
136: 
137:         //Вывод джампером (с разрывом, если кол-во страниц > допустимого интервала)
138:         if ($this->total_page > $this->max_length) {
139:             $midRange = $this->max_length - 2;
140: 
141:             $start_range = $this->current_page - floor($midRange / 2);
142:             $end_range = $this->current_page + floor($midRange / 2);
143: 
144:             if ($start_range <= 0) {
145:                 $end_range += abs($start_range) + 1;
146:                 $start_range = 1;
147:             }
148: 
149:             if ($end_range > $this->total_page) {
150:                 $start_range -= $end_range - $this->total_page;
151:                 $end_range = $this->total_page;
152:             }
153: 
154:             while ($end_range - $start_range + 1 < $this->max_length - 1) {
155:                 $end_range++;
156:             }
157: 
158:             $modulus = (int) $this->max_length % 2 == 0;
159:             $center = floor($this->max_length / 2);
160: 
161:             if ($this->current_page > $center) {
162:                 $end_range--;
163:             }
164: 
165:             if ($modulus == 0 && $this->total_page - $this->current_page + 1 <= $center) {
166:                 while ($end_range - $start_range + 1 < $this->max_length - 1) {
167:                     $start_range--;
168:                 }
169:             }
170:             $range = range($start_range, $end_range);
171: 
172:             for ($i = 1; $i <= $this->total_page; $i++) {
173:                 if ($i == 1 || $i == $this->total_page || in_array($i, $range)) {
174:                     $lastDot = '';
175: 
176:                     if ($modulus == 1) {
177:                         if ($i == $this->total_page && $this->current_page < ($this->total_page - ($this->max_length - $center - $modulus))) {
178:                             $lastDot = '...';
179:                         }
180:                     } else {
181:                         if ($i == $this->total_page && $this->current_page <= ($this->total_page - ($this->max_length - $center))) {
182:                             $lastDot = '...';
183:                         }
184:                     }
185: 
186:                     //-----------------------------------------------------------------------------НОМЕРА СТРАНИЦ
187:                     $_number = "<a href=\"{$this->base_url}/page/$i\">$lastDot $i";
188: 
189:                     if ($range[0] > 2 && $i == 1) {
190:                         $_number .= " ...</a>";
191:                     } else {
192:                         $_number .= '</a>';
193:                     }
194: 
195:                     $_class = ($i == $this->current_page) ? ' class="active"' : '';
196:                     $this->_output .= '<li' . $_class . '>' . $_number . '</li>';
197:                 }
198:             }
199: 
200:             //-----------------------------------------------------------------------------"ВПЕРЕД"
201:             $_next = "<a class=\"page_right\"  href=\"{$this->base_url}/page/$next_page\">&rarr;</a>";
202:             $_class = ($this->current_page != $this->total_page && $this->total_item >= $this->max_length) ? '' : ' class="disabled"';
203:             $this->components['next'] = '<li' . $_class . '>' . $_next . '</li>';
204: 
205:         } else {
206:             //-----------------------------------------------------------------------------НОМЕРА СТРАНИЦ
207:             for ($i = 1; $i <= $this->total_page; $i++) {
208:                 $_number = "<a href=\"{$this->base_url}/page/$i\">$i</a>";
209:                 $_class = ($i == $this->current_page) ? ' class="active"' : '';
210:                 $this->_output .= '<li' . $_class . '>' . $_number . '</li>';
211:             }
212: 
213:             //-----------------------------------------------------------------------------"ВПЕРЕД"
214:             $_next = "<a class=\"page_right\"  href=\"{$this->base_url}/page/$next_page\">&rarr;</a>";
215: 
216:             $_class = ($this->current_page != $this->total_page) ? '' : ' class="disabled"';
217:             $this->components['next'] = '<li' . $_class . '>' . $_next . '</li>';
218: 
219:         }
220: 
221:         $this->low = ($this->current_page - 1) * $this->item_per_page;
222:         $this->high = ($this->current_page * $this->item_per_page) - 1;
223:         $this->low = $this->low < 0 ? 0 : $this->low;
224:         $this->limit = $this->item_per_page;
225:         $this->offset = $this->low;
226: 
227:         $this->components['current_page'] = $this->current_page;
228:         $this->components['total_page'] = $this->total_page;
229: 
230:         $this->output = '<div class="pagination"><ul>' . $this->components['prev'] . $this->_output . $this->components['next'] . '</ul></div>';
231: 
232:         $this->output = $this->total_item > 0 && $this->total_page > 1 ? $this->output : '';
233: 
234:         $this->components['pages'] = $this->output;
235: 
236:         return $this->components;
237:     }
238: 
239: }
240: 
Joostina CMS / CMF v2.* API API documentation generated by ApiGen 2.6.1 – Template adapted by @olvlv and Joostina Team