first commit

This commit is contained in:
maher
2026-05-16 17:37:29 +02:00
commit 7a183b96cf
6162 changed files with 744834 additions and 0 deletions
View File
+119
View File
@@ -0,0 +1,119 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
use App\Security\LoginAuthenticator;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\User;
use App\Form\UserRegistrationType;
use Symfony\Contracts\Translation\TranslatorInterface;
#[Route('/authentication')]
final class AuthenticationController extends AbstractController
{
#[Route('/sign-in', name: 'app_sign_in')]
public function sign_in(TranslatorInterface $translator, AuthenticationUtils $authenticationUtils): Response
{
//login
if ($this->getUser()) {
return $this->redirectToRoute('app_home');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('authentication/sign-in.html.twig', ['last_username' => $lastUsername, 'error' => $error, 'titlePage' => 'Connexion']);
}
#[Route('/sign-up', name: 'app_sign_up')]
public function sign_up(Request $request,
UserPasswordHasherInterface $userPasswordHasher,
UserAuthenticatorInterface $userAuthenticator,
LoginAuthenticator $authenticator,
EntityManagerInterface $em): Response
{
$user = new User();
$form = $this->createForm(UserRegistrationType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$user->setPassword($userPasswordHasher->hashPassword($user, $form->get('password')->getData()));
$user->setTranslator($request->getSession()->get('_locale'));
$em->persist($user);
$em->flush();
return $userAuthenticator->authenticateUser($user, $authenticator, $request);
}
return $this->render('authentication/sign-up.html.twig', [
'form' => $form->createView(),
'errors' => $form->getErrors(),
'titlePage' => 'Inscription',
]);
}
#[Route('/recover-pw', name: 'app_recover_pw')]
public function recover_pw(): Response
{
return $this->render('authentication/recoverpw.html.twig', []);
}
#[Route(path: '/sign_out', name: 'app_sign_out')]
public function logout(Security $security): RedirectResponse
{
$response = $security->logout(false);
return $this->redirectToRoute('app_sign_in');
}
#[Route('/confirm-mail', name: 'app_confirm_mail')]
public function confirm_mail(): Response
{
return $this->render('authentication/confirm-mail.html.twig', []);
}
#[Route('/change-language', name: 'change_language')]
public function change_language(Request $request): RedirectResponse
{
$language = $request->query->get('lang');
// Stocker la langue dans la session
$request->getSession()->set('_locale', $language);
$request->setLocale($language);
// Rediriger vers la page précédente ou l'accueil
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
}
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\State;
use App\Entity\Investigation;
use App\Repository\StateRepository;
use App\Repository\BroadcastRepository;
use App\Repository\InvestigationRepository;
use App\Form\BroadcastType;
#[Route('/broadcast')]
final class BroadcastController extends AbstractController
{
/**
* @param EntityManagerInterface $em
* @param StateRepository $stateRepository
* @param BroadcastRepository $broadcastRepository
* @param InvestigationRepository $investigationRepository
* @return $this
*/
public function __construct(
private EntityManagerInterface $em,
private StateRepository $stateRepository,
private BroadcastRepository $broadcastRepository,
private InvestigationRepository $investigationRepository,
) {
$this->em = $em;
$this->stateRepository = $stateRepository;
$this->broadcastRepository = $broadcastRepository;
$this->investigationRepository = $investigationRepository;
}
#[Route('/index', name: 'app_broadcast_index')]
public function index(): Response
{
$investigations = $this->investigationRepository->findInvestigationAdminValidated($this->getUser());
$broadcasts = $this->broadcastRepository->findByUser($this->getUser());
return $this->render('broadcast/index.html.twig', [
'investigations' => $investigations,
'broadcasts' => $broadcasts,
]);
}
#[Route('/add/{id}', name: 'app_broadcast_add')]
public function add(Request $request, Investigation $investigation): Response
{
$form = $this->createForm(BroadcastType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$broadcast = $form->getData();
$broadcast->setInvestigation($investigation);
$broadcast->setCreateBy($this->getUser());
$broadcast->setCost(150);
$this->em->persist($broadcast);
$this->em->flush();
$investigation->setLastState(31);
$this->em->persist($investigation);
$this->em->flush();
$this->stateRepository->addState($investigation, 3, 1, $broadcast);
$this->addFlash('danger', " <strong>Well done!</strong> You successfully read this important alert message.");
return $this->redirectToRoute('app_broadcast_index');
}
return $this->render('broadcast/add.html.twig', [
'form' => $form->createView(),
'investigation' => $investigation,
]);
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
final class DemoController extends AbstractController
{
#[Route('/demo/index', name: 'app_demo_index')]
public function index(): Response
{
//https://demo.bootstrapdash.com/azia/src/template/dashboard-one.html
return $this->render('demo/index.html.twig', []);
}
#[Route('/demo/empty', name: 'app_demo_empty')]
public function empty(): Response
{
$this->addFlash('danger', " <strong>Well done!</strong> You successfully read this important alert message.");
//$this->addFlash('success', $this->translator->trans('conference.success_create_message', array(), 'Admin'));
return $this->render('demo/empty.html.twig', []);
}
#[Route('/demo/collapse', name: 'app_demo_collapse')]
public function collapse(): Response
{
return $this->render('demo/collapse.html.twig', []);
}
#[Route('/demo/chart', name: 'app_demo_chart')]
public function chart(): Response
{
return $this->render('demo/chart.html.twig', []);
}
#[Route('/demo/buttons', name: 'app_demo_buttons')]
public function buttons(): Response
{
return $this->render('demo/buttons.html.twig', []);
}
#[Route('/demo/dropdown', name: 'app_demo_dropdown')]
public function dropdown(): Response
{
return $this->render('demo/dropdown.html.twig', []);
}
#[Route('/demo/icons', name: 'app_demo_icons')]
public function icons(): Response
{
return $this->render('demo/icons.html.twig', []);
}
#[Route('/demo/elements', name: 'app_demo_elements')]
public function elements(): Response
{
return $this->render('demo/elements.html.twig', []);
}
#[Route('/demo/signin', name: 'app_demo_signin')]
public function signin(): Response
{
return $this->render('demo/signin.html.twig', []);
}
#[Route('/demo/signup', name: 'app_demo_signup')]
public function signup(): Response
{
return $this->render('demo/signup.html.twig', []);
}
#[Route('/demo/table', name: 'app_demo_table')]
public function table(): Response
{
return $this->render('demo/table.html.twig', []);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class HomeController extends AbstractController
{
#[Route('/', name: 'app_home')]
public function index(Request $request): Response
{
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
]);
}
}
+223
View File
@@ -0,0 +1,223 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Question;
use App\Entity\Investigation;
use App\Repository\StateRepository;
use App\Repository\InvestigationRepository;
use App\Form\InvestigationType;
#[Route('/investigation')]
final class InvestigationController extends AbstractController
{
/**
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
* @param StateRepository $stateRepository
* @param InvestigationRepository $investigationRepository
* @return $this
*/
public function __construct(
private EntityManagerInterface $em,
private TranslatorInterface $translator,
private StateRepository $stateRepository,
private InvestigationRepository $investigationRepository,
) {
$this->em = $em;
$this->translator = $translator;
$this->stateRepository = $stateRepository;
$this->investigationRepository = $investigationRepository;
}
#[Route('/index', name: 'app_investigation_index')]
public function index(): Response
{
$investigations = $this->investigationRepository->findBy(['create_by' => $this->getUser(), 'last_state' => [10, 11, 12, 20, 21, 22]], ["id" => 'DESC']);
$invesAdmins = $this->investigationRepository->findBy(['create_by' => $this->getUser(), 'last_state' => 21], ["id" => 'DESC']);
return $this->render('investigation/index.html.twig', [
'investigations' => $investigations,
'invesAdmins' => $invesAdmins,
]);
}
#[Route('/add', name: 'app_investigation_add')]
public function add(Request $request): Response
{
$investigation = new Investigation();
$form = $this->createForm(InvestigationType::class, $investigation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$investigation = $form->getData();
$investigation->setCreateBy($this->getUser());
;
foreach($investigation->getQuestions() as $question){
foreach ($question->getAttachments() as $attachment) {
if ($attachment->getFile()) {
// Optionnel : calculer les dimensions pour les images
$attachment->setDimensionsFromFile($attachment->getFile());
}
}
}
$this->em->persist($investigation);
$this->em->flush();
$this->addFlash('success', $this->translator->trans('alert_sucess_add', [], 'investigation'));
return $this->redirectToRoute('app_investigation_index');
}
return $this->render('investigation/add-index.html.twig', [
'form' => $form->createView()
]);
}
private function handleAttachments($form, Question $question): void
{
// Récupérer le champ attachments du formulaire
$attachmentsForm = $form->get('attachments');
// Parcourir tous les attachments du formulaire
foreach ($attachmentsForm as $attachmentForm) {
/** @var Attachment $attachment */
$attachment = $attachmentForm->getData();
// Récupérer le fichier uploadé
$file = $attachmentForm->get('file')->getData();
if ($file) {
// Définir le fichier sur l'entité Attachment
$attachment->setFile($file);
// Associer l'attachment à la question
if (!$attachment->getQuestion()) {
$attachment->setQuestion($question);
}
}
}
}
#[Route('/show/{id}', name: 'app_investigation_show')]
public function show(Investigation $investigation): Response
{
return $this->render('investigation/show.html.twig', [
'investigation' => $investigation
]);
}
#[Route('/edit/{id}', name: 'app_investigation_edit')]
public function edit(Request $request, Investigation $investigation): Response
{
$form = $this->createForm(InvestigationType::class, $investigation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$investigation = $form->getData();
$this->em->persist($investigation);
$this->em->flush();
$this->addFlash('success', $this->translator->trans('alert_sucess_add', [], 'investigation'));
}
return $this->render('investigation/add-index.html.twig', [
'form' => $form->createView(),
'investigation' => $investigation,
]);
}
#[Route('/duplicate/{id}', name: 'app_investigation_duplicate')]
public function duplicate(Investigation $investigation): Response
{
$cloneInvestigation = clone $investigation;
foreach ($investigation->duplicateQuestions() as $question) {
$cloneInvestigation->addQuestion($question);
}
$this->em->persist($cloneInvestigation);
$this->em->flush();
return $this->redirectToRoute('app_investigation_edit', [
'id' => $cloneInvestigation->getId()
]);
}
#[Route('/delete/{id}', name: 'app_investigation_delete')]
public function delete(Investigation $investigation): Response
{
$this->em->remove($investigation);
$this->em->flush();
return $this->redirectToRoute('app_investigation_index');
}
#[Route('/send/validation/{id}', name: 'app_investigation_send_validation')]
public function send_validation(Investigation $investigation): Response
{
$investigation->setLastState(21);
$this->em->persist($investigation);
$this->em->flush();
$this->stateRepository->addState($investigation, 2, 1);
$this->addFlash('success', $this->translator->trans('alert_sucess_send_validation', [], 'investigation'));
return $this->redirectToRoute('app_investigation_index');
}
#[Route('/ready/{id}', name: 'app_investigation_ready')]
public function ready(Investigation $investigation): Response
{
$investigation->setLastState(21);
$this->em->persist($investigation);
$this->em->flush();
$this->stateRepository->addState($investigation, 2, 1);
return $this->redirectToRoute('app_investigation_index');
}
#[Route('/active', name: 'app_investigation_admin_active')]
public function active(Request $request): Response
{
$investigations = $this->investigationRepository->findBy(['last_state' => 21], ["id" => 'DESC']);
$this->addFlash('success', $this->translator->trans('alert_sucess', array(), 'active'));
$id = $request->query->get('id');
if ($id) {
$investigation = $this->investigationRepository->find($id);
$investigation->setLastState(20);
$this->em->persist($investigation);
$this->em->flush();
$this->stateRepository->addState($investigation, 2, 0);
}
return $this->render('investigation/admin-active.html.twig', [
'investigations' => $investigations
]);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/profile')]
final class ProfileController extends AbstractController
{
#[Route('/edit', name: 'profile_edit')]
public function edit(): Response
{
return $this->render('edit/sign-in.html.twig', []);
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use App\Repository\BroadcastRepository;
#[Route('/rapport')]
final class RapportController extends AbstractController
{
/**
* @param BroadcastRepository $broadcastRepository
* @return $this
*/
public function __construct(
private BroadcastRepository $broadcastRepository,
) {
$this->broadcastRepository = $broadcastRepository;
}
#[Route('/index', name: 'app_rapport_index')]
public function index(Request $request): Response
{
$language = $request->getSession()->get('_locale');
$broadcasts = $this->broadcastRepository->findBroadcastByUser($this->getUser());
$listeInvestigations = [];
foreach($broadcasts as $broadcast)
{
$investigation = $broadcast->getInvestigation();
if($language == 'fr'){
$listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameFr()];
}elseif($language == 'en'){
$listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameEn()];
}elseif($language == 'ar'){
$listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameAr()];
}else{
$listeInvestigations[] = ['id'=>$investigation->getId(), 'name'=>$investigation->getNameFr()];
}
}
return $this->render('rapport/index.html.twig', ["listeInvestigations"=>$listeInvestigations]);
}
}