mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
allow ordering demo list
This commit is contained in:
parent
efd74cd966
commit
0f5f74e21b
2 changed files with 5 additions and 3 deletions
|
|
@ -58,7 +58,8 @@ class DemoController extends BaseController {
|
||||||
|
|
||||||
public function listDemos() {
|
public function listDemos() {
|
||||||
$page = $this->query('page', 1);
|
$page = $this->query('page', 1);
|
||||||
\Flight::json($this->demoListProvider->listDemos($page, $this->getFilter()));
|
$order = $this->query('order', 'DESC') === 'ASC' ? 'ASC' : 'DESC';
|
||||||
|
\Flight::json($this->demoListProvider->listDemos($page, $this->getFilter(), $order));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listProfile($steamid) {
|
public function listProfile($steamid) {
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,10 @@ class DemoListProvider extends BaseProvider {
|
||||||
/**
|
/**
|
||||||
* @param int $page
|
* @param int $page
|
||||||
* @param array $where
|
* @param array $where
|
||||||
|
* @param string $order
|
||||||
* @return Demo[]
|
* @return Demo[]
|
||||||
*/
|
*/
|
||||||
public function listDemos(int $page, array $where = []) {
|
public function listDemos(int $page, array $where = [], $order = 'DESC') {
|
||||||
if (isset($where['players']) and is_array($where['players']) and count($where['players']) > 0) {
|
if (isset($where['players']) and is_array($where['players']) and count($where['players']) > 0) {
|
||||||
return $this->listProfile($page, $where);
|
return $this->listProfile($page, $where);
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +61,7 @@ class DemoListProvider extends BaseProvider {
|
||||||
if (isset($where['uploader'])) {
|
if (isset($where['uploader'])) {
|
||||||
$query->where($query->expr()->in('uploader', $query->createNamedParameter($where['uploader'], \PDO::PARAM_INT)));
|
$query->where($query->expr()->in('uploader', $query->createNamedParameter($where['uploader'], \PDO::PARAM_INT)));
|
||||||
}
|
}
|
||||||
$query->orderBy('d.id', 'DESC')
|
$query->orderBy('d.id', $order)
|
||||||
->setMaxResults(50)
|
->setMaxResults(50)
|
||||||
->setFirstResult($offset);
|
->setFirstResult($offset);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue