public function totalCount() { if ($this->options['distinctCountGroup'] && count($this->originalBuilder->groups) == 1) { $this->originalBuilder->groups = null; } if ($this->options['searchWithAlias']) { $cnt = count($this->originalBuilder->get()); } else { $cnt = $this->originalBuilder->count(); } return $cnt; }
/** * @param array $attributes * @return bool * @throws BadDataQueryException */ public function canFind(array $attributes) { foreach ($attributes as $key => $value) { $this->where($key, $value); } return $this->model->count() > 0; }
/** * Count rows * * @return Integer */ public function count() { // Save the results from the builder $result = $this->builder->count(); // Reset the builder, just in case we are going to use this repository more then once $this->newBuilder(); return $result; }
/** * Scope a query to only one random item. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeRandom($query) { $total = $query->count(); if ($total > 1) { $offset = mt_rand(0, $total - 1); $query = $query->skip($offset)->take(1); } return $query; }
public function getItems($limit, $offset) { $builder = $this->query->getQuery(); if ($builder->groups || $builder->unions) { $row = DB::selectOne("SELECT COUNT(*) qty FROM (" . $this->query->toSql() . ") sub", $this->query->getBindings()); $total = (int) $row->qty; } else { $total = $this->query->count(); } $pageOfItems = $this->query->skip($offset)->take($limit)->get(); return [$pageOfItems, $total]; }
public function build() { $request = $this->request; $needle = $request->needle(); if ($needle && $request->searchable) { $this->qb->where(function ($subQB) use($needle, $request) { foreach ($request->searchable as $column) { $subQB->orWhere($column, 'LIKE', "%{$needle}%"); } }); } $request->modifyQuery($this->qb); $this->qb->orderBy($request->orderBy(), $request->sortBy()); $count = $this->qb->count(); $this->qb->take($request->perPage()); $this->qb->offset($request->offset()); $paginator = new LengthAwarePaginator($request->items($this->qb), $count, $request->perPage(), $request->page()); $paginator->request = $request; $paginator->appends($request->query()); $this->paginator = $paginator; }
/** * Возвращает коллекцию в виде пагинации * * @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']); }
/** * @return int */ public function count() { return $this->specificationQuery->count(); }
public function totalCount() { return $this->originalBuilder->count(); }
/** * Get the entry count. * * @param array $columns * @return int */ public function count(array $columns = ['*']) { return (new Decorator())->decorate($this->query->count($columns)); }
public function getItems($requestedLimit, $requestedOffset) { $items = $this->collection->slice($requestedOffset, $requestedLimit); return [$items, $this->collection->count()]; }
/** * @return int */ public function count() { return $this->builder->count(); }
/** * Formatting the returned data in an associative array representation of the required datatables response object. * @param Builder $originalQuery Original Eloquent query object before applying datatables process, use alt query if aggregate functions are used with the original. * @param array $data Returned data collection after processing. * @return array Associative array (object) that is required for responding to datatables request. */ public static function format(Builder $originalQuery, $data) { $recordsTotal = is_null(self::$distinctField) ? $originalQuery->count() : $originalQuery->select(DB::raw('COUNT(DISTINCT ' . self::$distinctField . ') AS total'))->get()->toArray()[0]['total']; return ['draw' => Request::input('draw'), 'recordsFiltered' => self::$totalFiltered, 'data' => $data] + compact('recordsTotal'); }