first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Repository\BroadcastRepository;
|
||||
|
||||
use App\Entity\State;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'investigation:broadcast',
|
||||
description: 'Add a short description for your command',
|
||||
)]
|
||||
class InvestigationBroadcastCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
* @param BroadcastRepository $broadcastRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private BroadcastRepository $broadcastRepository,
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->em = $em;
|
||||
$this->broadcastRepository = $broadcastRepository;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$broadcasts = $this->broadcastRepository->findBroadcast();
|
||||
|
||||
foreach ($broadcasts as $broadcast) {
|
||||
$state = new State();
|
||||
$state->setBroadcast($broadcast);
|
||||
$state->setInvestigation($broadcast->getInvestigation());
|
||||
$state->setProgress(2);
|
||||
$state->setStep(3);
|
||||
$this->em->persist($state);
|
||||
$this->em->flush();
|
||||
|
||||
|
||||
$broadcast->setLastState(32);
|
||||
$this->em->persist($broadcast);
|
||||
$this->em->flush();
|
||||
|
||||
$output->writeln('<info>'.$broadcast->getInvestigation()->getId().'</info> Investigation Broadcast');
|
||||
}
|
||||
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Executable
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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', []);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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', []);
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Vich\UploaderBundle\Mapping\Annotation as Vich;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[Vich\Uploadable]
|
||||
class Attachment
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[Vich\UploadableField(
|
||||
mapping: 'attachments',
|
||||
fileNameProperty: 'fileName',
|
||||
size: 'fileSize',
|
||||
mimeType: 'mimeType',
|
||||
originalName: 'originalName',
|
||||
dimensions: 'dimensions'
|
||||
)]
|
||||
private ?File $file = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $fileName = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $fileSize = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $mimeType = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $originalName = null;
|
||||
|
||||
#[ORM\Column(type: 'simple_array', nullable: true)]
|
||||
private ?array $dimensions = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Question::class, inversedBy: 'attachments')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Question $question = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setFile(?File $file = null): void
|
||||
{
|
||||
$this->file = $file;
|
||||
|
||||
if (null !== $file) {
|
||||
$this->updatedAt = new \DateTimeImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
public function getFile(): ?File
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
public function setFileName(?string $fileName): void
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
public function getFileName(): ?string
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
public function setFileSize(?int $fileSize): void
|
||||
{
|
||||
$this->fileSize = $fileSize;
|
||||
}
|
||||
|
||||
public function getFileSize(): ?int
|
||||
{
|
||||
return $this->fileSize;
|
||||
}
|
||||
|
||||
public function setMimeType(?string $mimeType): void
|
||||
{
|
||||
$this->mimeType = $mimeType;
|
||||
}
|
||||
|
||||
public function getMimeType(): ?string
|
||||
{
|
||||
return $this->mimeType;
|
||||
}
|
||||
|
||||
public function setOriginalName(?string $originalName): void
|
||||
{
|
||||
$this->originalName = $originalName;
|
||||
}
|
||||
|
||||
public function getOriginalName(): ?string
|
||||
{
|
||||
return $this->originalName;
|
||||
}
|
||||
|
||||
public function setDimensions(?array $dimensions): void
|
||||
{
|
||||
$this->dimensions = $dimensions;
|
||||
}
|
||||
|
||||
public function getDimensions(): ?array
|
||||
{
|
||||
return $this->dimensions;
|
||||
}
|
||||
|
||||
public function getQuestion(): ?Question
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
public function setQuestion(?Question $question): void
|
||||
{
|
||||
$this->question = $question;
|
||||
}
|
||||
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): void
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
}
|
||||
|
||||
// Méthode utilitaire pour afficher la taille en format lisible
|
||||
public function getReadableFileSize(): string
|
||||
{
|
||||
$bytes = $this->fileSize;
|
||||
$units = ['B', 'KB', 'MB', 'GB'];
|
||||
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
|
||||
$bytes /= (1 << (10 * $pow));
|
||||
|
||||
return round($bytes, 2) . ' ' . $units[$pow];
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->originalName ?? $this->fileName ?? '';
|
||||
}
|
||||
|
||||
// Si vous utilisez les dimensions (pour les images)
|
||||
public function setDimensionsFromFile(File $file): void
|
||||
{
|
||||
if (str_starts_with($file->getMimeType(), 'image/')) {
|
||||
try {
|
||||
$size = getimagesize($file->getPathname());
|
||||
if ($size) {
|
||||
$this->dimensions = [$size[0], $size[1]];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignorer l'erreur si ce n'est pas une image
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\BroadcastRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: BroadcastRepository::class)]
|
||||
#[ORM\Table(name: '`broadcast`')]
|
||||
class Broadcast
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?float $cost = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
private ?\DateTime $date_start = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
private ?\DateTime $date_end = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?\DateTime $date_create = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $notification_sms = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $notification_email = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'broadcasts')]
|
||||
private ?User $create_by = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'broadcasts')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Investigation $investigation = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, State>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: State::class, mappedBy: 'broadcast')]
|
||||
private Collection $states;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $last_state = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new \DateTime();
|
||||
$this->notification_sms = false;
|
||||
$this->notification_email = false;
|
||||
$this->last_state = 31;
|
||||
$this->states = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCost(): ?float
|
||||
{
|
||||
return $this->cost;
|
||||
}
|
||||
|
||||
public function setCost(float $cost): static
|
||||
{
|
||||
$this->cost = $cost;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateStart(): ?\DateTime
|
||||
{
|
||||
return $this->date_start;
|
||||
}
|
||||
|
||||
public function setDateStart(\DateTime $date_start): static
|
||||
{
|
||||
$this->date_start = $date_start;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateEnd(): ?\DateTime
|
||||
{
|
||||
return $this->date_end;
|
||||
}
|
||||
|
||||
public function setDateEnd(\DateTime $date_end): static
|
||||
{
|
||||
$this->date_end = $date_end;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCreate(): ?\DateTime
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setDateCreate(\DateTime $date_create): static
|
||||
{
|
||||
$this->date_create = $date_create;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isNotificationSms(): ?bool
|
||||
{
|
||||
return $this->notification_sms;
|
||||
}
|
||||
|
||||
public function setNotificationSms(bool $notification_sms): static
|
||||
{
|
||||
$this->notification_sms = $notification_sms;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isNotificationEmail(): ?bool
|
||||
{
|
||||
return $this->notification_email;
|
||||
}
|
||||
|
||||
public function setNotificationEmail(bool $notification_email): static
|
||||
{
|
||||
$this->notification_email = $notification_email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreateBy(): ?User
|
||||
{
|
||||
return $this->create_by;
|
||||
}
|
||||
|
||||
public function setCreateBy(?User $create_by): static
|
||||
{
|
||||
$this->create_by = $create_by;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvestigation(): ?Investigation
|
||||
{
|
||||
return $this->investigation;
|
||||
}
|
||||
|
||||
public function setInvestigation(?Investigation $investigation): static
|
||||
{
|
||||
$this->investigation = $investigation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, State>
|
||||
*/
|
||||
public function getStates(): Collection
|
||||
{
|
||||
return $this->states;
|
||||
}
|
||||
|
||||
public function addState(State $state): static
|
||||
{
|
||||
if (!$this->states->contains($state)) {
|
||||
$this->states->add($state);
|
||||
$state->setBroadcast($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeState(State $state): static
|
||||
{
|
||||
if ($this->states->removeElement($state)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($state->getBroadcast() === $this) {
|
||||
$state->setBroadcast(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastState(): ?int
|
||||
{
|
||||
return $this->last_state;
|
||||
}
|
||||
|
||||
public function setLastState(int $last_state): static
|
||||
{
|
||||
$this->last_state = $last_state;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\FilterRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FilterRepository::class)]
|
||||
class Filter
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $type = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $value = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'filters')]
|
||||
private ?Question $question = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getType(): ?int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(int $type): static
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue(): ?string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue(string $value): static
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuestion(): ?Question
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
public function setQuestion(?Question $question): static
|
||||
{
|
||||
$this->question = $question;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\InvestigationRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: InvestigationRepository::class)]
|
||||
class Investigation
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_en = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $source_en = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_fr = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $source_fr = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_ar = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $source_ar = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?\DateTime $date_create = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $last_state = null;
|
||||
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'investigations')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $create_by = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Question>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Question::class, mappedBy: 'investigation', orphanRemoval: true, cascade: ['persist', 'remove'])]
|
||||
private Collection $questions;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Broadcast>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Broadcast::class, mappedBy: 'investigation')]
|
||||
private Collection $broadcasts;
|
||||
|
||||
/**
|
||||
* @var Collection<int, State>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: State::class, mappedBy: 'investigation')]
|
||||
#[ORM\OrderBy(['date' => 'DESC'])]
|
||||
private Collection $states;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->questions = new ArrayCollection();
|
||||
$this->date_create = new \DateTime();
|
||||
$this->last_state = 11;
|
||||
$this->addQuestion(new Question());
|
||||
$this->broadcasts = new ArrayCollection();
|
||||
$this->states = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->name_en = $this->name_en ." duplicate";
|
||||
$this->name_fr = $this->name_fr ." duplicate";
|
||||
$this->name_ar = $this->name_ar ." duplicate";
|
||||
$this->date_create = new \DateTime();
|
||||
$this->last_state = 12;
|
||||
$this->broadcasts = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNameEn(): ?string
|
||||
{
|
||||
return $this->name_en;
|
||||
}
|
||||
|
||||
public function setNameEn(?string $name_en): static
|
||||
{
|
||||
$this->name_en = $name_en;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSourceEn(): ?string
|
||||
{
|
||||
return $this->source_en;
|
||||
}
|
||||
|
||||
public function setSourceEn(?string $source_en): static
|
||||
{
|
||||
$this->source_en = $source_en;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameFr(): ?string
|
||||
{
|
||||
return $this->name_fr;
|
||||
}
|
||||
|
||||
public function setNameFr(?string $name_fr): static
|
||||
{
|
||||
$this->name_fr = $name_fr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSourceFr(): ?string
|
||||
{
|
||||
return $this->source_fr;
|
||||
}
|
||||
|
||||
public function setSourceFr(?string $source_fr): static
|
||||
{
|
||||
$this->source_fr = $source_fr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameAr(): ?string
|
||||
{
|
||||
return $this->name_ar;
|
||||
}
|
||||
|
||||
public function setNameAr(?string $name_ar): static
|
||||
{
|
||||
$this->name_ar = $name_ar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSourceAr(): ?string
|
||||
{
|
||||
return $this->source_ar;
|
||||
}
|
||||
|
||||
public function setSourceAr(?string $source_ar): static
|
||||
{
|
||||
$this->source_ar = $source_ar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCreate(): ?\DateTime
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setDateCreate(\DateTime $date_create): static
|
||||
{
|
||||
$this->date_create = $date_create;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastState(): ?int
|
||||
{
|
||||
return $this->last_state;
|
||||
}
|
||||
|
||||
public function setLastState(int $last_state): static
|
||||
{
|
||||
$this->last_state = $last_state;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreateBy(): ?User
|
||||
{
|
||||
return $this->create_by;
|
||||
}
|
||||
|
||||
public function setCreateBy(?User $create_by): static
|
||||
{
|
||||
$this->create_by = $create_by;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Question>
|
||||
*/
|
||||
public function getQuestions(): Collection
|
||||
{
|
||||
return $this->questions;
|
||||
}
|
||||
|
||||
public function addQuestion(Question $question): static
|
||||
{
|
||||
if (!$this->questions->contains($question)) {
|
||||
$this->questions->add($question);
|
||||
$question->setInvestigation($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeQuestion(Question $question): static
|
||||
{
|
||||
if ($this->questions->removeElement($question)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($question->getInvestigation() === $this) {
|
||||
$question->setInvestigation(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNbrQuestions(): int
|
||||
{
|
||||
return count($this->questions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Broadcast>
|
||||
*/
|
||||
public function getBroadcasts(): Collection
|
||||
{
|
||||
return $this->broadcasts;
|
||||
}
|
||||
|
||||
public function addBroadcast(Broadcast $broadcast): static
|
||||
{
|
||||
if (!$this->broadcasts->contains($broadcast)) {
|
||||
$this->broadcasts->add($broadcast);
|
||||
$broadcast->setInvestigation($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeBroadcast(Broadcast $broadcast): static
|
||||
{
|
||||
if ($this->broadcasts->removeElement($broadcast)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($broadcast->getInvestigation() === $this) {
|
||||
$broadcast->setInvestigation(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function duplicateQuestions(): Collection
|
||||
{
|
||||
$dupQuestions = new ArrayCollection();
|
||||
foreach($this->questions as $question){
|
||||
$dupQuestions->add(clone $question);
|
||||
}
|
||||
return $dupQuestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, State>
|
||||
*/
|
||||
public function getStates(): Collection
|
||||
{
|
||||
return $this->states;
|
||||
}
|
||||
|
||||
public function addState(State $state): static
|
||||
{
|
||||
if (!$this->states->contains($state)) {
|
||||
$this->states->add($state);
|
||||
$state->setInvestigation($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeState(State $state): static
|
||||
{
|
||||
if ($this->states->removeElement($state)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($state->getInvestigation() === $this) {
|
||||
$state->setInvestigation(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getState(): ?State
|
||||
{
|
||||
return $this->states->first() ?: null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ModalityRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ModalityRepository::class)]
|
||||
class Modality
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_en = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_fr = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_ar = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'modalitys')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Question $question = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNameEn(): ?string
|
||||
{
|
||||
return $this->name_en;
|
||||
}
|
||||
|
||||
public function setNameEn(?string $name_en): static
|
||||
{
|
||||
$this->name_en = $name_en;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameFr(): ?string
|
||||
{
|
||||
return $this->name_fr;
|
||||
}
|
||||
|
||||
public function setNameFr(?string $name_fr): static
|
||||
{
|
||||
$this->name_fr = $name_fr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameAr(): ?string
|
||||
{
|
||||
return $this->name_ar;
|
||||
}
|
||||
|
||||
public function setNameAr(?string $name_ar): static
|
||||
{
|
||||
$this->name_ar = $name_ar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuestion(): ?Question
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
public function setQuestion(?Question $question): static
|
||||
{
|
||||
$this->question = $question;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\QuestionRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: QuestionRepository::class)]
|
||||
class Question
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_en = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_fr = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name_ar = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $choice = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $type_modality = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?float $amount = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $max_participant = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Modality>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question', cascade: ['persist', 'remove'])]
|
||||
private Collection $modalitys;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Filter>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Filter::class, mappedBy: 'question')]
|
||||
private Collection $filters;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'questions')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Investigation $investigation = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Attachment>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Attachment::class, mappedBy: 'question', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
private Collection $attachments;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->modalitys = new ArrayCollection();
|
||||
$this->filters = new ArrayCollection();
|
||||
$this->choice = false;
|
||||
$this->amount = 0;
|
||||
$this->max_participant = 0;
|
||||
$this->attachments = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->title = $this->title ." duplicate";
|
||||
|
||||
$this->name_en = $this->name_en ." duplicate";
|
||||
$this->name_fr = $this->name_fr ." duplicate";
|
||||
$this->name_ar = $this->name_ar ." duplicate";
|
||||
|
||||
$this->modalitys = new ArrayCollection();
|
||||
$this->filters = new ArrayCollection();
|
||||
$this->choice = false;
|
||||
$this->amount = 0;
|
||||
$this->max_participant = 0;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameEn(): ?string
|
||||
{
|
||||
return $this->name_en;
|
||||
}
|
||||
|
||||
public function setNameEn(?string $name_en): static
|
||||
{
|
||||
$this->name_en = $name_en;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameFr(): ?string
|
||||
{
|
||||
return $this->name_fr;
|
||||
}
|
||||
|
||||
public function setNameFr(?string $name_fr): static
|
||||
{
|
||||
$this->name_fr = $name_fr;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameAr(): ?string
|
||||
{
|
||||
return $this->name_ar;
|
||||
}
|
||||
|
||||
public function setNameAr(?string $name_ar): static
|
||||
{
|
||||
$this->name_ar = $name_ar;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isChoice(): ?bool
|
||||
{
|
||||
return $this->choice;
|
||||
}
|
||||
|
||||
public function setChoice(bool $choice): static
|
||||
{
|
||||
$this->choice = $choice;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTypeModality(): ?int
|
||||
{
|
||||
return $this->type_modality;
|
||||
}
|
||||
|
||||
public function setTypeModality(int $type_modality): static
|
||||
{
|
||||
$this->type_modality = $type_modality;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAmount(): ?float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
public function setAmount(float $amount): static
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxParticipant(): ?int
|
||||
{
|
||||
return $this->max_participant;
|
||||
}
|
||||
|
||||
public function setMaxParticipant(int $max_participant): static
|
||||
{
|
||||
$this->max_participant = $max_participant;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Modality>
|
||||
*/
|
||||
public function getModalitys(): Collection
|
||||
{
|
||||
return $this->modalitys;
|
||||
}
|
||||
|
||||
public function addModality(Modality $modality): static
|
||||
{
|
||||
if (!$this->modalitys->contains($modality)) {
|
||||
$this->modalitys->add($modality);
|
||||
$modality->setQuestion($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeModality(Modality $modality): static
|
||||
{
|
||||
if ($this->modalitys->removeElement($modality)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($modality->getQuestion() === $this) {
|
||||
$modality->setQuestion(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Filter>
|
||||
*/
|
||||
public function getFilters(): Collection
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
public function addFilter(Filter $filter): static
|
||||
{
|
||||
if (!$this->filters->contains($filter)) {
|
||||
$this->filters->add($filter);
|
||||
$filter->setQuestion($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeFilter(Filter $filter): static
|
||||
{
|
||||
if ($this->filters->removeElement($filter)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($filter->getQuestion() === $this) {
|
||||
$filter->setQuestion(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvestigation(): ?Investigation
|
||||
{
|
||||
return $this->investigation;
|
||||
}
|
||||
|
||||
public function setInvestigation(?Investigation $investigation): static
|
||||
{
|
||||
$this->investigation = $investigation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Attachment>
|
||||
*/
|
||||
public function getAttachments(): Collection
|
||||
{
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
public function addAttachment(Attachment $attachment): static
|
||||
{
|
||||
if (!$this->attachments->contains($attachment)) {
|
||||
$this->attachments->add($attachment);
|
||||
$attachment->setQuestion($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAttachment(Attachment $attachment): static
|
||||
{
|
||||
if ($this->attachments->removeElement($attachment)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($attachment->getQuestion() === $this) {
|
||||
$attachment->setQuestion(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\StateRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: StateRepository::class)]
|
||||
class State
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $step = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $progress = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?\DateTime $date = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?array $detail = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'states', cascade: ['persist'])]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Investigation $investigation = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'states')]
|
||||
private ?Broadcast $broadcast = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date = new \DateTime();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getStep(): ?int
|
||||
{
|
||||
return $this->step;
|
||||
}
|
||||
|
||||
public function setStep(int $step): static
|
||||
{
|
||||
$this->step = $step;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProgress(): ?int
|
||||
{
|
||||
return $this->progress;
|
||||
}
|
||||
|
||||
public function setProgress(int $progress): static
|
||||
{
|
||||
$this->progress = $progress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?\DateTime
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(\DateTime $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDetail(): ?array
|
||||
{
|
||||
return $this->detail;
|
||||
}
|
||||
|
||||
public function setDetail(?array $detail): static
|
||||
{
|
||||
$this->detail = $detail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvestigation(): ?Investigation
|
||||
{
|
||||
return $this->investigation;
|
||||
}
|
||||
|
||||
public function setInvestigation(?Investigation $investigation): static
|
||||
{
|
||||
$this->investigation = $investigation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBroadcast(): ?Broadcast
|
||||
{
|
||||
return $this->broadcast;
|
||||
}
|
||||
|
||||
public function setBroadcast(?Broadcast $broadcast): static
|
||||
{
|
||||
$this->broadcast = $broadcast;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private int $id;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $pseudo;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 180, unique: true)]
|
||||
private ?string $email;
|
||||
|
||||
#[ORM\Column(type: 'json')]
|
||||
private array $roles = [];
|
||||
|
||||
#[ORM\Column(type: 'string')]
|
||||
private string $password;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
private ?\DateTimeInterface $lastLogin = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
private ?\DateTimeInterface $dateAdd = null;
|
||||
|
||||
#[ORM\Column(length: 5, options:["default"=>"fr"])]
|
||||
private ?string $translator = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT)]
|
||||
private ?int $TypeUser = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Investigation>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Investigation::class, mappedBy: 'create_by')]
|
||||
private Collection $investigations;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Broadcast>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Broadcast::class, mappedBy: 'create_by')]
|
||||
private Collection $broadcasts;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dateAdd = new \DateTime();
|
||||
$this->lastLogin = new \DateTime();
|
||||
$this->translator = "fr";
|
||||
$this->roles = [];
|
||||
$this->investigations = new ArrayCollection();
|
||||
$this->broadcasts = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string
|
||||
{
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo(string $pseudo): self
|
||||
{
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): self
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The public representation of the user (e.g. a username, an email address, etc.)
|
||||
*
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return (string) $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = $this->roles;
|
||||
// guarantee every user at least has ROLE_USER
|
||||
$roles[] = 'ROLE_USER';
|
||||
|
||||
return array_unique($roles);
|
||||
}
|
||||
|
||||
public function setRoles(array $roles): self
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasRole(string $role): ?bool
|
||||
{
|
||||
$Indice = array_search($role, $this->roles);
|
||||
if(is_numeric($Indice)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function addRole(string $role): ?bool
|
||||
{
|
||||
if(!$this->hasRole($role)){
|
||||
$this->roles[] = $role;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeRole(string $role)
|
||||
{
|
||||
$Indice = array_search($role, $this->roles);
|
||||
if(is_numeric($Indice)){
|
||||
unset($this->roles[$Indice]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PasswordAuthenticatedUserInterface
|
||||
*/
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword(string $password): self
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// If you store any temporary, sensitive data on the user, clear it here
|
||||
// $this->plainPassword = null;
|
||||
}
|
||||
|
||||
public function getLastLogin(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->lastLogin;
|
||||
}
|
||||
|
||||
public function getLastLoginFormat($format): string
|
||||
{
|
||||
return $this->lastLogin->format($format);
|
||||
}
|
||||
|
||||
public function setLastLogin(\DateTimeInterface $lastLogin): self
|
||||
{
|
||||
$this->lastLogin = $lastLogin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateAdd(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->dateAdd;
|
||||
}
|
||||
|
||||
public function getDateAddText($format): ?string
|
||||
{
|
||||
return $this->dateAdd->format($format);
|
||||
}
|
||||
|
||||
public function setDateAdd(\DateTimeInterface $dateAdd): self
|
||||
{
|
||||
$this->dateAdd = $dateAdd;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTranslator(): ?string
|
||||
{
|
||||
return $this->translator;
|
||||
}
|
||||
|
||||
public function setTranslator(?string $translator): static
|
||||
{
|
||||
if($translator){
|
||||
$this->translator = $translator;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTypeUser(): ?int
|
||||
{
|
||||
return $this->TypeUser;
|
||||
}
|
||||
|
||||
public function setTypeUser(int $TypeUser): static
|
||||
{
|
||||
$this->TypeUser = $TypeUser;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Investigation>
|
||||
*/
|
||||
public function getInvestigations(): Collection
|
||||
{
|
||||
return $this->investigations;
|
||||
}
|
||||
|
||||
public function addInvestigation(Investigation $investigation): static
|
||||
{
|
||||
if (!$this->investigations->contains($investigation)) {
|
||||
$this->investigations->add($investigation);
|
||||
$investigation->setCreateBy($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeInvestigation(Investigation $investigation): static
|
||||
{
|
||||
if ($this->investigations->removeElement($investigation)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($investigation->getCreateBy() === $this) {
|
||||
$investigation->setCreateBy(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Broadcast>
|
||||
*/
|
||||
public function getBroadcasts(): Collection
|
||||
{
|
||||
return $this->broadcasts;
|
||||
}
|
||||
|
||||
public function addBroadcast(Broadcast $broadcast): static
|
||||
{
|
||||
if (!$this->broadcasts->contains($broadcast)) {
|
||||
$this->broadcasts->add($broadcast);
|
||||
$broadcast->setCreateBy($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeBroadcast(Broadcast $broadcast): static
|
||||
{
|
||||
if ($this->broadcasts->removeElement($broadcast)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($broadcast->getCreateBy() === $this) {
|
||||
$broadcast->setCreateBy(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class LocaleSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $defaultLocale;
|
||||
|
||||
public function __construct(
|
||||
private RequestStack $requestStack,
|
||||
string $defaultLocale = 'fr'
|
||||
) {
|
||||
$this->defaultLocale = $defaultLocale;
|
||||
}
|
||||
|
||||
public function onKernelRequest(RequestEvent $event): void
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
// Vérifier si la locale est définie dans la session
|
||||
$request->setLocale($request->getSession()->get('_locale') ?? $this->defaultLocale);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::REQUEST => [['onKernelRequest', 20]],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Attachment;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Vich\UploaderBundle\Form\Type\VichFileType; // Ajoutez cette ligne
|
||||
|
||||
class AttachmentType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('file', VichFileType::class, [ // Utilisez VichFileType au lieu de FileType
|
||||
'label' => 'Fichier',
|
||||
'required' => false,
|
||||
'allow_delete' => true,
|
||||
'delete_label' => 'Supprimer',
|
||||
'download_label' => 'Télécharger',
|
||||
'download_uri' => true,
|
||||
'asset_helper' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Attachment::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Broadcast;
|
||||
use App\Entity\Investigation;
|
||||
use App\Entity\User;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
|
||||
class BroadcastType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('date_start')
|
||||
->add('date_end')
|
||||
->add('notification_sms')
|
||||
->add('notification_email')
|
||||
->add("save", SubmitType::class)
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Broadcast::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Investigation;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Question;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
class InvestigationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name_en')
|
||||
->add('source_en')
|
||||
->add('name_fr')
|
||||
->add('source_fr')
|
||||
->add('name_ar')
|
||||
->add('source_ar')
|
||||
->add('questions', CollectionType::class, array(
|
||||
'entry_type' => QuestionType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'prototype' => true,
|
||||
'by_reference' => false
|
||||
))
|
||||
->add("save", SubmitType::class)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Investigation::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Modality;
|
||||
use App\Entity\Question;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ModalityType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name_en')
|
||||
->add('name_fr')
|
||||
->add('name_ar')
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Modality::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Question;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
|
||||
class QuestionType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('title')
|
||||
->add('name_en', null, [
|
||||
'label' => '🇬🇧 Name',
|
||||
])
|
||||
->add('name_fr', null, [
|
||||
'label' => '🇫🇷 Nom',
|
||||
])
|
||||
->add('name_ar', null, [
|
||||
'label' => '🇸🇦 العربية',
|
||||
])
|
||||
->add('choice', ChoiceType::class, [
|
||||
'label' => 'Gender',
|
||||
'choices' => [
|
||||
'Choix Multiple' => 'multiple',
|
||||
'Choix Unique' => 'unique',
|
||||
],
|
||||
'expanded' => true, // This makes it radio buttons instead of select
|
||||
'multiple' => false, // Single selection
|
||||
'required' => true,
|
||||
'placeholder' => false, // Remove the empty option
|
||||
])
|
||||
->add('type_modality', ChoiceType::class, [
|
||||
'label' => 'Type',
|
||||
'choices' => [
|
||||
'Text' => '1',
|
||||
'Image' => '3',
|
||||
'Video' => '4',
|
||||
'Son' => '5',
|
||||
'Form Text' => '2',
|
||||
],
|
||||
'placeholder' => 'Choose a type modality', // Optional placeholder
|
||||
'required' => true,
|
||||
])
|
||||
->add('amount')
|
||||
->add('max_participant')
|
||||
->add('modalitys', CollectionType::class, array(
|
||||
'entry_type' => ModalityType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'prototype' => true,
|
||||
'by_reference' => false
|
||||
))
|
||||
->add('attachments', CollectionType::class, [
|
||||
'label' => 'Pièces jointes',
|
||||
'entry_type' => AttachmentType::class,
|
||||
'entry_options' => ['label' => false],
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'by_reference' => false,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__attachment_prot__',
|
||||
'required' => false,
|
||||
]);
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Question::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
|
||||
class UserRegistrationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('pseudo', null, ['label' => 'pseudo', 'attr' => [ 'placeholder' => 'placeholder_pseudo'] ])
|
||||
->add('email', null, ['label' => 'placeholder_email', 'attr' => [ 'placeholder' => 'placeholder_email'] ])
|
||||
->add('password', null, ['label' => 'password', 'attr' => [ 'placeholder' => 'password'] ])
|
||||
->add('TypeUser', ChoiceType::class, array(
|
||||
'label' => 'placeholder_type_user',
|
||||
'attr' => [ 'placeholder' => 'placeholder_type_user'],
|
||||
'choices' => ['choice_type_user_0' => 0, 'choice_type_user_1' => 1 ],
|
||||
'expanded' => true
|
||||
))
|
||||
->add('cgu', CheckboxType::class, array(
|
||||
'mapped' => false,
|
||||
'label' => 'i_accept',
|
||||
'constraints' => [
|
||||
new IsTrue(message: 'Merci d’accepter les conditions générales d’utilisation en cochant la case ci-dessous'),
|
||||
],
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => User::class,
|
||||
'translation_domain' => 'authentications',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Attachment;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Attachment>
|
||||
*/
|
||||
class AttachmentRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Attachment::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Attachment[] Returns an array of Attachment objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('a')
|
||||
// ->andWhere('a.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('a.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Attachment
|
||||
// {
|
||||
// return $this->createQueryBuilder('a')
|
||||
// ->andWhere('a.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Broadcast;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Broadcast>
|
||||
*/
|
||||
class BroadcastRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Broadcast::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Broadcast[] Returns an array of Broadcast objects
|
||||
*/
|
||||
public function findByUser(User $user): array
|
||||
{
|
||||
return $this->createQueryBuilder('b')
|
||||
->where('b.create_by = :User')
|
||||
->setParameter('User', $user)
|
||||
->orderBy('b.date_create', 'DESC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Broadcast[] Returns an array of Broadcast objects
|
||||
*/
|
||||
public function findBroadcast()
|
||||
{
|
||||
return $this->createQueryBuilder('b')
|
||||
->where('b.last_state = 31')
|
||||
->andWhere('b.date_start <= :DateNow')
|
||||
->andWhere('b.date_end >= :DateNow')
|
||||
->setParameter('DateNow', new \DateTime())
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Broadcast[] Returns an array of Broadcast objects
|
||||
*/
|
||||
public function findBroadcastByUser(User $user)
|
||||
{
|
||||
return $this->createQueryBuilder('b')
|
||||
->where('b.last_state = 32')
|
||||
->where('b.create_by = :User')
|
||||
->setParameter('User', $user)
|
||||
->andWhere('b.date_start <= :DateNow')
|
||||
->setParameter('DateNow', new \DateTime())
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Filter;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Filter>
|
||||
*/
|
||||
class FilterRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Filter::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Filter[] Returns an array of Filter objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('f')
|
||||
// ->andWhere('f.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('f.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Filter
|
||||
// {
|
||||
// return $this->createQueryBuilder('f')
|
||||
// ->andWhere('f.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Investigation;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Investigation>
|
||||
*/
|
||||
class InvestigationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Investigation::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Investigation[] Returns an array of Investigation objects
|
||||
*/
|
||||
public function findByStep($user, $value): array
|
||||
{
|
||||
return $this->createQueryBuilder('i')
|
||||
|
||||
->innerJoin('i.states', 's')
|
||||
|
||||
->where('i.create_by = :User')
|
||||
->setParameter('User', $user)
|
||||
|
||||
->andWhere('s.step = :val')
|
||||
->setParameter('val', $value)
|
||||
|
||||
->orderBy('i.id', 'ASC')
|
||||
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findInvestigationAdminValidated(User $user): array
|
||||
{
|
||||
return $this->createQueryBuilder('INVES')
|
||||
|
||||
->where('INVES.create_by = :User')
|
||||
->setParameter('User', $user)
|
||||
|
||||
->andWhere('INVES.last_state = 20')
|
||||
|
||||
->orderBy('INVES.id', 'ASC')
|
||||
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
// public function findOneBySomeField($value): ?Investigation
|
||||
// {
|
||||
// return $this->createQueryBuilder('i')
|
||||
// ->andWhere('i.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Modality;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Modality>
|
||||
*/
|
||||
class ModalityRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Modality::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Modality[] Returns an array of Modality objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('m.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Modality
|
||||
// {
|
||||
// return $this->createQueryBuilder('m')
|
||||
// ->andWhere('m.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Question;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Question>
|
||||
*/
|
||||
class QuestionRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Question::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Question[] Returns an array of Question objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('q')
|
||||
// ->andWhere('q.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('q.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Question
|
||||
// {
|
||||
// return $this->createQueryBuilder('q')
|
||||
// ->andWhere('q.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\State;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<State>
|
||||
*/
|
||||
class StateRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, State::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function addState($investigation, $step, $progress, $broadcast = null): int
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$state = new State();
|
||||
$state->setInvestigation($investigation);
|
||||
$state->setStep($step);
|
||||
$state->setProgress($progress);
|
||||
$state->setBroadcast($broadcast);
|
||||
|
||||
$em->persist($state);
|
||||
$em->flush();
|
||||
|
||||
return (int) $step . $progress;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * @return State[] Returns an array of State objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('s')
|
||||
// ->andWhere('s.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('s.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?State
|
||||
// {
|
||||
// return $this->createQueryBuilder('s')
|
||||
// ->andWhere('s.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<User>
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return User[] Returns an array of User objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('u.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?User
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
||||
use Symfony\Component\Security\Http\Util\TargetPathTrait;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class LoginAuthenticator extends AbstractLoginFormAuthenticator
|
||||
{
|
||||
use TargetPathTrait;
|
||||
|
||||
public const LOGIN_ROUTE = 'app_sign_in';
|
||||
|
||||
private $em;
|
||||
|
||||
private $authenticationUtils;
|
||||
|
||||
public function __construct(private UrlGeneratorInterface $urlGenerator, EntityManagerInterface $em, AuthenticationUtils $authenticationUtils)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->authenticationUtils = $authenticationUtils;
|
||||
}
|
||||
|
||||
public function authenticate(Request $request): Passport
|
||||
{
|
||||
$email = $request->request->get('email', '');
|
||||
|
||||
$request->getSession()->set($this->authenticationUtils->getLastUsername(), $email);
|
||||
|
||||
return new Passport(
|
||||
new UserBadge($email),
|
||||
new PasswordCredentials($request->request->get('password', '')),
|
||||
[
|
||||
new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')),
|
||||
new RememberMeBadge(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
|
||||
{
|
||||
if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) {
|
||||
return new RedirectResponse($targetPath);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $token->getUser();
|
||||
$user->setLastLogin(new \DateTime());
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
|
||||
return new RedirectResponse($this->urlGenerator->generate('app_home'));
|
||||
}
|
||||
|
||||
protected function getLoginUrl(Request $request): string
|
||||
{
|
||||
return $this->urlGenerator->generate(self::LOGIN_ROUTE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user