Skip to content

Commit

Permalink
Introduce AbstractQueryState class
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Mar 1, 2021
1 parent 2457c49 commit a24981c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 77 deletions.
77 changes: 2 additions & 75 deletions src/Filter/FilterState.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,6 @@

namespace Flarum\Filter;

use Flarum\User\User;
use Illuminate\Database\Query\Builder;
use Flarum\Query\AbstractQueryState;

class FilterState
{
/**
* @var Builder
*/
protected $query;

/**
* @var User
*/
protected $actor;

/**
* @var mixed
*/
protected $defaultSort = [];

/**
* @param Builder $query
* @param User $actor
*/
public function __construct(Builder $query, User $actor, $defaultSort = [])
{
$this->query = $query;
$this->actor = $actor;
$this->defaultSort = $defaultSort;
}

/**
* Get the query builder for the search results query.
*
* @return Builder
*/
public function getQuery()
{
return $this->query;
}

/**
* Get the user who is performing the search.
*
* @return User
*/
public function getActor()
{
return $this->actor;
}

/**
* Get the default sort order for the search.
*
* @return array
*/
public function getDefaultSort()
{
return $this->defaultSort;
}

/**
* Set the default sort order for the search. This will only be applied if
* a sort order has not been specified in the search criteria.
*
* @param mixed $defaultSort An array of sort-order pairs, where the column
* is the key, and the order is the value. The order may be 'asc',
* 'desc', or an array of IDs to order by.
* Alternatively, a callable may be used.
* @return mixed
*/
public function setDefaultSort($defaultSort)
{
$this->defaultSort = $defaultSort;
}
}
class FilterState extends AbstractQueryState {}
87 changes: 87 additions & 0 deletions src/Query/AbstractQueryState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Query;

use Flarum\User\User;
use Illuminate\Database\Query\Builder;

abstract class AbstractQueryState
{
/**
* @var Builder
*/
protected $query;

/**
* @var User
*/
protected $actor;

/**
* @var mixed
*/
protected $defaultSort = [];

/**
* @param Builder $query
* @param User $actor
*/
public function __construct(Builder $query, User $actor, $defaultSort = [])
{
$this->query = $query;
$this->actor = $actor;
$this->defaultSort = $defaultSort;
}

/**
* Get the query builder for the search results query.
*
* @return Builder
*/
public function getQuery()
{
return $this->query;
}

/**
* Get the user who is performing the search.
*
* @return User
*/
public function getActor()
{
return $this->actor;
}

/**
* Get the default sort order for the search.
*
* @return array
*/
public function getDefaultSort()
{
return $this->defaultSort;
}

/**
* Set the default sort order for the search. This will only be applied if
* a sort order has not been specified in the search criteria.
*
* @param mixed $defaultSort An array of sort-order pairs, where the column
* is the key, and the order is the value. The order may be 'asc',
* 'desc', or an array of IDs to order by.
* Alternatively, a callable may be used.
* @return mixed
*/
public function setDefaultSort($defaultSort)
{
$this->defaultSort = $defaultSort;
}
}
4 changes: 2 additions & 2 deletions src/Search/AbstractSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace Flarum\Search;

use Flarum\Filter\FilterState;
use Flarum\Query\AbstractQueryState;

/**
* @deprecated, use SearchState instead.
* These methods should be transferred over to SearchState in beta 17.
*/
class AbstractSearch extends FilterState
class AbstractSearch extends AbstractQueryState
{
/**
* @var GambitInterface[]
Expand Down

0 comments on commit a24981c

Please sign in to comment.