<?php
declare(strict_types=1);
namespace AppBundle\Controller;
use AppBundle\Website\LinkGenerator\JobOfferLinkGenerator;
use Pimcore\Model\DataObject\PharmacyCity;
use Pimcore\Model\DataObject\PharmacyCity\Listing;
use Pimcore\Model\DataObject\PharmacyPoint;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class PharmacyController extends BaseController
{
public function defaultAction(): Response
{
$cities = new Listing();
$cities->setOrderKey('cityName');
$cities->setOrder('asc');
$cities->setLimit(0);
return $this->render('Pharmacy/default.html.twig', [
'cities' => $cities,
]);
}
/**
* @Route(
* "{pathpharmacy}/{pharmacycity}",
* name="pharmacy-city-list",
* defaults={"pathjoboffer"=""},
* requirements={"pathpharmacy":"apteki-stacjonarne", "pharmacycity"="[\w\p{L}-]+"},
* options={"utf8"=true}
* )
*/
public function cityAction(Request $request): Response
{
$city = $request->get('pharmacycity');
$pharmacies = PharmacyPoint::getByUrlCity($city, ['limit' => 0]);
$cityObject = PharmacyCity::getByUrl($city, ['limit' => 1]);
return $this->render('Pharmacy/city.html.twig', [
'pharmacies' => $pharmacies,
'city' => $cityObject,
]);
}
/**
* @Route("{pathpharmacy}/{pharmacycity}/{pharmacystreet}", name="pharmacy-detail", defaults={"pathjoboffer"=""}, requirements={"pathpharmacy":"apteki-stacjonarne", "pharmacycity"="[\w\p{L}-]+", "pharmacystreet"="[\w\p{L}./-]+"}, options={"utf8"=true})
*/
public function detailAction(Request $request, JobOfferLinkGenerator $pharmacyPointLinkGenerator): Response
{
$city = $request->get('pharmacycity');
$street = $request->get('pharmacystreet');
$pharmacyUrl = $city . '/' . $street;
$pharmacy = PharmacyPoint::getByUrl($pharmacyUrl, ['limit' => 1]);
$cityObject = PharmacyCity::getByUrl($city, ['limit' => 1]);
$pharmacies = PharmacyPoint::getByUrlCity($city, ['limit' => 0]);
if (!($pharmacy instanceof PharmacyPoint && ($pharmacy->isPublished() || $this->verifyPreviewRequest($request, $pharmacy)))) {
throw new NotFoundHttpException('PharmacyPoint not found.');
}
return $this->render('Pharmacy/detail.html.twig', [
'pharmacyObject' => $pharmacy,
'city' => $city,
'street' => $street,
'pharmacies' => $pharmacies,
'cityObject' => $cityObject,
]);
}
}