<?php
namespace App\Controller\Frontend;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Misc\ImageUrlHelper;
use App\Utilities\ServiceUtil;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Annotation\Route;
use App\Annotation\Log;
use App\Exception\BadRequestException;
use App\Misc\CaptchaHelper;
class AdmissionEnController extends BaseFrontendController
{
/**
* @Route("/landing-agency/{slug}", name="admission", requirements={"slug": "[a-zA-Z0-9\-]+"})
*/
public function index($slug) {
$landing = $this->landingpageRepo->findOneBy(['slug' => $slug, 'isAgent' => 1]);
if (!$landing) {
return $this->render('pages/404.html.twig');
}
$this->addTitle('Admission');
$this->setDescription('Admission');
$data = [];
$data['landing'] = $this->landingpageService->autoMapper->map($landing, 'App\DTO\Landingpage\LandingpageOutput');
$data['studyLevels'] = $this->studyLevelRepository->findAll();
$data['cursuses'] = $this->cursusRepository->findAll();
$data['programsByLevel'] = $this->programService->getActiveProgramGroupByLevel();
// dd($data['programsByLevel']);
$france = $this->countryRepo->find(1);
$data['countries'] = array_merge([$france], $this->countryRepo->getAll(['except_id' => 1, 'sort_asc' => 'name'], 'ENTITY'));
$data['departments'] = array_map(function ($department) {
return ['value' => $department, 'text' => $department];
}, $this->commonService->frenchDepartments);
$data['campuses'] = $this->campusRepository->getAll(['filter_status' => 1, 'memberOf_programs' => 'notNull','sort_asc' => 'ordering'], 'ENTITY');
$year = date("Y");
if (date("Y-m-d") > date("Y") . '-10-01') {
$data['year'] = date('Y', strtotime('+1 year')) . '-' . date('Y', strtotime('+2 year'));
} else {
$data['year'] = $year . '-' . date('Y', strtotime('+1 year'));
}
return $this->render(
'admission/index.html.twig',
$data
);
}
/**
* @Rest\Get("/admission/campus", name="programs_by_campus")
*/
public function getLandingPage(Request $request)
{
$id = $request->get('campus');
$programsByLevel = $this->programService->getActiveProgramGroupByLevel($id);
$select = $this->container->get('twig')->render('admission/program_campus.html.twig', [
'programsByLevel' => $programsByLevel
]);
return $this->json(ServiceUtil::processSuccessful(['html' => $select]));
}
/**
* @Rest\Post("/save-landing-page-agent", name="landingpage_agent.save")
* @Log
*/
public function save(
Request $request,
CaptchaHelper $captchaHelper,
TranslatorInterface $translator
) {
try {
$this->landingpageService->addProfileInLandingPage($request, 'App\DTO\Profile\AddProfileLandingpageInput');
return $this->json(ServiceUtil::processSuccessful());
} catch (BadRequestException $badRequestException) {
$messagesArr = $badRequestException->getMessages();
foreach ($messagesArr['data'] as $field => $message) {
$errorMessage = $message;
break;
}
}
$data['errorMessage'] = $errorMessage;
return $this->json(ServiceUtil::processFailed($data));
}
}