src/Controller/Customer/Delivery/DeliveryController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Customer\Delivery;
  3. use App\Entity\Configuration;
  4. use App\Entity\DeliveryPoint;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Exception;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class DeliveryController extends AbstractController
  11. {
  12.     /**
  13.      * Docasna fce pro obecne variables
  14.      * @param EntityManagerInterface $entityManager
  15.      * @param string $type
  16.      * @param string $value
  17.      * @return string
  18.      * @throws Exception
  19.      */
  20.     public function variableData(EntityManagerInterface $entityManager$type$value): string
  21.     {
  22.         if ($type === 'configuration') {
  23.             $repo $entityManager->getRepository(Configuration::class);
  24.             $data $repo->get($value);
  25.         } elseif ($type === 'prices') {
  26.             $prices = [
  27.                 'delivery_price' => '29 Kč',
  28.                 'flat_rate' => '1000 Kč',
  29.                 'per_consignment' => '5 Kč',
  30.                 'initial_fee' => '1000 Kč'
  31.             ];
  32.             $data $prices[$value];
  33.         } else {
  34.             $data 'missing value!';
  35.         }
  36.         return ($data);
  37.     }
  38.     /**
  39.      * Stranka Homepage
  40.      * @return Response
  41.      */
  42.     public function index(): Response
  43.     {
  44.         return $this->render(
  45.             'Customer/Delivery/index.html.twig'
  46.         );
  47.     }
  48.     /**
  49.      * Stranka Vyhledat supervydejnu
  50.      * @param EntityManagerInterface $entityManager
  51.      * @return Response
  52.      */
  53.     public function deliveryPoints(EntityManagerInterface $entityManager): Response
  54.     {
  55.         $deliveryPointRepo $entityManager->getRepository(DeliveryPoint::class);
  56.         $deliveryPoints $deliveryPointRepo->getPointsForMap();
  57.         return $this->render(
  58.             'Customer/Delivery/delivery_points.html.twig',
  59.             [
  60.                 'deliveryPoints' => $deliveryPoints,
  61.             ]
  62.         );
  63.     }
  64.     /**
  65.      * Stránka detail výdejny
  66.      * @param EntityManagerInterface $em
  67.      * @param TranslatorInterface $translator
  68.      * @param string $code
  69.      * @return Response
  70.      */
  71.     public function detail(EntityManagerInterface $emTranslatorInterface $translatorstring $code): Response
  72.     {
  73.         $delPointRepo $em->getRepository(DeliveryPoint::class);
  74.         $deliveryPoint $delPointRepo->findOneBy(['code' => $code]);
  75.         if (is_null($deliveryPoint) || !$deliveryPoint->isActive()) {
  76.             $this->addFlash(
  77.                 'error',
  78.                 $translator->trans(
  79.                     'Výdejní místo: %code% nenalezeno. Výdejna byla uzavřena, nebo máte špatný kód.',
  80.                     ['%code%' => $code],
  81.                     'customer'
  82.                 )
  83.             );
  84.             return $this->redirectToRoute('customer_delivery_points');
  85.         }
  86.         $holidays $delPointRepo->getFutureOrActiveHolidays($deliveryPoint);
  87.         return $this->render(
  88.             'Customer/Delivery/detail.html.twig',
  89.             [
  90.                 'dp' => $deliveryPoint,
  91.                 'isAcceptingNewPackages' => $delPointRepo->isAcceptingNewPackages($deliveryPoint),
  92.                 'holidays' => $holidays
  93.             ]
  94.         );
  95.     }
  96.     /**
  97.      * Stranka Pro e-shopy
  98.      * @param EntityManagerInterface $em
  99.      * @return Response
  100.      */
  101.     public function b2b(EntityManagerInterface $em): Response
  102.     {
  103.         return $this->render(
  104.             'Customer/Delivery/b2b.html.twig',
  105.             [
  106.                 'support_delivery_email' => $this->variableData($em'configuration''support_delivery_email'),
  107.                 'support_delivery_phone' => $this->variableData($em'configuration''support_delivery_phone'),
  108.                 'delivery_price' => $this->variableData($em'prices''delivery_price'),
  109.             ]
  110.         );
  111.     }
  112.     /**
  113.      * Stranka Kontakt
  114.      * @param EntityManagerInterface $em
  115.      * @return Response
  116.      */
  117.     public function contact(EntityManagerInterface $em): Response
  118.     {
  119.         return $this->render(
  120.             'Customer/Delivery/contact.html.twig',
  121.             [
  122.                 'support_delivery_email' => $this->variableData($em'configuration''support_delivery_email'),
  123.                 'support_delivery_phone' => $this->variableData($em'configuration''support_delivery_phone'),
  124.                 'support_delivery_phone_is_shown' => $this->variableData($em'configuration''support_delivery_phone_is_shown'),
  125.                 'depo_address_street' => $this->variableData($em'configuration''depo_address_street'),
  126.                 'depo_address_city' => $this->variableData($em'configuration''depo_address_city'),
  127.                 'depo_address_zipcode' => $this->variableData($em'configuration''depo_address_zipcode'),
  128.                 'billing_address_street' => $this->variableData($em'configuration''billing_address_street'),
  129.                 'billing_address_zipcode' => $this->variableData($em'configuration''billing_address_zipcode'),
  130.                 'billing_address_city' => $this->variableData($em'configuration''billing_address_city'),
  131.                 'billing_address_company_reg_number' => $this->variableData($em'configuration''billing_address_company_reg_number'),
  132.                 'billing_address_vat_number' => $this->variableData($em'configuration''billing_address_vat_number'),
  133.             ]
  134.         );
  135.     }
  136.     /**
  137.      * Informace v paticce
  138.      * @param TranslatorInterface $translator
  139.      * @param EntityManagerInterface $em
  140.      * @return Response
  141.      */
  142.     public function getContactInfo(TranslatorInterface $translatorEntityManagerInterface $em): Response
  143.     {
  144.         $email $this->variableData($em'configuration''support_delivery_email');
  145. //        $phone = $this->variableData($em, 'configuration', 'support_delivery_phone');
  146.         return new Response(
  147.             $translator->trans(
  148.                 'Kontaktujte nás na adrese: %email%',// nebo na telefonním čísle: %phone%.',
  149.                 [
  150.                     '%email%' => $email,
  151. //                    '%phone%' => $phone
  152.                 ],
  153.                 'customer'
  154.             )
  155.         );
  156.     }
  157.     /**
  158.      * Stranka s obchodnimi podminkami
  159.      *
  160.      * @return Response
  161.      */
  162.     public function termsAndConditions(): Response
  163.     {
  164.         return $this->render('Customer/Delivery/terms_and_conditions.html.twig', []);
  165.     }
  166. }