@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | private $pages_visibles; |
| 10 | 10 | private $row_count; |
| 11 | 11 | |
| 12 | - public function __construct($items_per_page=10,$pages_visibles=4,$page=1,$row_count=null){ |
|
| 12 | + public function __construct($items_per_page=10, $pages_visibles=4, $page=1, $row_count=null) { |
|
| 13 | 13 | $this->items_per_page=$items_per_page; |
| 14 | 14 | $this->row_count=$row_count; |
| 15 | 15 | $this->page=$page; |
@@ -17,29 +17,29 @@ discard block |
||
| 17 | 17 | $this->visible=true; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function getObjects($objects){ |
|
| 20 | + public function getObjects($objects) { |
|
| 21 | 21 | $auto=(!isset($this->row_count)); |
| 22 | 22 | $os=$objects; |
| 23 | - if(!\is_array($os)){ |
|
| 23 | + if (!\is_array($os)) { |
|
| 24 | 24 | $os=[]; |
| 25 | - foreach ($objects as $o){ |
|
| 25 | + foreach ($objects as $o) { |
|
| 26 | 26 | $os[]=$o; |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | - $this->page_count = 0; |
|
| 30 | - $row_count=($auto)?\sizeof($os):$this->row_count; |
|
| 31 | - if (0 === $row_count) { |
|
| 29 | + $this->page_count=0; |
|
| 30 | + $row_count=($auto) ? \sizeof($os) : $this->row_count; |
|
| 31 | + if (0===$row_count) { |
|
| 32 | 32 | $this->visible=false; |
| 33 | 33 | } else { |
| 34 | 34 | $this->visible=true; |
| 35 | - $this->page_count = (int)ceil($row_count / $this->items_per_page); |
|
| 36 | - if($this->page > $this->page_count+1) { |
|
| 37 | - $this->page = 1; |
|
| 35 | + $this->page_count=(int)ceil($row_count/$this->items_per_page); |
|
| 36 | + if ($this->page>$this->page_count+1) { |
|
| 37 | + $this->page=1; |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | - if($auto){ |
|
| 41 | - $offset = ($this->page - 1) * $this->items_per_page; |
|
| 42 | - return array_slice($os, $offset,$this->items_per_page); |
|
| 40 | + if ($auto) { |
|
| 41 | + $offset=($this->page-1)*$this->items_per_page; |
|
| 42 | + return array_slice($os, $offset, $this->items_per_page); |
|
| 43 | 43 | } |
| 44 | 44 | return $os; |
| 45 | 45 | } |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | return $this->page_count; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function getPagesNumbers(){ |
|
| 79 | - $middle= (int)ceil(($this->pages_visibles-1)/ 2); |
|
| 78 | + public function getPagesNumbers() { |
|
| 79 | + $middle=(int)ceil(($this->pages_visibles-1)/2); |
|
| 80 | 80 | $first=$this->page-$middle; |
| 81 | - if($first<1){ |
|
| 81 | + if ($first<1) { |
|
| 82 | 82 | $first=1; |
| 83 | 83 | } |
| 84 | 84 | $last=$first+$this->pages_visibles-1; |
| 85 | - if($last>$this->page_count){ |
|
| 85 | + if ($last>$this->page_count) { |
|
| 86 | 86 | $last=$this->page_count; |
| 87 | 87 | } |
| 88 | 88 | return \range($first, $last); |