Commit fb19fb6b by Lech Sawon

sorting form for room

parent fa8b058a
......@@ -33,7 +33,6 @@ final class CategoryController extends AbstractController
/**
* @Route("/new", name="category_new", methods={"GET", "POST"})
* @IsGranted("ROLE_ADMIN")
*/
public function new(Request $request): Response
{
......
......@@ -18,10 +18,13 @@ class RoomController extends AbstractController
/**
* @Route("/", name="room_index", methods={"GET"})
*/
public function index(RoomRepository $roomRepository): Response
public function index(Request $request, RoomRepository $roomRepository): Response
{
$sorting = $request->query->get('sorting');
return $this->render('room/index.html.twig', [
'rooms' => $roomRepository->findAll(),
'rooms' => $roomRepository->findSorted($sorting),
'sorting' => $sorting
]);
}
......
......@@ -2,6 +2,7 @@
namespace App\Repository;
use App\Entity\Reservation;
use App\Entity\Room;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
......@@ -19,6 +20,25 @@ class RoomRepository extends ServiceEntityRepository
parent::__construct($registry, Room::class);
}
/**
* @return Room[]
*/
public function findSorted(?string $sorting): array
{
$qb = $this
->createQueryBuilder('room');
if ('ASC' === $sorting) {
$qb->addOrderBy('room.name', 'ASC');
} elseif ('DESC' === $sorting) {
$qb->addOrderBy('room.name', 'DESC');
}
$query = $qb->getQuery();
return $query->getResult();
}
// /**
// * @return Room[] Returns an array of Room objects
// */
......
......@@ -4,7 +4,16 @@
{% block body %}
<h1>Room index</h1>
<form>
<label>
<select name="sorting">
<option value="">Brak</option>
<option value="ASC">Spadająco</option>
<option value="DESC">Rosnąco</option>
</select>
</label>
<input type="submit"/>
</form>
<table class="table">
<thead>
<tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment