Merge branch 'master' of ssh://git.thisfro.ch:222/thisfro/pflaenz.li
This commit is contained in:
commit
775dcfa681
5 changed files with 415 additions and 380 deletions
749
composer.lock
generated
749
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -33,15 +33,21 @@ class OfferController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/offers', name: 'offers', options: ["sitemap" => true])]
|
||||
public function showAll(Environment $twig, Request $request, OfferRepository $offerRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
|
||||
public function showAll(Request $request, OfferRepository $offerRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
|
||||
{
|
||||
$form = $this->createForm(OfferFilterFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$allOffers = $offerRepository->findAll();
|
||||
$filteredOffers = [];
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if ($form->isSubmitted() && $form->isValid() && $form->get('search')->getData() != null) {
|
||||
$allOffers = $offerRepository->findBySearchLiteral($form->get('search')->getData());
|
||||
}
|
||||
else {
|
||||
$allOffers = $offerRepository->findAll();
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid() && $form->get('distance')->getData() != null && $form->get('zipCode')->getData() != null) {
|
||||
$filterDistance = $form->get('distance')->getData();
|
||||
$filterPlz = $form->get('zipCode')->getData();
|
||||
$filterCoordinate = $plzconverter->convertPlzToCoordinate($filterPlz);
|
||||
|
@ -144,7 +150,7 @@ class OfferController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/offer/edit/{urlId}', name: 'edit_offer')]
|
||||
public function editOffer(Offer $offer, OfferRepository $offerRepository, Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
|
||||
public function editOffer(Offer $offer, Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
|
||||
{
|
||||
$form = $this->createForm(OfferFormType::class, $offer);
|
||||
$user = $this->getUser();
|
||||
|
@ -209,4 +215,14 @@ class OfferController extends AbstractController
|
|||
'offers' => $offerRepository->findByUser($user),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/offers/search', name: 'search', options: ["sitemap" => false])]
|
||||
public function search(OfferRepository $offerRepository): Response
|
||||
{
|
||||
$offers = $offerRepository->findBySearchLiteral('');
|
||||
|
||||
return $this->render('offer/search.html.twig', [
|
||||
'offers' => $offers,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ class OfferFilterFormType extends AbstractType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('zipCode', TextType::class, [
|
||||
->add('search', TextType::class, [
|
||||
'label' => 'Search',
|
||||
])
|
||||
->add('zipCode', NumberType::class, [
|
||||
'label' => 'ZIP',
|
||||
])
|
||||
->add('distance', NumberType::class, [
|
||||
|
|
|
@ -44,6 +44,19 @@ class OfferRepository extends ServiceEntityRepository
|
|||
;
|
||||
}
|
||||
|
||||
public function findBySearchLiteral(string $literal)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('o');
|
||||
$qb->andWhere($qb->expr()->like('o.title', ':lit'))
|
||||
->setParameter('lit', '%' . $literal . '%')
|
||||
->orderBy('o.id', 'ASC')
|
||||
;
|
||||
|
||||
$qb = $qb->getQuery()->getResult();
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?Offer
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<div class="btn btn-primary"><i class="fas fa-filter mr-3"></i>Filter<i class="fas fa-chevron-down ml-3 dropdown-collapse"></i></div>
|
||||
</a>
|
||||
<div class="collapse" id="collapseExample">
|
||||
{{ form(filter_form) }}
|
||||
{{ form(filter_form, {attr: {novalidate: 'novalidate'}}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Reference in a new issue