Ejemplo n.º 1
0
 /**
  * Get the paginated query results as a Paginator instance.
  *
  * @param  int        $per_page
  * @param  array      $columns
  * @return Paginator
  */
 public function paginate($per_page = 20, $columns = array('*'))
 {
     // Because some database engines may throw errors if we leave orderings
     // on the query when retrieving the total number of records, we'll drop
     // all of the ordreings and put them back on the query.
     list($orderings, $this->orderings) = array($this->orderings, null);
     $total = $this->count(reset($columns));
     $page = Paginator::page($total, $per_page);
     $this->orderings = $orderings;
     // Now we're ready to get the actual pagination results from the table
     // using the for_page and get methods. The "for_page" method provides
     // a convenient way to set the paging limit and offset.
     $results = $this->for_page($page, $per_page)->get($columns);
     return Paginator::make($results, $total, $per_page);
 }
Ejemplo n.º 2
0
 /**
  * Get paginated model results as a Paginator instance.
  *
  * @param  int        $per_page
  * @param  array      $columns
  * @return Paginator
  */
 private function _paginate($per_page = null, $columns = array('*'))
 {
     list($orderings, $this->query->orderings) = array($this->query->orderings, null);
     $total = $this->query->count();
     $this->query->orderings = $orderings;
     // The number of models to show per page may be specified as a static property
     // on the model. The models shown per page may also be overriden for the model
     // by passing the number into this method. If the models to show per page is
     // not available via either of these avenues, a default number will be shown.
     if (is_null($per_page)) {
         $per_page = property_exists(get_class($this), 'per_page') ? static::$per_page : 20;
     }
     return Paginator::make($this->for_page(Paginator::page($total, $per_page), $per_page)->get($columns), $total, $per_page);
 }
Ejemplo n.º 3
0
 public function paginate($per_page = 20, $columns = array('*'))
 {
     list($orderings, $this->orderings) = array($this->orderings, null);
     $total = $this->count(reset($columns));
     $page = Paginator::page($total, $per_page);
     $this->orderings = $orderings;
     $results = $this->for_page($page, $per_page)->get($columns);
     return Paginator::make($results, $total, $per_page);
 }
Ejemplo n.º 4
0
 /**
  * Get the paginated query results as a Paginator instance.
  *
  * @param  int        $per_page
  * @param  array      $columns
  * @return Paginator
  */
 public function paginate($per_page = 20, $columns = array('*'))
 {
     // Because some database engines may throw errors if we leave
     // orderings on the query when retrieving the total number
     // of records, we will remove all of the ordreings and put
     // them back on the query after we have the count.
     list($orderings, $this->orderings) = array($this->orderings, null);
     $page = Paginator::page($total = $this->count(), $per_page);
     $this->orderings = $orderings;
     return Paginator::make($this->for_page($page, $per_page)->get($columns), $total, $per_page);
 }
Ejemplo n.º 5
0
 /**
  * Get paginated model results as a Paginator instance.
  *
  * @param  int        $per_page
  * @return Paginator
  */
 private function _paginate($per_page = null, $columns = array('*'))
 {
     $countCol = str_replace('.*', '.id', $columns[0], $exists);
     if ($exists) {
         $total = $this->query->count($countCol);
     } else {
         $total = $this->query->count();
     }
     // The number of models to show per page may be specified as a static property
     // on the model. The models shown per page may also be overriden for the model
     // by passing the number into this method. If the models to show per page is
     // not available via either of these avenues, a default number will be shown.
     if (is_null($per_page)) {
         $per_page = property_exists(get_class($this), 'per_page') ? static::$per_page : 20;
     }
     return Paginator::make($this->select($columns)->distinct($columns)->for_page(Paginator::page($total, $per_page), $per_page)->get(), $total, $per_page);
 }