<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\RefPoste;
use App\Entity\RefRole;
use App\Entity\UtilisateurInformation;
use App\Entity\Conge;
use App\Entity\DemandeReport;
use App\Entity\FormationSession;
use App\Entity\Workflow;
use App\Entity\Utilisateur;
use App\Entity\ListeDiffusion;
use App\Entity\ListeDiffusionSup;
use App\Entity\DocumentService;
use App\Entity\Odm;
use App\Entity\ProjetLettreMission;
use App\Entity\RFederation;
use App\Entity\RefAffectation;
use Doctrine\Persistence\ManagerRegistry;
/**
* Description of HomeController
*
* @author Maxime Dequant
*/
class HomeController extends AbstractController
{
private ManagerRegistry $doctrine;
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}
#[Route(path: '/api/home', name: 'ctsweb_front_homepage')]
public function Index(): \Symfony\Component\HttpFoundation\RedirectResponse
{
return $this->redirect('/_profiler');
}
#[Route(path: '/api/modif_profil', name: 'ctsweb_modifier_profil')]
public function ModifierProfil(Request $request)
{
$success = false;
$em = $this->doctrine->getManager();
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
$request->request->replace(is_array($data) ? $data : []);
$dataRequest = $request->request->all();
$address = ($dataRequest['address'] ?? null);
$telBur = ($dataRequest['phone'] ?? "");
$telPor = ($dataRequest['phoneMobile'] ?? "");
$email = ($dataRequest['email'] ?? "");
$scan = ($dataRequest['scan'] ?? "");
$error = false;
if (!preg_match('/^[A-Za-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/', (string) $email)) {
$error = "L'adresse mail n'est pas correcte";
}
if ($telBur) {
if (!preg_match('/^0[1-5|8|9]\d{8}$/', (string) $telBur)) {
$error = "Le numéro de téléphone de bureau entré n'est pas valide";
}
}
if ($telPor) {
if (!preg_match('/^0(6|7)\d{8}$/', (string) $telPor)) {
$error = "Le numéro de téléphone portable entré n'est pas valide";
}
}
if (!$error) {
$utilisateurI = $this->getUser();
$utilisateurI->getUtilisateur()->setCourriel($email);
$utilisateurInformation = $this->GetUserInfos();
if ($telBur) {
$utilisateurI->getUtilisateur()->setTelephoneBureau($telBur);
} else {
$utilisateurI->getUtilisateur()->setTelephoneBureau(null);
}
if ($telPor) {
$utilisateurI->getUtilisateur()->setTelephonePortable($telPor);
} else {
$utilisateurI->getUtilisateur()->setTelephonePortable(null);
}
$utilisateurI->setAdresse($address);
$repositoryUI = $this->doctrine->getManager()->getRepository(Utilisateur::class);
$utilisateurData = $repositoryUI->find($utilisateurI->getIdUtilisateur());
$utilisateurData->setDateConnexion(date_format(new \DateTime(), "Y-m-d H:i:s"));
$em->persist($utilisateurI);
$em->flush();
$data = ['success' => $success = true, 'data' => 'Votre profil a bien été modifié'];
return new JsonResponse($data);
} else {
$data = ['success' => $success = false, 'data' => $error];
}
return new JsonResponse($data);
}
#[Route(path: '/api/profil', name: 'ctsweb_front_profil')]
#[Route('/api/profil/{profil}', name: 'cts_get_profil_by_profil_id', methods: ['GET'])]
public function Profil(Utilisateur $profil = null)
{
$repositoryUI = $this->doctrine->getManager()->getRepository(UtilisateurInformation::class);
$uid = $profil ? $profil->getIdUtilisateur() : $this->getUser()->getIdUtilisateur();
$session = new Session();
$utilisateurData = $repositoryUI->findDataForPageProfil($uid);
$affectation = $utilisateurData['idAffectation'];
$repositoryRA = $this->doctrine->getManager()->getRepository(RefAffectation::class);
$RefAffectationController = $repositoryRA->findOneBy(["idAffectation" => $affectation]);
$congeScolaire = $RefAffectationController->getCalendrierScolaire();
$dateBascule = $RefAffectationController->getDateBascule();
$today = new \DateTime();
$today = $today;
if ($today > $dateBascule) {
$utilisateurData['calendrier_scolaire'] = $congeScolaire;
} else {
$utilisateurData['calendrier_scolaire'] = !$congeScolaire;
}
$tabDroitRef = [
RefRole::ROLE_DS_ADMIN, RefRole::ROLE_DS_INVITE, RefRole::ROLE_LECTEUR,
RefRole::ROLE_DR, RefRole::ROLE_DS_SIGNATAIRE, RefRole::ROLE_DR_SIGNATAIRE
];
if ($utilisateurData['path_scan'] != null) {
$utilisateurData['path_scan'] = "api/downloadScan/$utilisateurData[path_scan]";
}
if (in_array($utilisateurData['id_profil'], $tabDroitRef)) {
$utilisateurData['droitRefFederation'] = true;
}
$result = ['success' => true, 'data' => $utilisateurData];
$session->set('libFede', $utilisateurData['rSerLibl']);
$result['data']['idUtilisateur'] = $uid;
return new JsonResponse($result);
}
#[Route(path: '/api/informations_generales', name: 'ctsweb_informations_generales')]
function getInformationGenerales()
{
try {
$listData = [];
$role = $this->getUser()->getUtilisateur()->getIdRole();
$today = new \DateTime();
if ($role != RefRole::ROLE_CTS) {
$em = $this->doctrine->getManager();
$listCollaborateurs = $em->getRepository(UtilisateurInformation::class)->findMyCollab($this->getUser());
foreach ($listCollaborateurs as $listCollaborateur) {
$affectionEntity = $em
->getRepository(RefAffectation::class)
->findOneBy(["idAffectation" => $listCollaborateur['idAffectation']]);
$congeScolaire = ($today >= $affectionEntity->getDateBascule()) ? $affectionEntity->getCalendrierScolaire() : !$affectionEntity->getCalendrierScolaire();
$listUser[] = $listCollaborateur['idUtilisateur'];
$telBureau = (string) $listCollaborateur['telephoneBureau'];
$telPortable = (string) $listCollaborateur['telephonePortable'];
$listData[] = ["civilite" => $listCollaborateur['civilite'], "login" => $listCollaborateur['login'], "dateNaissance" => $listCollaborateur['dateDeNaissance'], "telBureau" => $telBureau, "telPortable" => $telPortable, "nom" => $listCollaborateur['nom'], "prenom" => $listCollaborateur['prenom'], "grade" => $listCollaborateur['grade'], "indiceMajore" => $listCollaborateur['indiceMajore'], "dateFinDroits" => $listCollaborateur['dateFinDroits'], "adresse" => $listCollaborateur['adresse'], "uiFonctionCompl" => $listCollaborateur['uiFonctionCompl'], "uiCadreGeneral" => $listCollaborateur['uiCadreGeneral'], "pCivMatcle" => $listCollaborateur['pCivMatcle'], "libellePoste" => $listCollaborateur['libellePoste'], "libelleLong" => $listCollaborateur['libelleLong'], "rAdmDiside" => $listCollaborateur['rAdmDiside'], "rSerLibc" => $listCollaborateur['rSerLibc'], "rSerLibl" => $listCollaborateur['libelleCourtDiscipline'], "rSerIdent" => $listCollaborateur['affectation'], "idUtilisateur" => $listCollaborateur['idUtilisateur'], "courriel" => $listCollaborateur['courriel'], "droitLmUtilisateur" => $listCollaborateur['droit'], "idFederation" => $listCollaborateur['idFederation'], "idAffectation" => $listCollaborateur['idAffectation'], "idRole" => $listCollaborateur['IdRole'], "libelleFop" => $listCollaborateur['libelleFop'], "calendrierScolaire" => $congeScolaire];
}
}
$data = ['success' => true, 'data' => $listData];
} catch (\Exception) {
$data = ['success' => false, 'data' => "Erreur de chargement"];
}
return new JsonResponse($data);
}
// #[Route(path: '/api/informations_generales', name: 'ctsweb_informations_generales')]
function InformationsGenerales(Request $request)
{
$repositoryU = $this->doctrine->getManager()->getRepository(Utilisateur::class);
$repositoryUI = $this->doctrine->getManager()->getRepository(UtilisateurInformation::class);
$perimetre = $repositoryU->findPerimetreById($this->getUser()->getIdUtilisateur());
$droits = $repositoryU->findDroitById($this->getUser()->getIdUtilisateur());
$role = $this->getUser()->getUtilisateur()->getIdRole();
$CTSList = $repositoryUI->getCtsInformationGeneralList(
['affectation' => $this->getUser()->getIdAffectation() != null ? $this->getUser()->getIdAffectation()->getIdAffectation() : null, 'federation' => $this->getUser()->getIdFederation() != null ? $this->getUser()->getIdFederation()->getIdFederation() : null, 'droits' => $droits, 'perimetre' => $perimetre, 'role' => $role, 'AC' => $request->get('AC')]
);
$data = ['success' => true, 'data' => $CTSList];
return new JsonResponse($data);
}
#[Route(path: '/api/menu', name: 'ctsweb_menu')]
public function Menu()
{
$role = $this->getUser()->getUtilisateur()->getIdRole();
$menu = [];
$linkGCts = "/v2/gerer-cts";
$menu[0] = ["libelle" => "Gérer mon activité", "className" => "visible-md-inline-block visible-lg-inline-block", "href" => "/gerer-mon-activites", "actif" => $role == RefRole::ROLE_CTS || $role == RefRole::ROLE_FEDE, "mobile" => true];
$menu[1] = ["libelle" => "Gérer les CTS", "className" => "visible-md-inline-block visible-lg-inline-block", "href" => $linkGCts, "actif" => $role != RefRole::ROLE_CTS, "sousMenuOdm" => $role == RefRole::ROLE_CTS ? null : $this->getSousMenuCTSODM($role), "sousMenuConges" => $role == RefRole::ROLE_CTS ? null : $this->getSousMenuCTSConges($role), "sousMenuLm" => $role == RefRole::ROLE_CTS ? null : $this->getSousMenuCTSLM($role), "mobile" => true];
$menu[2] = ["libelle" => "Administration", "className" => "visible-lg-inline-block", "href" => "/administration", "actif" => $role != RefRole::ROLE_CTS && $role != RefRole::ROLE_LECTEUR, "mobile" => false];
$menu[3] = $this->getParameter('version');
return new JsonResponse($menu);
}
public function getSousMenuCTSODM($role)
{
$sousMenuCTSODM = [];
$sousMenuCTSODM[0] = ["libelle" => "Infos générales", "lienActif" => 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
$sousMenuCTSODM[1] = ["libelle" => "OM EN ATTENTE", "lienActif" => ($role != RefRole::ROLE_DS_INVITE || $role != RefRole::ROLE_DR ||
$role != RefRole::ROLE_DS_SIGNATAIRE || $role != RefRole::ROLE_DR_SIGNATAIRE || $role != RefRole::ROLE_LECTEUR) ? 1 : 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
// onglet désactivé
$sousMenuCTSODM[2] = [
"libelle" => "Signature OM",
"lienActif" => 0,
"actif" => 0,
];
$sousMenuCTSODM[3] = ["libelle" => "Déplacements en cours", "lienActif" => 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
return $sousMenuCTSODM;
}
public function getSousMenuCTSConges($role)
{
$sousMenuCTSConges = [];
$sousMenuCTSConges[0] = ["libelle" => "Infos générales", "lienActif" => 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
$sousMenuCTSConges[1] = ["libelle" => "CONGES EN ATTENTE", "lienActif" => ($role != RefRole::ROLE_DS_INVITE || $role != RefRole::ROLE_DR ||
$role != RefRole::ROLE_DS_SIGNATAIRE || $role != RefRole::ROLE_DR_SIGNATAIRE || $role != RefRole::ROLE_LECTEUR) ? 1 : 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
$sousMenuCTSConges[2] = ["libelle" => "CONGES EN COURS", "lienActif" => 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
return $sousMenuCTSConges;
}
public function getSousMenuCTSLM($role)
{
$sousMenuCTSLM = [];
$sousMenuCTSLM[0] = ["libelle" => "OUTILS DES LM", "lienActif" => 0, "actif" => ($role != RefRole::ROLE_LECTEUR)];
$sousMenuCTSLM[1] = ["libelle" => "Projet de LM", "lienActif" => 0, "actif" => 1];
// onglet désactivé
$sousMenuCTSLM[2] = [
"libelle" => "Signature LM",
"lienActif" => 0,
"actif" => 0,
];
$sousMenuCTSLM[3] = ["libelle" => "Lettres de missions", "lienActif" => 0, "actif" => 1];
return $sousMenuCTSLM;
}
#[Route(path: '/api/modifier_password', name: 'ctsweb_modifier_password')]
public function ProfilPassword(Request $request)
{
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
$request->request->replace(is_array($data) ? $data : []);
$passwords = $request->request->all();
$requestForm = [];
$uid = $this->getUser()->getIdUtilisateur();
$repository = $this->doctrine->getManager()->getRepository(UtilisateurInformation::class);
if ($passwords['password'] === $passwords['passwordrepeat']) {
if (preg_match('/^(?=(.*[a-z]){1,})(?=(.*[A-Z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{12,}$/', (string) $passwords['password'])) {
$requestForm['password']['first'] = $passwords['password'];
$requestForm['email'] = $this->getUser()->getUtilisateur()->getCourriel();
$insertion = $repository->changePassword($requestForm, $uid);
if ($insertion['error']) {
$data = ['success' => false, 'data' => $insertion['retour']];
} else {
$data = ['success' => true, 'data' => $insertion['retour']];
}
} else {
$data = ['success' => false, 'data' => "Votre mot de passe doit avoir une longueur de 12 caractères minimum, contenant au moins un chiffre, une lettre minuscule, une lettre majuscule et un caractère spécial"];
}
} else {
$data = ['success' => false, 'data' => "Vous devez renseigner le même mot de passe sur les 2 champs"];
}
return new JsonResponse($data);
}
#[Route(path: '/api/get_user_info', name: 'ctsweb_user_info')]
public function GetUserInfos()
{
$userInfo = ["nom" => $this->getUser()->getNom(), "prenom" => $this->getUser()->getPrenom()];
$data = ['success' => true, 'data' => $userInfo];
return new JsonResponse($data);
}
#[Route(path: '/api/pastilles/{page}', name: 'ctsweb_get_pastilles')]
public function getPastilles($page)
{
$em = $this->doctrine->getManager();
$repositoryO = $em->getRepository(Odm::class);
$repositoryLD = $em->getRepository(ListeDiffusion::class);
$repositoryLDS = $em->getRepository(ListeDiffusionSup::class);
$repositoryPLM = $em->getRepository(ProjetLettreMission::class);
$repositoryFS = $em->getRepository(FormationSession::class);
$repositoryDOC = $em->getRepository(DocumentService::class);
$user = $this->getUser();
$userId = $user->getIdUtilisateur();
$userRoleId = $user->getUtilisateur()->getIdRole();
$nbOdmCTS = $nbActuCTS = $nbLmCTS = $nbcongCTS = $nbreCTS = $nbFormationSessionUser = $nbservicesCTS = 0;
$nbOdmGA = $nbActuGA = $nbLmGa = $nbcongGa = $nbFormationSessionGA = $nbservicesGA = $nbreGa = 0;
if ($page == 'ga') {
$nbOdmGA = $repositoryO->countOdmPastille($userId);
$nbFormationSessionGA = $repositoryFS->countformationPastille($userId);
$nbActuGA = $repositoryLD->countArticleNotRead($userId);
$nbservicesGA = $repositoryDOC->getdocumentprofil($user->getUtilisateur(), $user);
$nbcongGa = count(
$this->doctrine->getManager()
->getRepository(Conge::class)
->findBy(
[
'workflow' => [Workflow::CO_WAITING],
'utilisateur' => $this->getUser()->getUtilisateur(),
],
['id' => 'desc']
)
);
$nbreGa = count(
$this->doctrine->getManager()
->getRepository(DemandeReport::class)
->findBy(
[
'workflow' => [Workflow::RE_WAITING],
'utilisateur' => $this->getUser()->getUtilisateur(),
],
['id' => 'desc']
)
);
//Si rôle Fédération et poste DTN
if ($userRoleId == RefRole::ROLE_FEDE && $user->getIdPoste()->getIdPoste() == RefPoste::POSTE_DTN) {
$nbLmGa = $repositoryPLM->countLmEnCoursExamenByUserDtnGA($userId);
$nbservicesGA = $repositoryDOC->getdocumentprofilFdDtn($user->getUtilisateur(), $user);
$nbOdmGA = $repositoryO->countOdmPastilleCts($userId);
} else {
$nbLmGa = $this->countLmByProfil();
// $nbLmGa = $repositoryPLM->countLmEnCoursExamenByUser($userId);
}
if ($userRoleId == RefRole::ROLE_CTS) {
$nbLmGa = $this->countLmByProfil();
$nbOdmGA = $repositoryO->countOdmPastilleCts($userId);
}
}
//Rôle different de CTS
if ($page == 'gcts' && $userRoleId != RefRole::ROLE_CTS) {
$nbOdmCTS = $this->countOdmPastillesByRoleUser();
$nbActuCTS = $repositoryLDS->countListeDiffusionValide($userId);
$nbLmCTS = $this->countLmByProfil();
$nbservicesCTS = $repositoryDOC->getdocumentprofil($user->getUtilisateur(), $user);
$nbcongCTS = $this->countconges('waiting');
$nbreCTS = $this->countreport('waiting');
$nbFormationSessionUser = $this->countformationByProfil();
}
if ($page == 'gcts' && $userRoleId == RefRole::ROLE_FEDE && $user->getIdPoste()->getIdPoste() == RefPoste::POSTE_DTN) {
$nbLmCTS = $repositoryPLM->countLmEnCoursExamenByUserDtn($userId);
}
$pastilles = [
"GA" => ["ODM" => $nbOdmGA, "ACTU" => $nbActuGA, "LM" => $nbLmGa, "conges" => $nbcongGa + $nbreGa, "formations" => $nbFormationSessionGA, "services" => $nbservicesGA],
"CTS" => ["ODM" => $nbOdmCTS, "ACTU" => $nbActuCTS, "LM" => $nbLmCTS, "conges" => $nbcongCTS + $nbreCTS, "formations" => $nbFormationSessionUser, "services" => $nbservicesCTS]
];
$data = ['success' => true, 'data' => $pastilles];
$response = new JsonResponse($data);
return $response;
}
private function countOdmPastillesByRoleUser()
{
$user = $this->getUser();
$userRole = $user->getUtilisateur()->getIdRole();
$em = $this->doctrine->getManager();
$nbOfCollabs = 0;
$idAffectation = $user->getIdAffectation() == null ? 1 : $user->getIdAffectation()->getIdAffectation();
$idFederation = $user->getIdFederation() == null ? null : $user->getIdFederation()->getIdFederation();
$nbOfCollabs = match ($userRole) {
RefRole::ROLE_FEDE, RefRole::ROLE_FEDE_INVITE => $em->getRepository(Odm::class)->countCtsForFede($idFederation),
RefRole::ROLE_DR => $em->getRepository(Odm::class)->countCtsForDrOrDrs($idAffectation, false),
RefRole::ROLE_DS_ADMIN, RefRole::ROLE_DS_INVITE, RefRole::ROLE_LECTEUR => $em->getRepository(Odm::class)->countCtsForDs($idAffectation),
RefRole::ROLE_DR_SIGNATAIRE => $em->getRepository(Odm::class)->countCtsForDrOrDrs($idAffectation, true),
RefRole::ROLE_DS_SIGNATAIRE => $em->getRepository(Odm::class)->countCtsForDss($idAffectation),
default => $nbOfCollabs,
};
return $nbOfCollabs;
}
private function countLmByProfil()
{
$userRole = $this->getUser()->getUtilisateur()->getIdRole();
$em = $this->doctrine->getManager();
$nbOfLm = 0;
$idAffectation = $this->getUser()->getIdAffectation() == null ? 1 : $this->getUser()->getIdAffectation()->getIdAffectation();
switch ($userRole) {
case RefRole::ROLE_FEDE:
case RefRole::ROLE_FEDE_INVITE:
$federation = $this->getUser()->getIdFederation()->getIdFederation();
$nbOfLm = $em->getRepository(ProjetLettreMission::class)->countLmForDtn($federation);
break;
case RefRole::ROLE_DR:
$nbOfLm = $em->getRepository(ProjetLettreMission::class)->countLmForDr($idAffectation);
break;
case RefRole::ROLE_DS_ADMIN:
case RefRole::ROLE_DS_INVITE:
case RefRole::ROLE_LECTEUR:
$nbOfLm = $em->getRepository(ProjetLettreMission::class)->countLmForDsAndDsInv();
break;
case RefRole::ROLE_DR_SIGNATAIRE:
$nbOfLm = $em->getRepository(ProjetLettreMission::class)->countLmForDrSignataire($idAffectation);
break;
case RefRole::ROLE_DS_SIGNATAIRE:
$nbOfLm = $em->getRepository(ProjetLettreMission::class)->countLmForDsSignataire($idAffectation);
break;
case RefRole::ROLE_CTS:
$repositoryPLM = $em->getRepository(ProjetLettreMission::class);
$result = $repositoryPLM->findProjetLettreMission($this->getUser()->getIdUtilisateur());
if (!is_null($result))
$nbOfLm = 1;
else
$nbOfLm = 0;
break;
}
return $nbOfLm;
}
public function countreport(string $state)
{
$repositoryUI = $this->doctrine->getManager()->getRepository(UtilisateurInformation::class);
$uid = $this->getUser()->getIdUtilisateur();
$role = $this->getUser()->getUtilisateur()->getIdRole();
if (!in_array($role, Utilisateur::MANAGE)) {
return new JsonResponse([], JsonResponse::HTTP_FORBIDDEN);
}
$states = ['current', 'waiting'];
if (!in_array($state, $states)) {
return new JsonResponse([], JsonResponse::HTTP_BAD_REQUEST);
}
$entityManager = $this->doctrine->getManager();
$affectation = $this->getUser()->getIdAffectation();
$federation = $this->getUser()->getIdFederation();
if ('waiting' == $state) {
$workflow = Workflow::RE_WAITING;
//federation on
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
return 0;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role || RefRole::ROLE_GCR=== $role) {
$federation = null;
} else {
$federation = null;
$affectation = null;
return 0;
}
} else {
$workflow = Workflow::RE_SIGN;
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role || RefRole::ROLE_GCR=== $role) {
$federation = null;
} else {
$affectation = null;
$federation = null;
}
}
$avisDtn = "avisDtn";
$conges = $entityManager
->getRepository(DemandeReport::class)
->findByWorkflowAndUserType($workflow, $federation, $affectation, $avisDtn);
return count($conges);
}
public function countconges(string $state)
{
$repositoryUI = $this->doctrine->getManager()->getRepository(UtilisateurInformation::class);
$uid = $this->getUser()->getIdUtilisateur();
$role = $this->getUser()->getUtilisateur()->getIdRole();
if (!in_array($role, Utilisateur::MANAGE)) {
return new JsonResponse([], JsonResponse::HTTP_FORBIDDEN);
}
$states = ['current', 'waiting'];
if (!in_array($state, $states)) {
return new JsonResponse([], JsonResponse::HTTP_BAD_REQUEST);
}
$entityManager = $this->doctrine->getManager();
$affectation = $this->getUser()->getIdAffectation();
$federation = $this->getUser()->getIdFederation();
if ('waiting' == $state) {
$workflow = Workflow::CO_WAITING;
//federation on
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role || RefRole::ROLE_GCR=== $role) {
$federation = null;
} else {
$federation = null;
$affectation = null;
}
} else {
$workflow = Workflow::CO_ACCEPTED;
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role || RefRole::ROLE_GCR=== $role) {
$federation = null;
} else {
$affectation = null;
$federation = null;
}
}
$avisDtn = "avisDtn";
$conges = $entityManager
->getRepository(Conge::class)
->findByWorkflowAndUserType($workflow, $federation, $affectation, $avisDtn);
return $this->countcongeAttente($conges);
}
private function countFormationByProfil()
{
$user = $this->getUser();
$userRole = $user->getUtilisateur()->getIdRole();
$em = $this->doctrine->getManager();
$nbOfFo = 0;
$idAffectation = $user->getIdAffectation() == null ? 1 : $user->getIdAffectation()->getIdAffectation();
$idFederation = $user->getIdFederation() == null ? null : $user->getIdFederation()->getIdFederation();
$nbOfFo = match ($userRole) {
RefRole::ROLE_FEDE, RefRole::ROLE_FEDE_INVITE => $em->getRepository(FormationSession::class)->countFoForDtn($idFederation),
RefRole::ROLE_DR => $em->getRepository(FormationSession::class)->countFoForDr($idAffectation),
RefRole::ROLE_DS_ADMIN, RefRole::ROLE_DS_INVITE, RefRole::ROLE_LECTEUR => $em->getRepository(FormationSession::class)->countFoForDsAndDsInv($idAffectation),
RefRole::ROLE_DR_SIGNATAIRE => $em->getRepository(FormationSession::class)->countFoForDrSignataire($idAffectation),
RefRole::ROLE_DS_SIGNATAIRE => $em->getRepository(FormationSession::class)->countFoForDsSignataire($idAffectation),
default => $nbOfFo,
};
return $nbOfFo;
}
public function countformation(string $state)
{
$role = $this->getUser()->getUtilisateur()->getIdRole();
if (!in_array($role, Utilisateur::MANAGE)) {
return new JsonResponse([], JsonResponse::HTTP_FORBIDDEN);
}
$states = ['current', 'waiting'];
if (!in_array($state, $states)) {
return new JsonResponse([], JsonResponse::HTTP_BAD_REQUEST);
}
$entityManager = $this->doctrine->getManager();
$affectation = $this->getUser()->getIdAffectation();
$federation = $this->getUser()->getIdFederation();
if ('waiting' == $state) {
$workflow = Workflow::FO_EN_ATTENTE_DE_VALIDATION;
//federation on
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role) {
$federation = null;
} else {
$federation = null;
$affectation = null;
}
} else {
$workflow = Workflow::FO_EN_ATTENTE_SIGNATURE;
if (RefRole::ROLE_FEDE === $role || RefRole::ROLE_FEDE_INVITE === $role) {
$affectation = null;
} else if (RefRole::ROLE_DR === $role || RefRole::ROLE_DR_SIGNATAIRE === $role) {
$federation = null;
} else {
$affectation = null;
$federation = null;
}
}
$formation = $entityManager
->getRepository(FormationSession::class)
->findByWorkflowAndUserType($workflow, $federation, $affectation);
return is_countable($formation) ? count($formation) : 0;
}
private function countcongeAttente($conges)
{
$numbre = 0;
$libelle = "en attente pour validation";
foreach ($conges as $conge) {
if (strtolower($conge['libelleAction']) == $libelle) {
$numbre++;
}
}
return $numbre;
}
private function conditionOfOdmUe($list)
{
$numbre = 0;
foreach ($list as $odm) {
if ($odm['idPoste'] == 4 || $odm['idPoste'] == 3) {
$numbre++;
} else {
if ($odm['euro'] == false) {
$numbre++;
}
}
}
return $numbre;
}
private function findFederation($rAdmDiside)
{
$em = $this->doctrine->getManager();
$resultatFede = $em->getRepository(RFederation::class)->findOneBy(['rAdmDiside' => $rAdmDiside]);
return $resultatFede;
}
#[Route(path: '/api/get_navigation_type_agenda', name: 'cts_get_favoris_navigation')]
public function getNavigationType()
{
$idUser = $this->getUser()->getIdUtilisateur();
$em = $this->doctrine->getManager();
$utilisateurInformation = $em->getRepository(UtilisateurInformation::class)->findOneBy(['idUtilisateur' => $idUser]);
$navigation = "";
if ($utilisateurInformation instanceof UtilisateurInformation) {
$navigation = $utilisateurInformation->getNavigation();
}
$data = ['success' => true, 'data' => $navigation];
return new JsonResponse($data);
}
#[Route(path: '/api/post_navigation_type_agenda', name: 'cts_post_favoris_navigation')]
public function setNavigationType(Request $request)
{
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
$request->request->replace(is_array($data) ? $data : []);
$params = $request->request->all();
$idUser = $this->getUser()->getIdUtilisateur();
$em = $this->doctrine->getManager();
$utilisateurInformation = $em->getRepository(UtilisateurInformation::class)->findOneBy(['idUtilisateur' => $idUser]);
$succes = false;
if ($utilisateurInformation instanceof UtilisateurInformation) {
$utilisateurInformation->setNavigation($params['typeAgenda']);
$em->persist($utilisateurInformation);
$em->flush();
$succes = true;
}
return new JsonResponse(['success' => $succes]);
}
#[Route(path: '/api/masterController.js', name: 'cts_master_controller')]
public function myInitialMasterController()
{
try {
$path = $this->getParameter('web_dir');
$content = file_get_contents("$path/ui/js/controller/masterController.js");
// $content = sprintf($content, $this->Menu()->getContent(), $this->Profil()->getContent(), $this->forward('App:Agenda:GetColorAgenda')->getContent(), $this->forward('App:CreationEvenement:GetConsulterAction')->getContent());
$content = sprintf(
$content,
$this->Menu()->getContent(),
$this->Profil()->getContent(),
$this->forward('App\Controller\AgendaController::GetColorAgenda')->getContent(),
$this->forward('App\Controller\CreationEvenementController::GetConsulterAction')->getContent()
);
$response = new Response(
$content,
Response::HTTP_OK,
['Content-Type' => 'application/javascript', 'Content-Length' => strlen($content), 'Content-Disposition' => 'attachment;filename=masterController.js', 'Accept-Ranges' => 'bytes']
);
} catch (\Exception $e) {
$response = new Response(
$e->getMessage(),
Response::HTTP_INTERNAL_SERVER_ERROR
);
}
return $response;
}
}