Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Paginator
- {
- public $items_count = 0;
- public $page_size = 0;
- public $page_number = 0;
- public $pages_count = 0;
- public $sql_limit_from = 0;
- public $sql_limit_count = 0;
- public $array_start_index = 0;
- public $array_end_index = 0;
- public $page_numbers = array();
- public $active_page_number = 0;
- public function __construct($iItemsCount, $iPageSize, $iPageNumber)
- {
- $this->items_count = $iItemsCount;
- $this->page_size = $iPageSize;
- $this->page_number = $iPageNumber;
- $this->_compute_pages_count();
- $this->_compute_array_indices();
- $this->_compute_sql_limit();
- $this->_make_page_numbers();
- $this->active_page_number = $iPageNumber;
- }
- private function _compute_pages_count()
- {
- $this->pages_count = (int) ($this->items_count / $this->page_size);
- if ($this->items_count % $this->page_size > 0)
- {
- $this->pages_count += 1;
- }
- }
- private function _compute_array_indices()
- {
- $preliminary_array_start_index = $this->page_size * ($this->page_number - 1);
- if ($preliminary_array_start_index < $this->items_count)
- {
- $this->array_start_index = $preliminary_array_start_index;
- }
- else
- {
- $this->array_start_index = 0; //DO WELL . IMPLEMENT GOOD NUMBERS INDICATOR?
- }
- $preliminary_array_end_index = $this->page_size * ($this->page_number - 1) + $this->page_size - 1;
- if ($preliminary_array_end_index < $this->items_count)
- {
- $this->array_end_index = $preliminary_array_end_index;
- }
- else
- {
- $this->array_end_index = $this->items_count - 1;
- }
- }
- private function _compute_sql_limit()
- {
- $this->sql_limit_from = $this->page_size * ($this->page_number - 1);
- $this->sql_limit_count = $this->page_size;
- }
- private function _make_page_numbers()
- {
- $this->page_numbers = array();
- for ($number = 1; $number <= $this->pages_count; $number += 1)
- {
- $this->page_numbers[] = $number;
- }
- }
- }
Add Comment
Please, Sign In to add comment