From a65eb73b81798c041d4f11ecc1c97fb64767e292 Mon Sep 17 00:00:00 2001 From: Romain Date: Mon, 11 Nov 2024 16:00:51 +0100 Subject: [PATCH] ajout FAQ + premiers controller / vues / formulaire pour annonce --- src/Controller/AnnouncementController.php | 84 +++++++++++++++++++++++ src/Entity/Announcement.php | 24 +++++-- src/Entity/FAQ.php | 66 ++++++++++++++++++ src/Entity/Obtaining.php | 36 ---------- src/Form/AnnouncementType.php | 39 +++++++++++ src/Repository/FAQRepository.php | 43 ++++++++++++ templates/announcement/add.html.twig | 14 ++++ templates/announcement/index.html.twig | 20 ++++++ templates/announcement/list.html.twig | 21 ++++++ 9 files changed, 307 insertions(+), 40 deletions(-) create mode 100644 src/Controller/AnnouncementController.php create mode 100644 src/Entity/FAQ.php delete mode 100644 src/Entity/Obtaining.php create mode 100644 src/Form/AnnouncementType.php create mode 100644 src/Repository/FAQRepository.php create mode 100644 templates/announcement/add.html.twig create mode 100644 templates/announcement/index.html.twig create mode 100644 templates/announcement/list.html.twig diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php new file mode 100644 index 0000000..9ca78fc --- /dev/null +++ b/src/Controller/AnnouncementController.php @@ -0,0 +1,84 @@ +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é + $announcement->setCreationDate(new \DateTime()); + + $this->entityManager->persist($announcement); + $this->entityManager->flush(); + + $this->addFlash('success', 'Annonce créée avec succès.'); + return $this->redirectToRoute('app_announcement_list'); + } + + return $this->render('announcement/add.html.twig', [ + 'announcementForm' => $form, + ]); + } + + #[Route('/list', name: '_list')] + public function list(): Response + { + $announcements = $this->announcementRepository->findAll(); + + return $this->render('announcement/list.html.twig', [ + 'announcements' => $announcements, + ]); + } + + #[Route('/update/{id}', name: '_update')] + public function update(int $id, Request $request): 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(); + } + + return $this->render('announcement/add.html.twig', [ + 'formAdd' => $form, + ]); + } + + #[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'); + } +} diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 5cf1c55..94cf1a6 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Repository\AnnouncementRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: AnnouncementRepository::class)] @@ -30,16 +31,19 @@ class Announcement private ?Status $status = null; /** - * @var Collection + * @var ?Collection */ #[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'application')] - private Collection $applicants; + private ?Collection $applicants; /** - * @var Collection + * @var ?Collection */ #[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'announcement')] - private Collection $favoritesInterns; + private ?Collection $favoritesInterns; + + #[ORM\Column(type: Types::DATE_MUTABLE)] + private ?\DateTimeInterface $creationDate = null; public function __construct() { @@ -159,4 +163,16 @@ class Announcement return $this; } + + public function getCreationDate(): ?\DateTimeInterface + { + return $this->creationDate; + } + + public function setCreationDate(\DateTimeInterface $creationDate): static + { + $this->creationDate = $creationDate; + + return $this; + } } diff --git a/src/Entity/FAQ.php b/src/Entity/FAQ.php new file mode 100644 index 0000000..986bc05 --- /dev/null +++ b/src/Entity/FAQ.php @@ -0,0 +1,66 @@ +id; + } + + public function getQuestion(): ?string + { + return $this->question; + } + + public function setQuestion(string $question): static + { + $this->question = $question; + + return $this; + } + + public function getAnswer(): ?string + { + return $this->answer; + } + + public function setAnswer(?string $answer): static + { + $this->answer = $answer; + + return $this; + } + + public function getUpdateDate(): ?\DateTimeInterface + { + return $this->updateDate; + } + + public function setUpdateDate(\DateTimeInterface $updateDate): static + { + $this->updateDate = $updateDate; + + return $this; + } +} diff --git a/src/Entity/Obtaining.php b/src/Entity/Obtaining.php deleted file mode 100644 index cecb3c1..0000000 --- a/src/Entity/Obtaining.php +++ /dev/null @@ -1,36 +0,0 @@ -id; - } - - public function getDate(): ?\DateTimeInterface - { - return $this->date; - } - - public function setDate(\DateTimeInterface $date): static - { - $this->date = $date; - - return $this; - } -} diff --git a/src/Form/AnnouncementType.php b/src/Form/AnnouncementType.php new file mode 100644 index 0000000..ef1255f --- /dev/null +++ b/src/Form/AnnouncementType.php @@ -0,0 +1,39 @@ +add('title') + ->add('description') + ->add('company', EntityType::class, [ + 'class' => Company::class, + 'choice_label' => 'id', + ]) + ->add('status', EntityType::class, [ + 'class' => Status::class, + 'choice_label' => 'id', + ]) + ->add('submit', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Announcement::class, + ]); + } +} diff --git a/src/Repository/FAQRepository.php b/src/Repository/FAQRepository.php new file mode 100644 index 0000000..228a85f --- /dev/null +++ b/src/Repository/FAQRepository.php @@ -0,0 +1,43 @@ + + */ +class FAQRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, FAQ::class); + } + + // /** + // * @return FAQ[] Returns an array of FAQ 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): ?FAQ + // { + // return $this->createQueryBuilder('f') + // ->andWhere('f.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/announcement/add.html.twig b/templates/announcement/add.html.twig new file mode 100644 index 0000000..6171d29 --- /dev/null +++ b/templates/announcement/add.html.twig @@ -0,0 +1,14 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AnnouncementController!{% endblock %} + +{% block body %} + + + {{ form(announcementForm) }} + + +{% endblock %} \ No newline at end of file diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig new file mode 100644 index 0000000..aca0c93 --- /dev/null +++ b/templates/announcement/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AnnouncementController!{% endblock %} + +{% block body %} + + +
+

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
  • +
+
+{% endblock %} diff --git a/templates/announcement/list.html.twig b/templates/announcement/list.html.twig new file mode 100644 index 0000000..d1d3c02 --- /dev/null +++ b/templates/announcement/list.html.twig @@ -0,0 +1,21 @@ +{% 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 }}

+ {% endfor %} + + +{% endblock %} \ No newline at end of file