From 579a56c53f6f2ffed725c1171056e6397999ba23 Mon Sep 17 00:00:00 2001 From: bourgoino Date: Mon, 9 Dec 2024 15:47:20 +0100 Subject: [PATCH] fixation beton --- migrations/Version20241017125351.php | 48 --------- src/Controller/AnnouncementController.php | 99 +++++++++++-------- src/Entity/Announcement.php | 25 ++++- src/Form/AnnouncementType.php | 11 +-- templates/announcement/_delete_form.html.twig | 4 + templates/announcement/_form.html.twig | 4 + templates/announcement/add.html.twig | 4 - templates/announcement/edit.html.twig | 63 ++++++++++++ templates/announcement/index.html.twig | 84 +++++++++++++--- templates/announcement/list.html.twig | 26 ----- templates/announcement/new.html.twig | 31 ++++++ templates/announcement/show.html.twig | 77 +++++++++++++++ templates/base.html.twig | 6 +- templates/faq/show.html.twig | 29 +++--- templates/index/index.html.twig | 36 ------- 15 files changed, 353 insertions(+), 194 deletions(-) delete mode 100644 migrations/Version20241017125351.php create mode 100644 templates/announcement/_delete_form.html.twig create mode 100644 templates/announcement/_form.html.twig delete mode 100644 templates/announcement/add.html.twig create mode 100644 templates/announcement/edit.html.twig delete mode 100644 templates/announcement/list.html.twig create mode 100644 templates/announcement/new.html.twig create mode 100644 templates/announcement/show.html.twig diff --git a/migrations/Version20241017125351.php b/migrations/Version20241017125351.php deleted file mode 100644 index e9561a5..0000000 --- a/migrations/Version20241017125351.php +++ /dev/null @@ -1,48 +0,0 @@ -addSql('DROP SEQUENCE user_id_seq CASCADE'); - $this->addSql('CREATE SEQUENCE "userApp_id_seq" INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE "userApp" (id INT NOT NULL, nickname VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NICKNAME ON "userApp" (nickname)'); - $this->addSql('ALTER TABLE employee DROP CONSTRAINT fk_5d9f75a1bf396750'); - $this->addSql('ALTER TABLE intern DROP CONSTRAINT fk_a5795f36bf396750'); - $this->addSql('DROP TABLE employee'); - $this->addSql('DROP TABLE "user"'); - $this->addSql('DROP TABLE intern'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('DROP SEQUENCE "userApp_id_seq" CASCADE'); - $this->addSql('CREATE SEQUENCE user_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE employee (id INT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE "user" (id INT NOT NULL, nickname VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, discriminator VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX uniq_identifier_nickname ON "user" (nickname)'); - $this->addSql('CREATE TABLE intern (id INT NOT NULL, cover_letter TEXT NOT NULL, resume VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('ALTER TABLE employee ADD CONSTRAINT fk_5d9f75a1bf396750 FOREIGN KEY (id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE intern ADD CONSTRAINT fk_a5795f36bf396750 FOREIGN KEY (id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('DROP TABLE "userApp"'); - } -} diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index 9ca78fc..0c7a22e 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -11,74 +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()) - { - $this->entityManager->persist($announcement); - $this->entityManager->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('app_announcement_index', [], Response::HTTP_SEE_OTHER); } - return $this->render('announcement/add.html.twig', [ - 'formAdd' => $form, + return $this->render('announcement/edit.html.twig', [ + 'announcement' => $announcement, + 'form' => $form, ]); } - #[Route('/delete/{id}', name: '_delete')] - public function delete(int $id): Response + #[Route('/{id}', name: 'app_announcement_delete', methods: ['POST'])] + public function delete(Request $request, Announcement $announcement, EntityManagerInterface $entityManager): Response { - $announcement = $this->announcementRepository->find($id); - $this->entityManager->remove($announcement); - $this->entityManager->flush(); + if ($this->isCsrfTokenValid('delete'.$announcement->getId(), $request->getPayload()->getString('_token'))) { + $entityManager->remove($announcement); + $entityManager->flush(); + } - return $this->redirectToRoute('app_announcement_list'); + 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') + { + $announcement->setStatus('Verified'); + $entityManager->flush(); + } + return $this->redirectToRoute('app_announcement_show', + ['id' => $announcement->getId()], Response::HTTP_SEE_OTHER); + } + } diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 757de84..9e1694e 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -27,7 +27,13 @@ class Announcement private ?Company $company = null; #[ORM\Column(nullable: false)] - private ?string $status = null; + private ?string $status = "notVerfied"; + + #[ORM\Column(nullable: false)] + private ?string $date = null; + + #[ORM\Column(type: Types::DATE_MUTABLE)] + private ?\DateTimeInterface $creationDate = null; /** * @var ?Collection @@ -41,9 +47,6 @@ class Announcement #[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'announcement')] private ?Collection $favoritesInterns; - #[ORM\Column(type: Types::DATE_MUTABLE)] - private ?\DateTimeInterface $creationDate = null; - public function __construct() { $this->applicants = new ArrayCollection(); @@ -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; + } + } diff --git a/src/Form/AnnouncementType.php b/src/Form/AnnouncementType.php index ef1255f..cc5b5ba 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,13 +20,12 @@ class AnnouncementType extends AbstractType ->add('description') ->add('company', EntityType::class, [ 'class' => Company::class, - 'choice_label' => 'id', + 'choice_label' => 'name', ]) - ->add('status', EntityType::class, [ - 'class' => Status::class, - 'choice_label' => 'id', + ->add('date', TextType::class, [ + 'label' => 'Date de stage', + 'required' => true, ]) - ->add('submit', SubmitType::class) ; } 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..bf20b98 --- /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 737f0f4..0000000 --- a/templates/announcement/list.html.twig +++ /dev/null @@ -1,26 +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 %} diff --git a/templates/announcement/new.html.twig b/templates/announcement/new.html.twig new file mode 100644 index 0000000..120d18b --- /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 1b5a07a..62b17e9 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -27,8 +27,8 @@
@@ -57,7 +57,7 @@

Liens utiles

diff --git a/templates/faq/show.html.twig b/templates/faq/show.html.twig index d6ccc55..b635ecc 100644 --- a/templates/faq/show.html.twig +++ b/templates/faq/show.html.twig @@ -26,23 +26,24 @@
- -
-
- - - -
+ +
+ + Modifier cette FAQ + +
+ + + +
+
{% endblock %} diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index a5a2a55..a84473b 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -37,40 +37,4 @@ - -
-
-

Propositions de stages

- Voir tout -
-
- {# Loop over recent offers (replace with dynamic data) - {% for offer in recent_offers %} -
-
-
{{ offer.time_ago }}
-
-

{{ offer.title }}

-

{{ offer.company }}

-
- - {{ offer.category }} - - - {{ offer.type }} - - - {{ offer.salary }} - - - {{ offer.location }} - -
-
-
- -
- {% endfor %}#} -
-
{% endblock %}