Browse Source

sort servers by players quantity by default

main
ghost 10 months ago
parent
commit
80e362a131
  1. 20
      src/Controller/MainController.php

20
src/Controller/MainController.php

@ -33,12 +33,7 @@ class MainController extends AbstractController @@ -33,12 +33,7 @@ class MainController extends AbstractController
// Collect servers info
$servers = [];
foreach ((array) $entityManagerInterface->getRepository(Server::class)->findBy(
[],
[
'online' => 'desc'
]
) as $server)
foreach ((array) $entityManagerInterface->getRepository(Server::class)->findAll() as $server)
{
// Init defaults
$status = false;
@ -106,10 +101,21 @@ class MainController extends AbstractController @@ -106,10 +101,21 @@ class MainController extends AbstractController
'updated' => $server->getUpdated(),
'online' => $server->getOnline(),
'info' => $info,
'status' => $status
'status' => $status,
'sort' => empty($info['Players']) ? 0 : (int) $info['Players']
];
}
// Sort by players
array_multisort(
array_column(
$servers,
'sort'
),
SORT_DESC,
$servers
);
return $this->render(
'default/main/index.html.twig',
[

Loading…
Cancel
Save