<?php
namespace App\Controller\Frontend;
use App\Entity\OurStudent;
use App\Entity\Program;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class ProgramController extends BaseFrontendController
{
/**
* @Route("/{_locale}/{level}-estiam", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="level")
*/
public function level($level, Request $request, TranslatorInterface $translator): Response
{
$arrLevels = ['bts' => 1, 'bachelor' => 2, 'mba' => 3];
$this->addTitle($translator->trans('title.program-level-' . $level));
$this->setDescription($translator->trans('desc.program-level-' . $level));
if (isset($arrLevels[$level])) {
$data = [];
$data['cursus'] = null;
$data['level'] = $arrLevels[$level];
$programs = $this->currentService->repository->findBy(['level' => $arrLevels[$level], 'status' => 1], ['name' => 'ASC']);
if ($programs) {
$data['programs'] = $this->currentService->autoMapper->mapMultiple($programs, 'App\DTO\Program\ProgramOutput');
} else {
$data['programs'] = null;
}
if ($arrLevels[$level] == 3) {
$cursus = $this->cursusService->repository->findAll();
if ($cursus) {
$data['cursus'] = $this->cursusService->autoMapper->mapMultiple($cursus, 'App\DTO\Cursus\CursusOutput');
}
}
} else {
return $this->render('pages/404.html.twig');
}
return $this->render('programs/level.html.twig', $data);
}
/**
* @Route("/{_locale}/tarifs", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="tarifs")
*/
public function tarifs(TranslatorInterface $translator): Response
{
$siteName = $this->getParameter('site_name');
$this->addTitle($translator->trans('tarifs.title', [
'%siteName%' => $siteName
]));
$this->setDescription($translator->trans('tarifs.desc',[
'%siteName%' => $siteName
]));
return $this->render('programs/price.html.twig', []);
}
/**
* @Route("/{_locale}/formation-{slug}-alternance", requirements={"_locale": "en|fr", "slug": "[a-zA-Z0-9\-]+","id": "[0-9]+"}, defaults={"_locale"="fr"}, name="program_detail")
*/
public function programDetail($slug, Request $request, TranslatorInterface $translator): Response
{
$program = $this->currentService->repository->findOneBy(['slug' => $slug, 'status' => 1]);
if(!$program) {
return $this->render('pages/404.html.twig');
}
//301 redirect program no alternance
return $this->redirect('/fr/formation-' . $program->getSlug());
}
/**
* @Route("/{_locale}/formation-{slug}", requirements={"_locale": "en|fr", "slug": "[a-zA-Z0-9\-]+","id": "[0-9]+"}, defaults={"_locale"="fr"}, name="program_detail_no_alternance")
*/
public function programDetailNoAlternance($slug, Request $request, TranslatorInterface $translator): Response
{
$data = [];
$program = $this->currentService->repository->findOneBy(['slug' => $slug, 'status' => 1]);
if ($program) {
$data['outStudentVideos'] = $this->ourStudentRepo->getAllOurStudentByType(OurStudent::TYPE_VIDEO, 3);
$data['program'] = $this->currentService->autoMapper->map($program, 'App\DTO\Program\ProgramOutput');
$programTranning = [];
if ($data['program']->level == 1) {
$data['tranningText'] = Program::TRANNING_BTS;
} elseif ($data['program']->level == 2) {
$data['tranningText'] = Program::TRANNING_BACHELOR;
} elseif ($data['program']->level == 3) {
$data['tranningText'] = Program::TRANNING_MBA;
}
} else {
return $this->render('pages/404.html.twig');
}
$this->addTitle(
isset($data['program']->metadata['tags']['seoTitle']) ? $data['program']->metadata['tags']['seoTitle'] : $translator->trans('program.title', [
'%programName%' => $data['program']->name,
'%level%' => $translator->trans('program_level' . ($data['program']->level))
])
);
$this->setDescription(isset($data['program']->metadata['tags']['seoDescription']) ? $data['program']->metadata['tags']['seoDescription'] : $data['program']->description);
return $this->render('programs/program_detail.html.twig', $data);
}
}