src/AppBundle/Controller/PharmacyController.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace AppBundle\Controller;
  4. use AppBundle\Website\LinkGenerator\JobOfferLinkGenerator;
  5. use Pimcore\Model\DataObject\PharmacyCity;
  6. use Pimcore\Model\DataObject\PharmacyCity\Listing;
  7. use Pimcore\Model\DataObject\PharmacyPoint;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class PharmacyController extends BaseController
  13. {
  14.     public function defaultAction(): Response
  15.     {
  16.         $cities = new Listing();
  17.         $cities->setOrderKey('cityName');
  18.         $cities->setOrder('asc');
  19.         $cities->setLimit(0);
  20.         return $this->render('Pharmacy/default.html.twig', [
  21.             'cities' => $cities,
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route(
  26.      *     "{pathpharmacy}/{pharmacycity}",
  27.      *     name="pharmacy-city-list",
  28.      *     defaults={"pathjoboffer"=""},
  29.      *     requirements={"pathpharmacy":"apteki-stacjonarne", "pharmacycity"="[\w\p{L}-]+"},
  30.      *     options={"utf8"=true}
  31.      * )
  32.      */
  33.     public function cityAction(Request $request): Response
  34.     {
  35.         $city $request->get('pharmacycity');
  36.         $pharmacies PharmacyPoint::getByUrlCity($city, ['limit' => 0]);
  37.         $cityObject PharmacyCity::getByUrl($city, ['limit' => 1]);
  38.         return $this->render('Pharmacy/city.html.twig', [
  39.             'pharmacies' => $pharmacies,
  40.             'city' => $cityObject,
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("{pathpharmacy}/{pharmacycity}/{pharmacystreet}", name="pharmacy-detail", defaults={"pathjoboffer"=""}, requirements={"pathpharmacy":"apteki-stacjonarne", "pharmacycity"="[\w\p{L}-]+", "pharmacystreet"="[\w\p{L}./-]+"}, options={"utf8"=true})
  45.      */
  46.     public function detailAction(Request $requestJobOfferLinkGenerator $pharmacyPointLinkGenerator): Response
  47.     {
  48.         $city $request->get('pharmacycity');
  49.         $street $request->get('pharmacystreet');
  50.         $pharmacyUrl $city '/' $street;
  51.         $pharmacy PharmacyPoint::getByUrl($pharmacyUrl, ['limit' => 1]);
  52.         $cityObject PharmacyCity::getByUrl($city, ['limit' => 1]);
  53.         $pharmacies PharmacyPoint::getByUrlCity($city, ['limit' => 0]);
  54.         if (!($pharmacy instanceof PharmacyPoint && ($pharmacy->isPublished() || $this->verifyPreviewRequest($request$pharmacy)))) {
  55.             throw new NotFoundHttpException('PharmacyPoint not found.');
  56.         }
  57.         return $this->render('Pharmacy/detail.html.twig', [
  58.             'pharmacyObject' => $pharmacy,
  59.             'city' => $city,
  60.             'street' => $street,
  61.             'pharmacies' => $pharmacies,
  62.             'cityObject' => $cityObject,
  63.         ]);
  64.     }
  65. }