Commit 4650a38d by Lech Sawon

search by like query

parent f8e57532
...@@ -21,10 +21,12 @@ class RoomController extends AbstractController ...@@ -21,10 +21,12 @@ class RoomController extends AbstractController
public function index(Request $request, RoomRepository $roomRepository): Response public function index(Request $request, RoomRepository $roomRepository): Response
{ {
$sorting = $request->query->get('sorting'); $sorting = $request->query->get('sorting');
$queryString = $request->query->get('search');
return $this->render('room/index.html.twig', [ return $this->render('room/index.html.twig', [
'rooms' => $roomRepository->findSorted($sorting), 'rooms' => $roomRepository->findSorted($sorting, $queryString),
'sorting' => $sorting 'sorting' => $sorting,
'queryString' =>$queryString
]); ]);
} }
......
...@@ -23,7 +23,7 @@ class RoomRepository extends ServiceEntityRepository ...@@ -23,7 +23,7 @@ class RoomRepository extends ServiceEntityRepository
/** /**
* @return Room[] * @return Room[]
*/ */
public function findSorted(?string $sorting): array public function findSorted(?string $sorting, ?string $queryString): array
{ {
$qb = $this $qb = $this
->createQueryBuilder('room'); ->createQueryBuilder('room');
...@@ -34,6 +34,11 @@ class RoomRepository extends ServiceEntityRepository ...@@ -34,6 +34,11 @@ class RoomRepository extends ServiceEntityRepository
$qb->addOrderBy('room.name', 'DESC'); $qb->addOrderBy('room.name', 'DESC');
} }
if ($queryString) {
$qb->andWhere('room.name LIKE :queryString');
$qb->setParameter(':queryString', "%$queryString%");
}
$query = $qb->getQuery(); $query = $qb->getQuery();
return $query->getResult(); return $query->getResult();
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
{% block body %} {% block body %}
<h1>Room index</h1> <h1>Room index</h1>
{{ include('_embed/_simple_sorting.html.twig') }} {{ include('_embed/_simple_sorting.html.twig') }}
<form>
<input type="text" name="search"/>
<input type="submit"/>
</form>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <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