<?php
namespace App\Controller\Customer;
use App\Entity\CarrierPricePostman;
use App\Entity\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
class StaticPagesController extends AbstractController
{
/**
* Zobrazí robots.txt nad customer částí
* Na customer můžeme povolit robotům přístup ke všemu vyjma trackingu.
* @return Response
*/
public function robotsTxtFile(): Response
{
$response = new Response(
implode("\n", [
'User-agent: *',
'Disallow: /track-and-trace/',
]),
200
);
$response->headers->set('Content-Type', 'text/plain; charset=utf-8');
return $response;
}
/**
* Stranka O nas
* @return Response
*/
public function aboutUs(): Response
{
return $this->render('Customer/Postman/about_us.html.twig', []);
}
/**
* Stranka Intro
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @return Response
*/
public function index(TranslatorInterface $translator, EntityManagerInterface $em): Response
{
$carrierPricePostmanRepo = $em->getRepository(CarrierPricePostman::class);
$countries = $carrierPricePostmanRepo->getLowestNeighbourPrices($translator);
return $this->render('Customer/Postman/index.html.twig', ['countries' => $countries]);
}
/**
* Stranka s Kontaktnimi informacemi
* @param EntityManagerInterface $em
* @return Response
* @throws Exception
*/
public function contact(EntityManagerInterface $em): Response
{
$config = $em->getRepository(Configuration::class);
return $this->render('Customer/Postman/contact.html.twig', [
'support_postman_email' => $config->get('support_postman_email'),
'support_postman_phone' => $config->get('support_postman_phone'),
'depo_address_street' => $config->get('depo_address_street'),
'depo_address_city' => $config->get('depo_address_city'),
'depo_address_zipcode' => $config->get('depo_address_zipcode'),
]);
}
/**
* Stranka Pro firmy
* @param EntityManagerInterface $em
* @return Response
* @throws Exception
*/
public function b2b(EntityManagerInterface $em): Response
{
$config = $em->getRepository(Configuration::class);
return $this->render('Customer/Postman/b2b.html.twig', [
'support_postman_email' => $config->get('support_postman_email'),
'support_postman_phone' => $config->get('support_postman_phone'),
]);
}
/**
* Stranka s obchodnimi podminkami
*
* @return Response
*/
public function termsAndConditions(): Response
{
return $this->render('Customer/Postman/terms_and_conditions.html.twig', []);
}
/**
* Vraci kontaktni informace do paticky
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @return Response
*/
public function getContactInfo(TranslatorInterface $translator, EntityManagerInterface $em): Response
{
$configRepo = $em->getRepository(Configuration::class);
try {
$email = $configRepo->get('support_postman_email');
// $phone = $configRepo->get('support_delivery_phone');
} catch (Exception $ex) {
$email = '';
// $phone = '';
}
return new Response(
$translator->trans(
'Kontaktujte nás na adrese: %email% nebo na telefonním čísle: %phone%.',
[
'%email%' => $email,
// '%phone%' => $phone
],
'customer'
)
);
}
/**
* Nacita stranku ceniku - tabulek s cenou pro kazdou zemi
* @param EntityManagerInterface $em
* @return Response
* @throws Exception
*/
public function priceList(EntityManagerInterface $em): Response
{
$config = $em->getRepository(Configuration::class);
$carrierPricePostmanRepo = $em->getRepository(CarrierPricePostman::class);
$countries = $carrierPricePostmanRepo->getCarrierPrices();
$output = [];
foreach ($countries as $country) {
$output[$country->getCountry()->getName()][$country->getCountry()->getIso()][$country->getWeight(
)] = $country->getPriceSell();
}
return $this->render(
'Customer/Postman/price_list.html.twig',
[
'support_postman_email' => $config->get('support_postman_email'),
'support_postman_phone' => $config->get('support_postman_phone'),
'countries' => $output
]
);
}
}