skip() public method

Alias to set the "offset" value of the query.
public skip ( integer $value ) : Builder | static
$value integer
return Builder | static
Example #1
1
 public function build()
 {
     if (is_string($this->source) && strpos(" ", $this->source) === false) {
         //tablename
         $this->type = "query";
         $this->query = $this->table($this->source);
         $this->total_rows = $this->query->count();
     } elseif (is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Model") || is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Builder")) {
         $this->type = "model";
         $this->query = $this->source;
         $this->total_rows = $this->query->count();
     } elseif (is_array($this->source)) {
         $this->type = "array";
         $this->total_rows = count($this->source);
     }
     //exception
     //offset and pagination setup/detect
     $config = array('cid' => $this->cid, 'total_items' => $this->total_rows, 'items_per_page' => $this->per_page, 'num_links' => round($this->num_links / 2), 'hash' => $this->hash, 'url' => $this->url, 'current_page' => $this->current_page);
     $this->pagination = new \Rapyd\Helpers\Pagination($config);
     $offset = $this->pagination->offset();
     $this->limit($this->per_page, $offset);
     //build orderby urls
     $this->orderby_uri_asc = $this->app->url->remove('pag' . $this->cid)->remove('reset' . $this->cid)->append('orderby' . $this->cid, array("-field-", "asc"))->get() . $this->hash;
     $this->orderby_uri_desc = $this->app->url->remove('pag' . $this->cid)->remove('reset' . $this->cid)->append('orderby' . $this->cid, array("-field-", "desc"))->get() . $this->hash;
     //detect orderby
     $orderby = $this->app->url->value("orderby" . $this->cid);
     if ($orderby) {
         $this->orderby_field = $orderby[0];
         $this->orderby_direction = $orderby[1];
         $this->orderby($this->orderby_field, $this->orderby_direction);
     }
     //build subset of data
     switch ($this->type) {
         case "array":
             //orderby
             if (isset($this->orderby)) {
                 list($field, $direction) = $this->orderby;
                 $column = array();
                 foreach ($this->source as $key => $row) {
                     $column[$key] = $row[$field];
                 }
                 if ($direction == "asc") {
                     array_multisort($column, SORT_ASC, $this->source);
                 } else {
                     array_multisort($column, SORT_DESC, $this->source);
                 }
             }
             //limit-offset
             if (isset($this->limit)) {
                 $this->source = array_slice($this->source, $this->limit[1], $this->limit[0]);
             }
             $this->data = $this->source;
             break;
         case "query":
         case "model":
             //orderby
             if (isset($this->orderby)) {
                 $this->query = $this->query->orderBy($this->orderby[0], $this->orderby[1]);
             }
             //limit-offset
             if (isset($this->limit)) {
                 $this->query = $this->query->skip($this->pagination->offset())->take($this->per_page);
             }
             $this->data = $this->query->get();
             break;
     }
     return $this;
 }
Example #2
0
 /**
  * flush events, build pagination and sort items
  * 
  * @return $this
  */
 public function build()
 {
     BurpEvent::flush('dataset.sort');
     BurpEvent::flush('dataset.page');
     $this->paginator = Paginator::make($this->total_rows, $this->per_page, $this->page);
     $offset = $this->paginator->offset();
     $this->limit($this->per_page, $offset);
     if (is_array($this->source)) {
         //orderby
         if (isset($this->orderby)) {
             list($field, $direction) = $this->orderby;
             array_orderby($this->source, $field, $direction);
         }
         //limit-offset
         if (isset($this->limit)) {
             $this->source = array_slice($this->source, $this->limit[1], $this->limit[0]);
         }
         $this->data = $this->source;
     } else {
         //orderby
         if (isset($this->orderby)) {
             $this->query = $this->query->orderBy($this->orderby[0], $this->orderby[1]);
         }
         //limit-offset
         if (isset($this->per_page)) {
             $this->query = $this->query->skip($offset)->take($this->per_page);
         }
         $this->data = $this->query->get();
     }
     return $this;
 }
Example #3
0
 /**
  * Get a paginator only supporting simple next and previous links.
  *
  * This is more efficient on larger data-sets, etc.
  *
  * @param  int    $perPage
  * @param  array  $columns
  * @return \Illuminate\Pagination\Paginator
  */
 public function simplePaginate($perPage = null, $columns = array('*'))
 {
     $paginator = $this->query->getConnection()->getPaginator();
     $page = $paginator->getCurrentPage();
     $perPage = $perPage ?: $this->model->getPerPage();
     $this->query->skip(($page - 1) * $perPage)->take($perPage + 1);
     return $paginator->make($this->get($columns)->all(), $perPage);
 }
Example #4
0
 /**
  * Возвращает коллекцию в виде пагинации
  *
  * @param int $page
  * @param int $limit
  */
 public function pagination($page, $limit = 10)
 {
     /**
      * @var \Illuminate\Support\Collection $data
      */
     $countTotal = $this->_query->count();
     $this->_query->skip($limit * $page - $limit);
     $this->_query->limit($limit);
     $data = collect();
     foreach ($this->_query->get() as $key => $instance) {
         $_listRow = [];
         foreach ($this->columns->getColumns() as $column) {
             $_listRow[$column->getKey()] = $column->getValues($instance);
         }
         $buttons = $this->filterAction($instance);
         if (count($buttons)) {
             $_listRow = array_merge($_listRow, [GridColumn::ACTION_NAME => implode('', $buttons)]);
         }
         $data->offsetSet($key, $_listRow);
     }
     return new \Illuminate\Pagination\LengthAwarePaginator($data, $countTotal, $limit, $page, ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath(), 'pageName' => 'page']);
 }
Example #5
0
 /**
  * Alias to set the "offset" value of the query.
  *
  * @param int $value
  * @return \Illuminate\Database\Query\Builder|static 
  * @static 
  */
 public static function skip($value)
 {
     return \Illuminate\Database\Query\Builder::skip($value);
 }
 /**
  * Datatable paging
  *
  * @return null
  */
 protected function paging()
 {
     if (!is_null($this->input['start']) && !is_null($this->input['length']) && $this->input['length'] != -1) {
         $this->query->skip($this->input['start'])->take((int) $this->input['length'] > 0 ? $this->input['length'] : 10);
     }
 }
Example #7
0
 /**
  * Add limit to query builder
  * @param \Illuminate\Database\Query\Builder $query object is by reference
  */
 protected function addLimitQuery($query)
 {
     if (isset($this->limit)) {
         $query->skip($this->limit['skip'])->take($this->limit['take']);
     }
 }
Example #8
0
 public function execute(Builder $query)
 {
     $query->skip($this->getValue());
     return $query;
 }
 /**
  * Perform pagination
  *
  * @return mixed
  */
 public function paging()
 {
     $this->query->skip($this->request->getStart())->take($this->request->getCount());
 }
Example #10
0
 /**
  * Return the crud's custom query columns
  *
  * @param Builder $builder
  * @return array
  */
 public static function getQueryColumns(Builder $builder)
 {
     // Get the first result of the query
     $resultSet = $builder->skip(0)->take(1)->get();
     // Get the first line from the result query
     $firstRow = array_shift($resultSet);
     // Convert stdClass $firstRow to array
     $stdClassVars = get_object_vars($firstRow);
     // Return only the column names
     return array_keys($stdClassVars);
 }