<?php
namespace App\Controller\Etudiant;
use App\Entity\EnseignantSemestre;
use App\Entity\Rapport;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Route('/etudiant')]
class EtudiantController extends AbstractController
{
private $client;
private $em;
public function __construct(HttpClientInterface $client, ManagerRegistry $em)
{
$this->client = $client;
$this->em = $em->getManager();
}
#[Route('/', name: 'etudiant_index')]
public function index(Request $request): Response
{
$table = null;
// dd('test');
if(in_array('ROLE_ENSEIGNANT', $this->getUser()->getRoles())) {
$sessions = $this->em->getRepository(EnseignantSemestre::class)->getEnseignantSemestresByClosedTime($this->getUser());
// dd($sessions);
return $this->render('etudiant/intro.html.twig', [
'sessions' => $sessions
]);
}
// $response = $this->client->request('GET', $this->getParameter("api")."/getetablissement");
// $etablissements = $response->toArray();
return $this->redirectToRoute("rapport_index");
// return $this->render('etudiant/index.html.twig', [
// 'etablissements' => $etablissements,
// 'table' => $table
// ]);
}
#[Route('/list/{session}', name: 'etudiant_list')]
public function rapports(EnseignantSemestre $session, Request $request): Response
{
$table = null;
// echo ('En cours de maintenance');
// dd($session);
$table = $this->list($request, $session->getSemestre(),$session->getNiveau());
return $this->render('etudiant/index.html.twig', [
'table' => $table
]);
}
public function list($request, $id,$niveau)
{
// dd("test");
$response = $this->client->request('GET', $this->getParameter("api")."/getlistofstagebysemestrebyniveau/$id/$niveau");
$session = $request->getSession();
$data = $response->toArray();
// echo ('En Cours de maintenance!');
// dd($data);
$inscriptions = $data['inscriptions'];
// dd($inscriptions);
$cycles = $data['cycles'];
$etab = $inscriptions[0]['etab'];
$form = $inscriptions[0]['frm'];
// echo 'En Cours De Maintenance!.. merci de patienté.';
//dd($cycles);
$stageSimulation = $stageClinique = $stageSDentaire = $stagePharmacy = $stagePharmacyHopital = $stagePharmacyStaff = $stageFmaGlobal = $stageFpaGlobal = $stageFdaGlobal = null;
$data = [];
foreach ($inscriptions as $key => $inscription) {
// if($inscription['id'] == "12105" or $inscription['id'] == "12156") {
$arrayOfStage = [];
foreach ($cycles as $cycle) {
$checkifexits = $this->em->getRepository(Rapport::class)->findOneBy(['inscription'=>$inscription["id"], 'stage'=> $cycle['stages']]);
if(!$checkifexits){
array_push($arrayOfStage, [
'clinique' => NULL,
'simulation' => NULL,
'pharmacy' => NULL,
'dentaire' => NULL,
'staff' => NULL,
'hopital' => NULL,
'fmaglobal' => NULL,
'fdaglobal' => NULL,
'fpaglobal' => NULL,
]);
continue;
}
//dd($checkifexits);
// $stageClinique = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "clinique");
// $stageSimulation = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "simulation");
// $stagePharmacy = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "pharmacy");
// $stageSDentaire = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "dentaire");
// $stagePharmacyStaff = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "staff");
// $stagePharmacyHopital = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "hopital");
// $stageFdaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
// $stageFpaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
// $stageFmaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
switch ($etab) {
case 'FMDA':
if (str_contains($form, 'Résidanat')) {
$stageFdaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
}else{
$stageSDentaire = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "dentaire");
$stageSimulation = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "simulation");
$stageClinique = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "clinique");
}
break;
case 'FPA':
if (str_contains($form, 'Résidanat')) {
$stageFpaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
}else{
$stagePharmacyHopital = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "hopital");
$stagePharmacy = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "pharmacy");
$stagePharmacyStaff = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "staff");
$stageSimulation = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "simulation");
}
break;
default:
if (str_contains($form, 'Résidanat')) {
$stageFmaGlobal = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "global");
}else{
$stageSimulation = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "simulation");
$stageClinique = $this->em->getRepository(Rapport::class)->findStage($inscription["id"], $cycle['stages'], "clinique");
}
break;
}
array_push($arrayOfStage, [
'clinique' => $stageClinique,
'simulation' => $stageSimulation,
'pharmacy' => $stagePharmacy,
'dentaire' => $stageSDentaire,
'staff' => $stagePharmacyStaff,
'hopital' => $stagePharmacyHopital,
'fmaglobal' => $stageFmaGlobal,
'fdaglobal' => $stageFdaGlobal,
'fpaglobal' => $stageFpaGlobal,
]);
}
array_push($data, [
'inscription' => $inscription,
'stages' => $arrayOfStage
]);
// }
}
// dd($cycles);
$html = $this->render("rapport/page/table.html.twig", [
'datas' => $data,
'cycles' => $cycles
])->getContent();
$session->set("inscriptions", $inscriptions);
return $html;
}
}