<?php
declare(strict_types=1);
/**
* @author Mehrez Labidi
*/
namespace App\Controller;
use App\Services\MetaTag;
use App\Helper\Utils;
use App\Services\ManagerEntity\EvaluationsFormationsManagers;
use App\Services\ManagerEntity\FormationsManager;
use App\Services\PDFGenerator;
use Symfony\Component\HttpFoundation\Response;
use App\Twig\TranslationExtension;
use Symfony\Component\HttpFoundation\Request;
class FormationController extends EntityUsingController {
public const MAX_AGE = 43200; // 12heures
public const REF_EXPERT = ["MOD34", "MOD32", "MOD01", "MOD16", "MOD35", "MOD02", "MOD01"];
/**
* @var \App\Services\PDFGenerator
*/
private $pg;
/**
* @var \App\Services\ManagerEntity\EvaluationsFormationsManagers
*/
private $efm;
/**
* @var FormationsManager
*/
private $fm;
/**
* @var MetaTag
*/
private $metaTag;
public function __construct(FormationsManager $fm, PDFGenerator $pg, EvaluationsFormationsManagers $efm, MetaTag $metaTag) {
$this->fm = $fm;
$this->pg = $pg;
$this->efm = $efm;
$this->metaTag = $metaTag;
}
/**
* @throws \Exception
*/
public function index(): Response {
$jrFormations = array_slice($this->fm->getFormationJR(true, null, 10), 0, 3);
$expertsFormations = $this->fm->getFormationExpert(true, null, null);
$expertsFormations = Utils::array_unique_multidiemension($expertsFormations);
$repriseCommerceFormations = array_slice($this->fm->getFormationRepriseCommerce(true, true, 10), 0, 3);
$croissanceExterneFormations = array_slice($this->fm->getFormationCroissanceExterne(true, null, 10), 0, 3);
$idRefFormations = $this->fm->getIdRefTitreFormations();
return $this->render('formation/index.html.twig', [
'controller_name' => 'FormationController',
'jrFormations' => $jrFormations,
'idRefFormations' => $idRefFormations,
'expertsFormations' => $expertsFormations,
'rcFormations' => $repriseCommerceFormations,
'ceFormations' => $croissanceExterneFormations,
]);
}
/**
* @param $idformation
* @param $date
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Exception
*/
public function detail(Request $request, TranslationExtension $translationExtension, $idformation, $date) {
if (!$idformation) {
throw $this->createNotFoundException('No Formation found for id ' . $idformation);
}
$formation = $this->fm->getFormationDetail($idformation);
$autresDates = $this->fm->getAutresSession($formation['reference']);
if (!in_array($formation['reference'], ["JR1", "JR2", "JR3", "CE1", "CE2", "CE3", "PDC01", "PDC02", "PDC03"])) {// session expert seulement
$autresDates = $this->fm->getAutresSessionExpert($formation['reference']);
}
$prochaineDates = $this->fm->getProchaineDate($formation['reference']);
$currentDateSession = (Utils::isValidDate($date)) ? Utils::getDateObjectFromFUSACQDate($date) : NULL;
$formationsRelated = $this->fm->getFormationsRelated($idformation);
$formation_expert = (bool) in_array($formation['reference'], self::REF_EXPERT);
if (in_array($formation['reference'], ["JR1", "JR2", "JR3"])) {
$metaTitle = 'formation à la reprise d\'entreprise - devenez un repreneur opérationnel en trois jours';
$metaDescription = 'formation à la reprise d\'entreprise - devenez un repreneur opérationnel en trois jours';
} elseif (in_array($formation['reference'], ["CE1", "CE2", "CE3"])) {
$metaTitle = 'formation à la croissance externe - réussir votre opération de croissance externe';
$metaDescription = 'formation à la croissance externe - réussir votre opération de croissance externe';
} elseif (in_array($formation['reference'], ["PDC01", "PDC02", "PDC03"])) {
$metaTitle = 'formation à la reprise de commerce - 3 jours pour comprendre comment';
$metaDescription = 'formation à la reprise de commerce - 3 jours pour comprendre comment';
} elseif (in_array($formation['reference'], self::REF_EXPERT)) {
$metaTitle = 'formations "Expert" - savoir lire et analyser un Bilan et un Compte de résultat, sur 2 jours';
$metaDescription = 'Formations "Expert" - savoir lire et analyser un Bilan et un Compte de résultat, sur 2 jours';
} else {
$metaTitle = 'formation à la reprise d\'entreprise, et formations pour les experts en fusions-acquisitions';
$metaDescription = 'Participez à nos formation à la reprise d\'entreprise et formations pour les experts en fusions-acquisitions';
}
$lang = $request->getSession()->get('lang');
$metaTag = $this->metaTag
->setTitle($translationExtension->translate($metaTitle, $lang, "", "M", ""))
->setDescription($translationExtension->translate($metaDescription, $lang, "", "M", ""));
return $this->render('formation/detail.html.twig', [
'metaTag' => $metaTag,
'controller_name' => 'FormationController',
'formation' => $formation, "formation_expert" => $formation_expert,
'prochaineDates' => $prochaineDates, 'formationsRelated' => $formationsRelated,
'autresDates' => $autresDates,
'currentDateSession' => $currentDateSession,
]);
}
/**
* @param $idformation
*/
public function downloadProgram($idformation) {
if (!$idformation) {
throw $this->createNotFoundException('No Formation found for id ' . $idformation);
}
$url = $this->fm->getUrlProgram($idformation);
if (!$url) {
throw $this->createNotFoundException('No program found for id ' . $url);
}
return $this->pg->displayPDFByURL($url);
}
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function financements() {
$response = $this->render('formation/financements.html.twig',
['controller_name' => 'FormationController']
);
$response->setPublic();
$response->setMaxAge(self::MAX_AGE); // 12heures
return $response;
}
/**
* @return Response
*/
public function detailFinancements(): Response {
$response = $this->render('formation/detail_financements.html.twig',
['controller_name' => 'FormationController']
);
$response->setPublic();
$response->setMaxAge(self::MAX_AGE); // 12heures
return $response;
}
/**
* @param $idformation
* @param $date
*/
public function evaluations(Request $request, TranslationExtension $translationExtension, $idformation, $reference): Response {
if (!$idformation) {
throw $this->createNotFoundException('No Formation found for id ' . $idformation);
}
$evaluations = $this->efm->getEvaluationsByRefFormation($reference, null);
$formation = $this->fm->getFormationDetail($idformation);
$autresDates = $this->fm->getAutresSession($formation['reference']);
$prochaineDates = $this->fm->getProchaineDate($formation['reference']);
$formationsRelated = $this->fm->getFormationsRelated($idformation);
$formation_expert = (bool) in_array($formation['reference'], self::REF_EXPERT);
if (in_array($formation['reference'], ["JR1", "JR2", "JR3"])) {
$metaTitle = 'évaluation de la formation à la reprise d\'entreprise - devenez un repreneur opérationnel en trois jours';
$metaDescription = 'consultez les évaluations de la formation à la reprise d\'entreprise - devenez un repreneur opérationnel en trois jours';
} elseif (in_array($formation['reference'], ["CE1", "CE2", "CE3"])) {
$metaTitle = 'évaluation des formation à la croissance externe - réussir votre opération de croissance externe';
$metaDescription = 'consultez les évaluations des formation à la croissance externe - réussir votre opération de croissance externe';
} elseif (in_array($formation['reference'], ["PDC01", "PDC02", "PDC03"])) {
$metaTitle = 'évaluation des formation à la reprise de commerce - 3 jours pour comprendre comment';
$metaDescription = 'consultez les évaluations des formation à la reprise de commerce - 3 jours pour comprendre comment';
} elseif (in_array($formation['reference'], self::REF_EXPERT)) {
$metaTitle = 'évaluation des formations "Expert" - savoir lire et analyser un Bilan et un Compte de résultat, sur 2 jours';
$metaDescription = 'consultez les évaluations des Formations "Expert" - savoir lire et analyser un Bilan et un Compte de résultat, sur 2 jours';
} else {
$metaTitle = 'formation à la reprise d\'entreprise, et formations pour les experts en fusions-acquisitions';
$metaDescription = 'Participez à nos formation à la reprise d\'entreprise et formations pour les experts en fusions-acquisitions';
}
$lang = $request->getSession()->get('lang');
$metaTag = $this->metaTag
->setTitle($translationExtension->translate($metaTitle, $lang, "", "M", ""))
->setDescription($translationExtension->translate($metaDescription, $lang, "", "M", ""));
return $this->render('formation/evaluations.html.twig', [
'metaTag' => $metaTag,
'controller_name' => 'FormationController',
'evaluations' => $evaluations, "formation_expert" => $formation_expert,
'formation' => $formation,
'prochaineDates' => $prochaineDates, 'formationsRelated' => $formationsRelated,
'autresDates' => $autresDates,
]);
}
public function listeFormationsExpert(): Response {
$formationsAll = $this->fm->getFormationExpert();
$formationsPrecis = array_filter($formationsAll, fn($item) => ($item["date_formation"] != "A venir"));
$formationsAvenir = array_filter($formationsAll, fn($item) => ( $item["date_formation"] == "A venir"));
$formations = array_merge($formationsPrecis, $formationsAvenir);
$listRef = [];
foreach ($formations as $key => $value) {
$listRef[] = $value["reference"];
if ($value["date_formation"] == "A venir" && in_array($value["reference"], $listRef)) {
// unset($formations[$key]);
}
}
$formations = Utils::array_unique_multidiemension($formations);
$metaTag = $this->metaTag
->setTitle("Formations à Transmission d'entreprise pour les professionnels")
->setDescription("Formations à Transmission d'entreprise pour les professionnels");
return $this->render('formation/liste_formations_expert.html.twig', [
'controller_name' => 'FormationController', 'formations' => $formations,
'metaTag' => $metaTag,
]);
}
/**
*
* @param Request $request
* @param type $codePays
* @return Response
*/
public function temoignagesFormation(Request $request, $codePays): Response {
$filters = $request->query->all();
$temoignages = $this->fm->getTemoignagesFormation($filters);
$rangesDates = range(date("Y"), date("Y") - 5);
$response = $this->render('formation/temoignages_formation.html.twig',
[
'controller_name' => 'FormationController',
'temoignages' => $temoignages, "rangesDates" => $rangesDates
]
);
$response->setPublic();
$response->setMaxAge(self::MAX_AGE); // 12heures
return $response;
}
}