상속: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements JsonSerializabl\JsonSerializable
예제 #1
0
 public function toArray()
 {
     if ($this->paginator) {
         try {
             $total = $this->total();
         } catch (Exception $e) {
             $total = null;
         }
         return ['total' => $total, 'per_page' => $this->listRows(), 'current_page' => $this->currentPage(), 'data' => parent::toArray()];
     } else {
         return parent::toArray();
     }
 }
예제 #2
0
 protected function __construct($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = [])
 {
     $this->options = array_merge($this->options, $options);
     $this->options['path'] = $this->options['path'] != '/' ? rtrim($this->options['path'], '/') : $this->options['path'];
     $this->simple = $simple;
     $this->listRows = $listRows;
     if ($simple) {
         if (!$items instanceof Collection) {
             $items = Collection::make($items);
         }
         $this->currentPage = $this->setCurrentPage($currentPage);
         $this->hasMore = count($items) > $this->listRows;
         $items = $items->slice(0, $this->listRows);
     } else {
         $this->total = $total;
         $this->lastPage = (int) ceil($total / $listRows);
         $this->currentPage = $this->setCurrentPage($currentPage);
         $this->hasMore = $this->currentPage < $this->lastPage;
     }
     $this->items = PaginatorCollection::make($items, $this);
 }