ajout FAQ + premiers controller / vues / formulaire pour annonce
This commit is contained in:
parent
2818279438
commit
a65eb73b81
84
src/Controller/AnnouncementController.php
Normal file
84
src/Controller/AnnouncementController.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Announcement;
|
||||||
|
use App\Form\AnnouncementType;
|
||||||
|
use App\Repository\AnnouncementRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly AnnouncementRepository $announcementRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#[Route('/add', name: '_add')]
|
||||||
|
public function addAnnouncement(Request $request): 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é
|
||||||
|
$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');
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ namespace App\Entity;
|
|||||||
use App\Repository\AnnouncementRepository;
|
use App\Repository\AnnouncementRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: AnnouncementRepository::class)]
|
#[ORM\Entity(repositoryClass: AnnouncementRepository::class)]
|
||||||
@ -30,16 +31,19 @@ class Announcement
|
|||||||
private ?Status $status = null;
|
private ?Status $status = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, InternApplication>
|
* @var ?Collection<int, InternApplication>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'application')]
|
#[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'application')]
|
||||||
private Collection $applicants;
|
private ?Collection $applicants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, InternFavorite>
|
* @var ?Collection<int, InternFavorite>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'announcement')]
|
#[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()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -159,4 +163,16 @@ class Announcement
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreationDate(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreationDate(\DateTimeInterface $creationDate): static
|
||||||
|
{
|
||||||
|
$this->creationDate = $creationDate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
66
src/Entity/FAQ.php
Normal file
66
src/Entity/FAQ.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\FAQRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: FAQRepository::class)]
|
||||||
|
class FAQ
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::TEXT)]
|
||||||
|
private ?string $question = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||||
|
private ?string $answer = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||||
|
private ?\DateTimeInterface $updateDate = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity;
|
|
||||||
|
|
||||||
use App\Repository\ObtainingRepository;
|
|
||||||
use Doctrine\DBAL\Types\Types;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: ObtainingRepository::class)]
|
|
||||||
class Obtaining
|
|
||||||
{
|
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\GeneratedValue]
|
|
||||||
#[ORM\Column]
|
|
||||||
private ?int $id = null;
|
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
|
||||||
private ?\DateTimeInterface $date = null;
|
|
||||||
|
|
||||||
public function getId(): ?int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDate(): ?\DateTimeInterface
|
|
||||||
{
|
|
||||||
return $this->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDate(\DateTimeInterface $date): static
|
|
||||||
{
|
|
||||||
$this->date = $date;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
39
src/Form/AnnouncementType.php
Normal file
39
src/Form/AnnouncementType.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Announcement;
|
||||||
|
use App\Entity\Company;
|
||||||
|
use App\Entity\Status;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class AnnouncementType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
43
src/Repository/FAQRepository.php
Normal file
43
src/Repository/FAQRepository.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\FAQ;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<FAQ>
|
||||||
|
*/
|
||||||
|
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()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
14
templates/announcement/add.html.twig
Normal file
14
templates/announcement/add.html.twig
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Hello AnnouncementController!{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<style>
|
||||||
|
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||||
|
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{{ form(announcementForm) }}
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
20
templates/announcement/index.html.twig
Normal file
20
templates/announcement/index.html.twig
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Hello AnnouncementController!{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<style>
|
||||||
|
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||||
|
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="example-wrapper">
|
||||||
|
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||||
|
|
||||||
|
This friendly message is coming from:
|
||||||
|
<ul>
|
||||||
|
<li>Your controller at <code>C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/src/Controller/AnnouncementController.php</code></li>
|
||||||
|
<li>Your template at <code>C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/templates/announcement/index.html.twig</code></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
21
templates/announcement/list.html.twig
Normal file
21
templates/announcement/list.html.twig
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Bienvenue sur Hegreshpere{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<style>
|
||||||
|
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||||
|
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h1> Liste des annonces</h1>
|
||||||
|
{% for ann in announcements %}
|
||||||
|
<h2> {{ ann.title }} </h2>
|
||||||
|
<h3> {{ ann.company.name }} </h3>
|
||||||
|
<p> {{ ann.description }} </p>
|
||||||
|
|
||||||
|
<p> {{ ann.creationDate }} </p>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user