@@ -171,10 +171,10 @@ class Pagination
171
171
/**
172
172
* Stores the generated pagination structure.
173
173
*
174
- * @var string
174
+ * @var array
175
175
*/
176
176
protected $ pages = null ;
177
-
177
+
178
178
/**
179
179
* Constructor class.
180
180
*/
@@ -274,7 +274,7 @@ public function large()
274
274
275
275
return $ this ;
276
276
}
277
-
277
+
278
278
/**
279
279
* Sets the Bootstrap 4 alignment class to left.
280
280
*
@@ -311,20 +311,6 @@ public function alignRight()
311
311
return $ this ;
312
312
}
313
313
314
- /**
315
- * Sets the show separator flag to true.
316
- *
317
- * Shows the separator blocks.
318
- *
319
- * @return PHPPagination
320
- */
321
- public function showSeparator ()
322
- {
323
- $ this ->show_separator = true ;
324
-
325
- return $ this ;
326
- }
327
-
328
314
/**
329
315
* Sets the show separator flag to false.
330
316
*
@@ -579,7 +565,7 @@ protected function buildURL($page)
579
565
}
580
566
581
567
if ($ this ->fragment_query_string ) {
582
- $ url .= '# ' . $ this ->fragment_query_string ;
568
+ $ url .= '# ' . $ this ->fragment_query_string ;
583
569
}
584
570
585
571
return $ url ;
@@ -624,71 +610,71 @@ protected function pageText($page_text)
624
610
*/
625
611
protected function generate ()
626
612
{
627
- $ this -> total_pages = $ this ->items_per_page != 0 ? ceil ($ this ->total_items / $ this ->items_per_page ) : 0 ;
613
+ $ total_pages = $ this ->items_per_page != 0 ? ceil ($ this ->total_items / $ this ->items_per_page ) : 0 ;
628
614
629
- if ($ this -> total_pages <= 1 ) {
615
+ if ($ total_pages <= 1 ) {
630
616
$ this ->pages = [];
631
617
632
618
return $ this ->pages ;
633
619
}
634
620
635
621
$ pages = [];
636
622
$ this ->pages = [];
637
- $ this -> prev_page = $ this ->page - 1 ;
638
- $ this -> next_page = $ this ->page + 1 ;
623
+ $ prev_page = $ this ->page - 1 ;
624
+ $ next_page = $ this ->page + 1 ;
639
625
640
- $ this -> prev_page = $ this -> prev_page > 0 ? $ this -> prev_page : 0 ;
641
- $ this -> next_page = $ this -> next_page <= $ this -> total_pages ? $ this -> next_page : 0 ;
642
- $ this -> first_page = 1 ;
643
- $ this -> last_page = $ this -> total_pages ;
626
+ $ prev_page = $ prev_page > 0 ? $ prev_page : 0 ;
627
+ $ next_page = $ next_page <= $ total_pages ? $ next_page : 0 ;
628
+ $ first_page = 1 ;
629
+ $ last_page = $ total_pages ;
644
630
645
- $ this -> start_offset = ($ this ->page - $ this ->pages_around_active ) > 0 ? $ this ->page - $ this ->pages_around_active : $ this -> first_page ;
646
- $ this -> end_offset = ($ this ->page + $ this ->pages_around_active ) < $ this -> total_pages ? $ this ->page + $ this ->pages_around_active : $ this -> last_page ;
631
+ $ start_offset = ($ this ->page - $ this ->pages_around_active ) > 0 ? $ this ->page - $ this ->pages_around_active : $ first_page ;
632
+ $ end_offset = ($ this ->page + $ this ->pages_around_active ) < $ total_pages ? $ this ->page + $ this ->pages_around_active : $ last_page ;
647
633
648
- if ((($ this ->pages_before_separator * 2 ) + $ this ->pages_before_separator ) >= $ this -> last_page ) {
634
+ if ((($ this ->pages_before_separator * 2 ) + $ this ->pages_before_separator ) >= $ last_page ) {
649
635
$ this ->hide_separator = true ;
650
636
}
651
637
652
638
if (!$ this ->hide_previous ) {
653
- if ($ this -> prev_page ) {
654
- $ this ->pages [] = $ this ->pageArray ($ this -> prev_page , $ this ->previous_text , 'prev ' );
639
+ if ($ prev_page ) {
640
+ $ this ->pages [] = $ this ->pageArray ($ prev_page , $ this ->previous_text , 'prev ' );
655
641
}
656
642
}
657
643
658
- if ($ this -> start_offset >= $ this ->pages_before_separator ) {
644
+ if ($ start_offset >= $ this ->pages_before_separator ) {
659
645
for ($ i = 1 ; $ i <= $ this ->pages_before_separator ; $ i ++) {
660
646
$ this ->pages [] = $ this ->pageArray ($ i , $ this ->pageText ($ i ));
661
647
$ pages [] = $ i ;
662
648
}
663
649
664
- if (!$ this ->hide_separator ) {
650
+ if (!$ this ->hide_separator && $ start_offset != $ this -> pages_before_separator && $ start_offset != ( $ this -> pages_before_separator + 1 ) ) {
665
651
$ this ->pages [] = $ this ->pageArray (null , $ this ->separator , 'separator ' );
666
652
}
667
653
}
668
654
669
- for ($ i = $ this -> start_offset ; $ i <= $ this -> end_offset ; $ i ++) {
655
+ for ($ i = $ start_offset ; $ i <= $ end_offset ; $ i ++) {
670
656
if (!in_array ($ i , $ pages )) {
671
657
$ this ->pages [] = $ this ->pageArray ($ i , $ this ->pageText ($ i ));
672
658
}
673
659
}
674
660
675
- if ($ this -> end_offset <= ($ this -> last_page - $ this ->pages_before_separator )) {
661
+ if ($ end_offset <= ($ last_page - $ this ->pages_before_separator )) {
676
662
if (!$ this ->hide_separator ) {
677
663
$ this ->pages [] = $ this ->pageArray (null , $ this ->separator , 'separator ' );
678
664
}
679
665
680
- for ($ i = ($ this -> last_page - ($ this ->pages_before_separator - 1 )); $ i <= $ this -> last_page ; $ i ++) {
666
+ for ($ i = ($ last_page - ($ this ->pages_before_separator - 1 )); $ i <= $ last_page ; $ i ++) {
681
667
$ this ->pages [] = $ this ->pageArray ($ i , $ this ->pageText ($ i ));
682
668
}
683
669
}
684
670
685
- if ($ i == $ this -> last_page ) {
671
+ if ($ i == $ last_page ) {
686
672
$ this ->pages [] = $ this ->pageArray ($ i , $ this ->pageText ($ i ));
687
673
}
688
674
689
675
if (!$ this ->hide_next ) {
690
- if ($ this -> next_page ) {
691
- $ this ->pages [] = $ this ->pageArray ($ this -> next_page , $ this ->next_text , 'next ' );
676
+ if ($ next_page ) {
677
+ $ this ->pages [] = $ this ->pageArray ($ next_page , $ this ->next_text , 'next ' );
692
678
}
693
679
}
694
680
@@ -766,9 +752,7 @@ public function get()
766
752
$ output .= '</nav> ' ;
767
753
$ output .= "\r\n" ;
768
754
769
- $ this ->pagination = $ output ;
770
-
771
- return $ this ->pagination ;
755
+ return $ output ;
772
756
}
773
757
774
758
/**
0 commit comments