1
0
mirror of https://github.com/flarum/core.git synced 2025-10-27 21:46:17 +01:00

Update discussion/post sort semantics inline with new API actions

Instead of $sort and $order being separate, they are now a single
array, allowing multiple sort criteria: `[‘foo’ => ‘asc', ‘bar’ =>
‘desc’]`
This commit is contained in:
Toby Zerner
2015-05-02 09:00:07 +09:30
parent 22ff8a203d
commit 8ee9480205
5 changed files with 28 additions and 36 deletions

View File

@@ -29,19 +29,21 @@ class EloquentPostRepository implements PostRepositoryInterface
*
* @param array $where
* @param \Flarum\Core\Models\User|null $user
* @param string $sort
* @param string $order
* @param array $sort
* @param integer $count
* @param integer $start
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findWhere($where = [], User $user = null, $sort = 'time', $order = 'asc', $count = null, $start = 0)
public function findWhere($where = [], User $user = null, $sort = [], $count = null, $start = 0)
{
$query = Post::where($where)
->orderBy($sort, $order)
->skip($start)
->take($count);
foreach ((array) $sort as $field => $order) {
$query->orderBy($field, $order);
}
return $this->scopeVisibleForUser($query, $user)->get();
}

View File

@@ -22,13 +22,12 @@ interface PostRepositoryInterface
*
* @param array $where
* @param \Flarum\Core\Models\User|null $user
* @param string $sort
* @param string $order
* @param array $sort
* @param integer $count
* @param integer $start
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findWhere($where = [], User $user = null, $sort = 'time', $order = 'asc', $count = null, $start = 0);
public function findWhere($where = [], User $user = null, $sort = [], $count = null, $start = 0);
/**
* Find posts by their IDs, optionally making sure they are visible to a