diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index 150595b..0c7a22e 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -3,7 +3,6 @@ namespace App\Controller; use App\Entity\Announcement; -use App\Entity\InternApplication; use App\Form\AnnouncementType; use App\Repository\AnnouncementRepository; use Doctrine\ORM\EntityManagerInterface; @@ -12,112 +11,95 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; -#[Route('/announcement', name: 'app_announcement')] -class AnnouncementController extends AbstractController +#[Route('/announcement')] +final class AnnouncementController extends AbstractController { - public function __construct( - private readonly EntityManagerInterface $entityManager, - private readonly AnnouncementRepository $announcementRepository - ) + #[Route('/', name: 'app_announcement_index', methods: ['GET'])] + public function index(Request $request, AnnouncementRepository $announcementRepository): Response { + $showNonValidated = $request->query->get('show_non_validated') === '1'; + + $announcements = $showNonValidated + ? $announcementRepository->findBy(['status' => 'notVerified']) + : $announcementRepository->findAll(); + + + return $this->render('announcement/index.html.twig', [ + 'announcements' => $announcements, + 'showNonValidated' => $showNonValidated, + ]); } - #[Route('/add', name: '_add')] - public function addAnnouncement(Request $request): Response + + + #[Route('/new', name: 'app_announcement_new', methods: ['GET', 'POST'])] + public function new(Request $request, EntityManagerInterface $entityManager): Response { $announcement = new Announcement(); $form = $this->createForm(AnnouncementType::class, $announcement); $form->handleRequest($request); - if($form->isSubmitted() && $form->isValid()) - { - //met la date de création de l'annonce au moment où le formulaire est envoyé + if ($form->isSubmitted() && $form->isValid()) { $announcement->setCreationDate(new \DateTime()); + $announcement->setStatus('notVerified'); + $entityManager->persist($announcement); + $entityManager->flush(); - $this->entityManager->persist($announcement); - $this->entityManager->flush(); - - $this->addFlash('success', 'Annonce créée avec succès.'); - return $this->redirectToRoute('app_announcement_list'); + return $this->redirectToRoute('app_announcement_index', [], Response::HTTP_SEE_OTHER); } - return $this->render('announcement/add.html.twig', [ - 'announcementForm' => $form, + return $this->render('announcement/new.html.twig', [ + 'announcement' => $announcement, + 'form' => $form, ]); } - #[Route('/list', name: '_list')] - public function list(): Response + #[Route('/{id}', name: 'app_announcement_show', methods: ['GET'])] + public function show(Announcement $announcement): Response { - $announcements = $this->announcementRepository->findAll(); - - return $this->render('announcement/list.html.twig', [ - 'announcements' => $announcements, + return $this->render('announcement/show.html.twig', [ + 'announcement' => $announcement, ]); } - #[Route('/update/{id}', name: '_update')] - public function update(int $id, Request $request): Response + #[Route('/{id}/edit', name: 'app_announcement_edit', methods: ['GET', 'POST'])] + public function edit(Request $request, Announcement $announcement, EntityManagerInterface $entityManager): Response { - $announcement = $this->announcementRepository->find($id); $form = $this->createForm(AnnouncementType::class, $announcement); $form->handleRequest($request); - if($form->isSubmitted() && $form->isValid()) + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('app_announcement_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('announcement/edit.html.twig', [ + 'announcement' => $announcement, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_announcement_delete', methods: ['POST'])] + public function delete(Request $request, Announcement $announcement, EntityManagerInterface $entityManager): Response + { + if ($this->isCsrfTokenValid('delete'.$announcement->getId(), $request->getPayload()->getString('_token'))) { + $entityManager->remove($announcement); + $entityManager->flush(); + } + + return $this->redirectToRoute('app_announcement_index', [], Response::HTTP_SEE_OTHER); + } + + #[Route('/{id}/validate', name: 'app_announcement_validate', methods: ['POST'])] + public function validate(Request $request, Announcement $announcement, EntityManagerInterface $entityManager): Response + { + if ($announcement->getStatus() !== 'Verified') { - $this->entityManager->persist($announcement); - $this->entityManager->flush(); - - $this->addFlash('success', 'Annonce modifiéé avec succès.'); - return $this->redirectToRoute('app_announcement_list'); + $announcement->setStatus('Verified'); + $entityManager->flush(); } - - return $this->render('announcement/add.html.twig', [ - 'formAdd' => $form, - ]); + return $this->redirectToRoute('app_announcement_show', + ['id' => $announcement->getId()], Response::HTTP_SEE_OTHER); } - #[Route('/delete/{id}', name: '_delete')] - public function delete(int $id): Response - { - $announcement = $this->announcementRepository->find($id); - $this->entityManager->remove($announcement); - $this->entityManager->flush(); - - return $this->redirectToRoute('app_announcement_list'); - } - - #[Route('/apply/{id}', name: '_apply')] - public function applyToAnnouncement(int $id): Response - { - - $announcement = $this->announcementRepository->find($id); - - $user = $this->getUser(); - - $existingCandidature = $this->entityManager->getRepository(InternApplication::class)->findOneBy([ - 'intern' => $user, - 'announcement' => $announcement - ]); - - if($existingCandidature) { - $this->addFlash('error', 'Vous avez déjà postulé à cette annonce.'); - return $this->redirectToRoute('app_announcement_list'); - } - $application = new InternApplication(); - $application->setIntern($user); - $application->setIntern($announcement); - $application->setApplicationDate(new \DateTime()); - - $this->entityManager->persist($application); - $this->entityManager->flush(); - - $this->addFlash('success', 'Votre candidature a été envoyée avec succès.'); - return $this->redirectToRoute('annonce_list', ['id' => $announcement->getId()]); - } - - #[Route('/filterByCompany', name: '_filterByCompany')] - public function filterByCompany(int $id): Response - { - return $this->redirectToRoute('annonce_list', ['id' => $id]); - } } diff --git a/src/Controller/FAQController.php b/src/Controller/FAQController.php index fbba2aa..2a3aa50 100644 --- a/src/Controller/FAQController.php +++ b/src/Controller/FAQController.php @@ -30,6 +30,7 @@ final class FAQController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + $fAQ->setUpdateDate(new \DateTime()); $entityManager->persist($fAQ); $entityManager->flush(); @@ -57,6 +58,7 @@ final class FAQController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + $fAQ->setUpdateDate(new \DateTime()); $entityManager->flush(); return $this->redirectToRoute('app_faq_index', [], Response::HTTP_SEE_OTHER); diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index ed4d371..ae207a9 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -22,15 +22,18 @@ class Announcement #[ORM\Column(length: 255)] private ?string $description = null; - #[ORM\Column(type: Types::DATE_MUTABLE)] - private ?\DateTimeInterface $creationDate = null; - #[ORM\ManyToOne(inversedBy: 'announcements')] #[ORM\JoinColumn(nullable: false)] private ?Company $company = null; - #[ORM\Column(length: 255,nullable: false)] - private ?string $status = "notVerified"; + #[ORM\Column(nullable: false)] + private ?string $status = "notVerfied"; + + #[ORM\Column(nullable: false)] + private ?string $date = null; + + #[ORM\Column(type: Types::DATE_MUTABLE)] + private ?\DateTimeInterface $creationDate = null; /** * @var ?Collection @@ -96,7 +99,7 @@ class Announcement return $this->status; } - public function setStatus(?string $status): static + public function setStatus(?string $status): self { $this->status = $status; @@ -174,4 +177,16 @@ class Announcement return $this; } -} + + public function getDate(): ?string + { + return $this->date; + } + + public function setDate(string $date): self + { + $this->date = $date; + return $this; + } + +} \ No newline at end of file diff --git a/src/Form/AnnouncementType.php b/src/Form/AnnouncementType.php index 21a844d..c6c87ed 100644 --- a/src/Form/AnnouncementType.php +++ b/src/Form/AnnouncementType.php @@ -10,7 +10,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; - +use Symfony\Component\Form\Extension\Core\Type\TextType; class AnnouncementType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void @@ -20,9 +20,12 @@ class AnnouncementType extends AbstractType ->add('description') ->add('company', EntityType::class, [ 'class' => Company::class, - 'choice_label' => 'id', + 'choice_label' => 'name', + ]) + ->add('date', TextType::class, [ + 'label' => 'Date de stage', + 'required' => true, ]) - ->add('submit', SubmitType::class) ; } @@ -32,4 +35,4 @@ class AnnouncementType extends AbstractType 'data_class' => Announcement::class, ]); } -} +} \ No newline at end of file diff --git a/src/Form/FAQType.php b/src/Form/FAQType.php index c420a1c..0038157 100644 --- a/src/Form/FAQType.php +++ b/src/Form/FAQType.php @@ -13,11 +13,7 @@ class FAQType extends AbstractType { $builder ->add('question') - ->add('answer') - ->add('updateDate', null, [ - 'widget' => 'single_text', - ]) - ; + ->add('answer'); } public function configureOptions(OptionsResolver $resolver): void diff --git a/templates/announcement/_delete_form.html.twig b/templates/announcement/_delete_form.html.twig new file mode 100644 index 0000000..417af85 --- /dev/null +++ b/templates/announcement/_delete_form.html.twig @@ -0,0 +1,4 @@ +
+ + +
diff --git a/templates/announcement/_form.html.twig b/templates/announcement/_form.html.twig new file mode 100644 index 0000000..30b9809 --- /dev/null +++ b/templates/announcement/_form.html.twig @@ -0,0 +1,4 @@ +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/templates/announcement/add.html.twig b/templates/announcement/add.html.twig deleted file mode 100644 index 73233c7..0000000 --- a/templates/announcement/add.html.twig +++ /dev/null @@ -1,4 +0,0 @@ -{% extends 'base.html.twig' %} -{% block body %} - {{ form(announcementForm) }} -{% endblock %} \ No newline at end of file diff --git a/templates/announcement/edit.html.twig b/templates/announcement/edit.html.twig new file mode 100644 index 0000000..92f6620 --- /dev/null +++ b/templates/announcement/edit.html.twig @@ -0,0 +1,63 @@ +{% extends 'base.html.twig' %} + +{% block title %}Modifier l'Annonce{% endblock %} + +{% block body %} +
+

Modifier l'Annonce

+ +
+
+ {{ form_start(form) }} + +
+ + +
+ {{ form_widget(form.company, {'attr': {'class': 'w-full p-3 border rounded-md'}}) }} +
+
+ + +
+ +
+ {{ form_widget(form.title, {'attr': {'class': 'w-full p-3 border rounded-md'}}) }} +
+
+ + +
+ +
+ {{ form_widget(form.description, { 'attr': { 'class': 'w-full p-3 border rounded-md' } }) }} +
+
+ + +
+ +
+ {{ form_widget(form.date, { 'attr': { 'class': 'w-full p-3 border rounded-md' } }) }} +
+
+ + +
+ +
+ + {{ form_end(form) }} +
+
+ + + +
+{% endblock %} diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig index aca0c93..028356d 100644 --- a/templates/announcement/index.html.twig +++ b/templates/announcement/index.html.twig @@ -1,20 +1,78 @@ {% extends 'base.html.twig' %} -{% block title %}Hello AnnouncementController!{% endblock %} +{% block title %}Liste des Annonces{% endblock %} {% block body %} - +
+

Liste des Annonces

-
-

Hello {{ controller_name }}! ✅

+ +
+ + +
- This friendly message is coming from: -
    -
  • Your controller at C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/src/Controller/AnnouncementController.php
  • -
  • Your template at C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/templates/announcement/index.html.twig
  • -
-
+ + + + +
+ {% for announcement in announcements %} +
+ +
+ {% if announcement.status == 'notVerified' %} + Non validée + {% else %} + Validée + {% endif %} +
+ + +

{{ announcement.title }}

+ + +

{{ announcement.company.name }}

+ +
+ +
+ + Date du stage : {{ announcement.date }} +
+ + +
+ + {{ announcement.company.address }} +
+
+ + + + Détails + +
+ {% else %} +

Aucune annonce disponible.

+ {% endfor %} +
+
{% endblock %} + diff --git a/templates/announcement/list.html.twig b/templates/announcement/list.html.twig deleted file mode 100644 index 541caaa..0000000 --- a/templates/announcement/list.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Bienvenue sur Hegreshpere{% endblock %} - -{% block body %} - - -

Liste des annonces

- {% for ann in announcements %} -

{{ ann.title }}

-

{{ ann.company.name }}

-

{{ ann.description }}

- ------------------------------ - -

{{ ann.creationDate|date("d-m-y") }}

- {% endfor %} - - -{% endblock %} \ No newline at end of file diff --git a/templates/announcement/new.html.twig b/templates/announcement/new.html.twig new file mode 100644 index 0000000..c6d4b5c --- /dev/null +++ b/templates/announcement/new.html.twig @@ -0,0 +1,31 @@ +{% extends 'base.html.twig' %} + +{% block title %}Créer une Annonce{% endblock %} + +{% block body %} +
+

Créer une Annonce

+ + {{ form_start(form) }} +
+ {{ form_label(form.title) }} + {{ form_widget(form.title, {'attr': {'class': 'form-input w-full p-2 rounded border'}}) }} +
+
+ {{ form_label(form.description) }} + {{ form_widget(form.description, {'attr': {'class': 'form-input w-full p-2 rounded border'}}) }} +
+
+ {{ form_label(form.date) }} + {{ form_widget(form.date, {'attr': {'class': 'form-input w-full p-2 rounded border'}}) }} +
+
+ {{ form_label(form.company) }} + {{ form_widget(form.company, {'attr': {'class': 'form-input w-full p-2 rounded border'}}) }} +
+ + {{ form_end(form) }} +
+{% endblock %} diff --git a/templates/announcement/show.html.twig b/templates/announcement/show.html.twig new file mode 100644 index 0000000..d35e158 --- /dev/null +++ b/templates/announcement/show.html.twig @@ -0,0 +1,77 @@ +{% extends 'base.html.twig' %} + +{% block title %}Détails de l'Annonce{% endblock %} + +{% block body %} +
+

Détails de l'Annonce

+ + +
+ +

{{ announcement.title }}

+ + +

{{ announcement.company.name }}

+ +
+ +
+ + Date du stage : {{ announcement.date }} +
+ + +
+ + {{ announcement.company.address }} +
+
+ + +
+ Description du stage : +

{{ announcement.description }}

+
+ + +
+ Statut : + + {% if announcement.status == 'notVerified' %} + Non validée + {% else %} + Validée + {% endif %} + +
+ + +
+ Date de création : + {{ announcement.creationDate | date('d/m/Y') }} +
+ + +
+ + Modifier l'annonce + + + {% if announcement.status == 'notVerified' %} +
+ +
+ {% endif %} +
+
+ + + + Retour à la liste des annonces + +
+{% endblock %} diff --git a/templates/base.html.twig b/templates/base.html.twig index f7bf832..0f85cf3 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -28,7 +28,7 @@
@@ -61,12 +61,9 @@
-

Contactez-nous

Email: support@hegresphere.com

diff --git a/templates/faq/index.html.twig b/templates/faq/index.html.twig index 46efd88..be69921 100644 --- a/templates/faq/index.html.twig +++ b/templates/faq/index.html.twig @@ -10,18 +10,18 @@ - + {% for faq in faqs %} - +
ID Question RéponseDenrnière modif Actions
{{ faq.id }} {{ faq.question }} {{ faq.answer }}{{ faq.updateDate|date("d-m-y") }} Voir diff --git a/templates/faq/show.html.twig b/templates/faq/show.html.twig index d6ccc55..1b986f3 100644 --- a/templates/faq/show.html.twig +++ b/templates/faq/show.html.twig @@ -24,25 +24,25 @@
-
- + + Retour à la liste des FAQs - - Modifier cette FAQ - -
- -
-
- - - -
+ +
+ + Modifier cette FAQ + +
+ + + +
+
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/templates/profile/index.html.twig b/templates/profile/index.html.twig index 251ddc1..0c4742a 100644 --- a/templates/profile/index.html.twig +++ b/templates/profile/index.html.twig @@ -15,5 +15,11 @@ {% if 'ROLE_EMPLOYEE' in app.user.roles %} {% include 'profile/employee.html.twig' %} {% endif %} + + {% if 'ROLE_ADMIN' in app.user.roles%} +
+

Vous etes admin

+
+ {% endif %} {% endblock %} diff --git a/templates/profile/intern.html.twig b/templates/profile/intern.html.twig index 1482561..5d6e0b3 100644 --- a/templates/profile/intern.html.twig +++ b/templates/profile/intern.html.twig @@ -19,6 +19,10 @@ Aucun pour le moment {% endif %} +
+ Selectionner vos diplômes +

Vos compétences :

+
+ Selectionner vos compétences +