<?php
namespace App\Controller\Customer\Delivery;
use App\Entity\Configuration;
use App\Entity\DeliveryPoint;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
class DeliveryController extends AbstractController
{
/**
* Docasna fce pro obecne variables
* @param EntityManagerInterface $entityManager
* @param string $type
* @param string $value
* @return string
* @throws Exception
*/
public function variableData(EntityManagerInterface $entityManager, $type, $value): string
{
if ($type === 'configuration') {
$repo = $entityManager->getRepository(Configuration::class);
$data = $repo->get($value);
} elseif ($type === 'prices') {
$prices = [
'delivery_price' => '29 Kč',
'flat_rate' => '1000 Kč',
'per_consignment' => '5 Kč',
'initial_fee' => '1000 Kč'
];
$data = $prices[$value];
} else {
$data = 'missing value!';
}
return ($data);
}
/**
* Stranka Homepage
* @return Response
*/
public function index(): Response
{
return $this->render(
'Customer/Delivery/index.html.twig'
);
}
/**
* Stranka Vyhledat supervydejnu
* @param EntityManagerInterface $entityManager
* @return Response
*/
public function deliveryPoints(EntityManagerInterface $entityManager): Response
{
$deliveryPointRepo = $entityManager->getRepository(DeliveryPoint::class);
$deliveryPoints = $deliveryPointRepo->getPointsForMap();
return $this->render(
'Customer/Delivery/delivery_points.html.twig',
[
'deliveryPoints' => $deliveryPoints,
]
);
}
/**
* Stránka detail výdejny
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
* @param string $code
* @return Response
*/
public function detail(EntityManagerInterface $em, TranslatorInterface $translator, string $code): Response
{
$delPointRepo = $em->getRepository(DeliveryPoint::class);
$deliveryPoint = $delPointRepo->findOneBy(['code' => $code]);
if (is_null($deliveryPoint) || !$deliveryPoint->isActive()) {
$this->addFlash(
'error',
$translator->trans(
'Výdejní místo: %code% nenalezeno. Výdejna byla uzavřena, nebo máte špatný kód.',
['%code%' => $code],
'customer'
)
);
return $this->redirectToRoute('customer_delivery_points');
}
$holidays = $delPointRepo->getFutureOrActiveHolidays($deliveryPoint);
return $this->render(
'Customer/Delivery/detail.html.twig',
[
'dp' => $deliveryPoint,
'isAcceptingNewPackages' => $delPointRepo->isAcceptingNewPackages($deliveryPoint),
'holidays' => $holidays
]
);
}
/**
* Stranka Pro e-shopy
* @param EntityManagerInterface $em
* @return Response
*/
public function b2b(EntityManagerInterface $em): Response
{
return $this->render(
'Customer/Delivery/b2b.html.twig',
[
'support_delivery_email' => $this->variableData($em, 'configuration', 'support_delivery_email'),
'support_delivery_phone' => $this->variableData($em, 'configuration', 'support_delivery_phone'),
'delivery_price' => $this->variableData($em, 'prices', 'delivery_price'),
]
);
}
/**
* Stranka Kontakt
* @param EntityManagerInterface $em
* @return Response
*/
public function contact(EntityManagerInterface $em): Response
{
return $this->render(
'Customer/Delivery/contact.html.twig',
[
'support_delivery_email' => $this->variableData($em, 'configuration', 'support_delivery_email'),
'support_delivery_phone' => $this->variableData($em, 'configuration', 'support_delivery_phone'),
'support_delivery_phone_is_shown' => $this->variableData($em, 'configuration', 'support_delivery_phone_is_shown'),
'depo_address_street' => $this->variableData($em, 'configuration', 'depo_address_street'),
'depo_address_city' => $this->variableData($em, 'configuration', 'depo_address_city'),
'depo_address_zipcode' => $this->variableData($em, 'configuration', 'depo_address_zipcode'),
'billing_address_street' => $this->variableData($em, 'configuration', 'billing_address_street'),
'billing_address_zipcode' => $this->variableData($em, 'configuration', 'billing_address_zipcode'),
'billing_address_city' => $this->variableData($em, 'configuration', 'billing_address_city'),
'billing_address_company_reg_number' => $this->variableData($em, 'configuration', 'billing_address_company_reg_number'),
'billing_address_vat_number' => $this->variableData($em, 'configuration', 'billing_address_vat_number'),
]
);
}
/**
* Informace v paticce
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @return Response
*/
public function getContactInfo(TranslatorInterface $translator, EntityManagerInterface $em): Response
{
$email = $this->variableData($em, 'configuration', 'support_delivery_email');
// $phone = $this->variableData($em, 'configuration', 'support_delivery_phone');
return new Response(
$translator->trans(
'Kontaktujte nás na adrese: %email%',// nebo na telefonním čísle: %phone%.',
[
'%email%' => $email,
// '%phone%' => $phone
],
'customer'
)
);
}
/**
* Stranka s obchodnimi podminkami
*
* @return Response
*/
public function termsAndConditions(): Response
{
return $this->render('Customer/Delivery/terms_and_conditions.html.twig', []);
}
}