本文整理汇总了PHP中Illuminate\Database\Query\Builder::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::orderBy方法的具体用法?PHP Builder::orderBy怎么用?PHP Builder::orderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::orderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeQuery
/**
* 주어진 db query를 실행한다.
*
* @param Builder $query 질의
* @param int|int[]|stdClass $navigation 검색시 사용할 navigation(page, perPage, sort, order) 정보
*
* @return array
*/
protected function executeQuery($query, $navigation = null)
{
// set default
$order = $this->defaultOrder;
$sort = $this->defaultSort;
$perPage = $this->defaultPerPage;
$page = null;
if (is_array($navigation)) {
list($page, $perPage) = $navigation;
} elseif (is_object($navigation)) {
$page = data_get($navigation, 'page', $page);
$perPage = data_get($navigation, 'perPage', $perPage);
$order = data_get($navigation, 'order', $order);
$sort = data_get($navigation, 'sort', $sort);
}
if ($sort !== null) {
$query->orderBy($sort, $order);
}
if ($navigation === null) {
$collection = $query->get();
} elseif ($page !== null) {
$collection = $query->forPage($page, $perPage);
} else {
$collection = $query->paginate($perPage);
}
return $collection;
}
示例2: applyOrderBy
/**
* @param string $column
* @param string $direction
* @return $this
*/
public function applyOrderBy($column, $direction = 'asc')
{
/**
* Save to conditons.
*/
$this->addCondition('order by', [$column, $direction]);
$this->model = $this->model->orderBy($column, $direction);
return $this;
}
示例3: order
/**
* {@inheritdoc}
*/
public function order(Builder $builder, $direction)
{
if ($this->columnClause !== null) {
$builder->orderBy($this->columnClause, $direction);
}
return $this;
}
示例4: build
/**
* 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;
}
示例5: execute
public function execute(Builder $query)
{
foreach ($this->getValuesIterator() as $orderBy) {
$query->orderBy($orderBy->getName(), $orderBy->getValue());
}
return $query;
}
示例6: orderBy
/**
*
* @param string $value
*/
public function orderBy($value = [])
{
//if array is not empty
if (count($value) > 0) {
$this->query = $this->query->orderBy($value[0], $value[1]);
}
return $this;
}
示例7: orderBy
/**
* Order the results by the given column in the given direction.
*
* @param string $key
* @param string $direction
* @return $this
* @throws TableNotSetException
*/
public function orderBy($key, $direction = 'asc')
{
if (!$this->query) {
throw new TableNotSetException("You must set a database table to get results from.");
}
$this->query = $this->query->orderBy($key, $direction);
return $this;
}
示例8: setupBasicQueryFilter
/**
* Setup basic query string filter to eloquent or query builder.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param array $input
*
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
*/
protected function setupBasicQueryFilter($query, array $input = [])
{
$orderBy = $this->getBasicQueryOrderBy($input);
$direction = $this->getBasicQueryDirection($input);
$columns = isset($input['columns']) ? $input['columns'] : null;
if (is_array($columns) && $this->isColumnExcludedFromFilterable($orderBy, $columns)) {
return $query;
}
!empty($orderBy) && $query->orderBy($orderBy, $direction);
return $query;
}
示例9: scopeQueryWithParams
/**
* A reusable query to pass params
*
* @param Builder $query
* @param array $queryFilter
*
* @return Builder
*/
public function scopeQueryWithParams($query, $queryFilter)
{
$limit = isset($queryFilter['limit']) ? $queryFilter['limit'] : 10;
$perPage = isset($queryFilter['perPage']);
$orderBy = isset($queryFilter['orderBy']) ? $queryFilter['orderBy'] : 'created_at';
$sortOrder = isset($queryFilter['sortOrder']) ? $queryFilter['sortOrder'] : 'desc';
$query->orderBy($orderBy, $sortOrder);
if ($perPage) {
return $query->paginate($perPage);
}
return $query->take($limit);
}
示例10: optionAppliedPaginate
/**
* @param \Illuminate\Database\Query\Builder|\Minhbang\Kit\Extensions\Model $query
* @param bool $position
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
protected function optionAppliedPaginate($query, $position = false)
{
list($column, $direction) = $this->options->column('sort');
if ($column) {
$query->orderBy($column, $direction);
} else {
if ($position) {
$query->orderPosition();
}
}
return $query->paginate($this->options->get('page_size', 6));
}
示例11: ordering
/**
* Datatable ordering
*
* @return null
*/
protected function ordering()
{
if (array_key_exists('order', $this->input) && count($this->input['order']) > 0) {
$columns = $this->cleanColumns($this->aliased_ordered_columns);
for ($i = 0, $c = count($this->input['order']); $i < $c; $i++) {
$order_col = (int) $this->input['order'][$i]['column'];
if (isset($columns[$order_col])) {
if ($this->input['columns'][$order_col]['orderable'] == "true") {
$this->query->orderBy($columns[$order_col], $this->input['order'][$i]['dir']);
}
}
}
}
}
示例12: orderBy
/**
* @param array $orders
* @param string $v 兼容原来的方法
* @return $this
*/
public function orderBy($orders = [], $v = 'desc')
{
if (empty($orders)) {
return $this;
}
if (is_array($orders)) {
foreach ($orders as $k => $v) {
$this->operator->orderBy($k, $v);
}
} else {
$this->operator->orderBy($orders, $v);
}
return $this;
}
示例13: getFilteredQueryListRows
/**
* Return the filtered, ordered and paginated rows from the crud's custom query
*
* @param Builder $query
* @param int $start
* @param int $length
* @param array $filters
* @param null $order
* @return array
*/
public static function getFilteredQueryListRows(Builder $query, $start, $length, $filters = [], $order = null)
{
// Get the total count of rows with no filters and pagination
$countTotal = $query->count();
// Check if any filters were submitted
if ($filters) {
foreach ($filters as $filterName => $filterValue) {
// Check if there is any filter operator in the field string
$operation = SQL::findOperationWhere($filterValue);
$query->where($filterName, $operation['operation'], $operation['text']);
}
}
// Get the total count of rows filtered, but without pagination
$countFiltered = $query->count();
// Execute pagination
$query->skip($start)->take($length);
// Check if an order by was submitted
if ($order) {
$query->orderBy($order['name'], $order['dir']);
}
return ['rows' => $query->get(), 'count_filtered' => $countFiltered, 'count_total' => $countTotal];
}
示例14: addOrderByQuery
/**
* Add order by to query builder
* @param \Illuminate\Database\Query\Builder $query object is by reference
*/
protected function addOrderByQuery($query)
{
if (isset($this->orderBy)) {
$query->orderBy($this->orderBy['column'], $this->orderBy['direction']);
} else {
// Default order by
if (isset($this->attributes['order_by'])) {
$query->orderBy($this->attributes('order_by'), $this->attributes('order_by_dir'));
}
// Else omit the order by statement completely which will use tables clustered index as order
}
}
示例15: loadLatest
/**
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function loadLatest()
{
return $this->productResource->orderBy('updated_at', 'desc')->with(Product::standardRelations())->paginate();
}