connexion base et création premier crud
This commit is contained in:
81
src/Controller/ContributionController.php
Normal file
81
src/Controller/ContributionController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Contribution;
|
||||
use App\Form\ContributionType;
|
||||
use App\Repository\ContributionRepository;
|
||||
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('/contribution')]
|
||||
final class ContributionController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_contribution_index', methods: ['GET'])]
|
||||
public function index(ContributionRepository $contributionRepository): Response
|
||||
{
|
||||
return $this->render('contribution/index.html.twig', [
|
||||
'contributions' => $contributionRepository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_contribution_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$contribution = new Contribution();
|
||||
$form = $this->createForm(ContributionType::class, $contribution);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->persist($contribution);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_contribution_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('contribution/new.html.twig', [
|
||||
'contribution' => $contribution,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_contribution_show', methods: ['GET'])]
|
||||
public function show(Contribution $contribution): Response
|
||||
{
|
||||
return $this->render('contribution/show.html.twig', [
|
||||
'contribution' => $contribution,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_contribution_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, Contribution $contribution, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(ContributionType::class, $contribution);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_contribution_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('contribution/edit.html.twig', [
|
||||
'contribution' => $contribution,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_contribution_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, Contribution $contribution, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete'.$contribution->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$entityManager->remove($contribution);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_contribution_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Membre;
|
||||
use App\Form\MembreType;
|
||||
use App\Form\Membre2Type;
|
||||
use App\Repository\MembreRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -14,14 +15,10 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
final class MembreController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_membre_index', methods: ['GET'])]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
public function index(MembreRepository $membreRepository): Response
|
||||
{
|
||||
$membres = $entityManager
|
||||
->getRepository(Membre::class)
|
||||
->findAll();
|
||||
|
||||
return $this->render('membre/index.html.twig', [
|
||||
'membres' => $membres,
|
||||
'membres' => $membreRepository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -29,7 +26,7 @@ final class MembreController extends AbstractController
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$membre = new Membre();
|
||||
$form = $this->createForm(MembreType::class, $membre);
|
||||
$form = $this->createForm(Membre2Type::class, $membre);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@@ -56,7 +53,7 @@ final class MembreController extends AbstractController
|
||||
#[Route('/{id}/edit', name: 'app_membre_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, Membre $membre, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(MembreType::class, $membre);
|
||||
$form = $this->createForm(Membre2Type::class, $membre);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
84
src/Controller/ProjetController.php
Normal file
84
src/Controller/ProjetController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Projet;
|
||||
use App\Form\ProjetType;
|
||||
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('/projet')]
|
||||
final class ProjetController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_projet_index', methods: ['GET'])]
|
||||
public function index(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$projets = $entityManager
|
||||
->getRepository(Projet::class)
|
||||
->findAll();
|
||||
|
||||
return $this->render('projet/index.html.twig', [
|
||||
'projets' => $projets,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_projet_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$projet = new Projet();
|
||||
$form = $this->createForm(ProjetType::class, $projet);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->persist($projet);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_projet_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('projet/new.html.twig', [
|
||||
'projet' => $projet,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_projet_show', methods: ['GET'])]
|
||||
public function show(Projet $projet): Response
|
||||
{
|
||||
return $this->render('projet/show.html.twig', [
|
||||
'projet' => $projet,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_projet_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, Projet $projet, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(ProjetType::class, $projet);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_projet_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('projet/edit.html.twig', [
|
||||
'projet' => $projet,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_projet_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, Projet $projet, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete'.$projet->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$entityManager->remove($projet);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_projet_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
||||
65
src/Entity/Contribution.php
Normal file
65
src/Entity/Contribution.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ContributionRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ContributionRepository::class)]
|
||||
class Contribution
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Membre::class, inversedBy: 'contributions')]
|
||||
#[ORM\JoinColumn(name: 'membre_id', referencedColumnName: 'id', nullable: false)]
|
||||
private ?Membre $membre = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Projet::class)]
|
||||
#[ORM\JoinColumn(name: 'projet_id', referencedColumnName: 'id', nullable: false)]
|
||||
private ?Projet $projet = null;
|
||||
|
||||
#[ORM\Column(type: 'integer', options: ['default' => 0])]
|
||||
private ?int $duree = 0;
|
||||
|
||||
// Getters et Setters...
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMembre(): ?Membre
|
||||
{
|
||||
return $this->membre;
|
||||
}
|
||||
|
||||
public function setMembre(?Membre $membre): static
|
||||
{
|
||||
$this->membre = $membre;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProjet(): ?Projet
|
||||
{
|
||||
return $this->projet;
|
||||
}
|
||||
|
||||
public function setProjet(?Projet $projet): static
|
||||
{
|
||||
$this->projet = $projet;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDuree(): ?int
|
||||
{
|
||||
return $this->duree;
|
||||
}
|
||||
|
||||
public function setDuree(int $duree): static
|
||||
{
|
||||
$this->duree = $duree;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
// src/Entity/Droit.php
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: "Droit")]
|
||||
class Droit
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: "integer", name: "idDroit")]
|
||||
private ?int $idDroit = null;
|
||||
|
||||
#[ORM\Column(type: "string", length: 30, name: "LibDroit")]
|
||||
private ?string $libDroit = null;
|
||||
|
||||
// Getter et Setter
|
||||
public function getIdDroit(): ?int
|
||||
{
|
||||
return $this->idDroit;
|
||||
}
|
||||
|
||||
public function getLibDroit(): ?string
|
||||
{
|
||||
return $this->libDroit;
|
||||
}
|
||||
|
||||
public function setLibDroit(string $libDroit): self
|
||||
{
|
||||
$this->libDroit = $libDroit;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,71 @@
|
||||
<?php
|
||||
// src/Entity/Membre.php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\MembreRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: "Membre")]
|
||||
#[ORM\Table(name: "membre")]
|
||||
class Membre
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: "string", length: 20)]
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private ?string $id = null;
|
||||
|
||||
#[ORM\Column(type: "string", length: 50)]
|
||||
#[ORM\Column(type: 'string', length: 50)]
|
||||
private ?string $nom = null;
|
||||
|
||||
#[ORM\Column(type: "string", length: 100, nullable: true)]
|
||||
#[ORM\Column(type: 'string', length: 100)]
|
||||
private ?string $password = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Droit::class)]
|
||||
#[ORM\JoinColumn(name: "droit_id", referencedColumnName: "idDroit", nullable: true, onDelete: "SET NULL")]
|
||||
private ?Droit $droit = null;
|
||||
#[ORM\Column(type: 'string', length: 50, options: ['default' => 'dev'])]
|
||||
private ?string $droit = 'dev';
|
||||
|
||||
// Getters et setters
|
||||
public function getId(): ?string { return $this->id; }
|
||||
public function setId(string $id): self { $this->id = $id; return $this; }
|
||||
#[ORM\OneToMany(mappedBy: 'membre', targetEntity: Contribution::class)]
|
||||
private Collection $contributions;
|
||||
|
||||
public function getNom(): ?string { return $this->nom; }
|
||||
public function setNom(string $nom): self { $this->nom = $nom; return $this; }
|
||||
public function __construct()
|
||||
{
|
||||
$this->contributions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getPassword(): ?string { return $this->password; }
|
||||
public function setPassword(?string $password): self { $this->password = $password; return $this; }
|
||||
// Getters et Setters...
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDroit(): ?Droit { return $this->droit; }
|
||||
public function setDroit(?Droit $droit): self { $this->droit = $droit; return $this; }
|
||||
public function getNom(): ?string
|
||||
{
|
||||
return $this->nom;
|
||||
}
|
||||
|
||||
public function setNom(string $nom): static
|
||||
{
|
||||
$this->nom = $nom;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword(string $password): static
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDroit(): ?string
|
||||
{
|
||||
return $this->droit;
|
||||
}
|
||||
|
||||
public function setDroit(string $droit): static
|
||||
{
|
||||
$this->droit = $droit;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
35
src/Entity/Projet.php
Normal file
35
src/Entity/Projet.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ProjetRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: "projet")]
|
||||
class Projet
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private ?string $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 50)]
|
||||
private ?string $nom = null;
|
||||
|
||||
// Getters et Setters...
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNom(): ?string
|
||||
{
|
||||
return $this->nom;
|
||||
}
|
||||
|
||||
public function setNom(string $nom): static
|
||||
{
|
||||
$this->nom = $nom;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,26 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Droit;
|
||||
use App\Entity\Contribution;
|
||||
use App\Entity\Membre;
|
||||
use App\Entity\Projet;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class Membre1Type extends AbstractType
|
||||
class ContributionType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('id')
|
||||
->add('nom')
|
||||
->add('password')
|
||||
->add('droit', EntityType::class, [
|
||||
'class' => Droit::class,
|
||||
->add('duree')
|
||||
->add('membre', EntityType::class, [
|
||||
'class' => Membre::class,
|
||||
'choice_label' => 'id',
|
||||
])
|
||||
->add('projet', EntityType::class, [
|
||||
'class' => Projet::class,
|
||||
'choice_label' => 'id',
|
||||
])
|
||||
;
|
||||
@@ -27,7 +30,7 @@ class Membre1Type extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Membre::class,
|
||||
'data_class' => Contribution::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
45
src/Form/Membre2Type.php
Normal file
45
src/Form/Membre2Type.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Membre;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class Membre2Type extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('id')
|
||||
->add('nom')
|
||||
->add('plainPassword', PasswordType::class, [
|
||||
'label' => 'Mot de passe',
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'placeholder' => 'Saisir le mot de passe',
|
||||
],
|
||||
])
|
||||
->add('droit', ChoiceType::class, [
|
||||
'label' => 'Droit',
|
||||
'choices' => [
|
||||
'dev' => 'dev',
|
||||
'admin' => 'admin',
|
||||
],
|
||||
'placeholder' => 'Sélectionnez un droit',
|
||||
'required' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Membre::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Droit;
|
||||
use App\Entity\Membre;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MembreType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('id')
|
||||
->add('nom')
|
||||
->add('password')
|
||||
->add('droit', EntityType::class, [
|
||||
'class' => Droit::class,
|
||||
'choice_label' => 'id',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Membre::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,25 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Droit;
|
||||
use App\Entity\Projet;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DroitType extends AbstractType
|
||||
class ProjetType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('libDroit')
|
||||
->add('id')
|
||||
->add('nom')
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Droit::class,
|
||||
'data_class' => Projet::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user