diff --git a/.env b/.env index 3666c82..128d6e1 100644 --- a/.env +++ b/.env @@ -32,7 +32,7 @@ DEFAULT_URI=http://localhost # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" -DATABASE_URL="mysql://contrib_root:123abc@127.0.0.1:3306/contrib?serverVersion=8.0.32&charset=utf8mb4" +DATABASE_URL="mysql://contribA_root:123abc@127.0.0.1:3306/contribC?serverVersion=8.0.32&charset=utf8mb4" ###< doctrine/doctrine-bundle ### ###> symfony/messenger ### # Choose one of the transports below diff --git a/src/Controller/ContributionController.php b/src/Controller/ContributionController.php new file mode 100644 index 0000000..d8b9e8c --- /dev/null +++ b/src/Controller/ContributionController.php @@ -0,0 +1,81 @@ +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); + } +} diff --git a/src/Controller/MembreController.php b/src/Controller/MembreController.php index c16957c..8eca2f2 100644 --- a/src/Controller/MembreController.php +++ b/src/Controller/MembreController.php @@ -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()) { diff --git a/src/Controller/ProjetController.php b/src/Controller/ProjetController.php new file mode 100644 index 0000000..c7e01c3 --- /dev/null +++ b/src/Controller/ProjetController.php @@ -0,0 +1,84 @@ +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); + } +} diff --git a/src/Entity/Contribution.php b/src/Entity/Contribution.php new file mode 100644 index 0000000..56617e3 --- /dev/null +++ b/src/Entity/Contribution.php @@ -0,0 +1,65 @@ + 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; + } +} diff --git a/src/Entity/Droit.php b/src/Entity/Droit.php deleted file mode 100644 index 5640667..0000000 --- a/src/Entity/Droit.php +++ /dev/null @@ -1,35 +0,0 @@ -idDroit; - } - - public function getLibDroit(): ?string - { - return $this->libDroit; - } - - public function setLibDroit(string $libDroit): self - { - $this->libDroit = $libDroit; - return $this; - } -} diff --git a/src/Entity/Membre.php b/src/Entity/Membre.php index f862d59..0303821 100644 --- a/src/Entity/Membre.php +++ b/src/Entity/Membre.php @@ -1,37 +1,71 @@ '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; + } } diff --git a/src/Entity/Projet.php b/src/Entity/Projet.php new file mode 100644 index 0000000..d27ef0a --- /dev/null +++ b/src/Entity/Projet.php @@ -0,0 +1,35 @@ +id; + } + + public function getNom(): ?string + { + return $this->nom; + } + + public function setNom(string $nom): static + { + $this->nom = $nom; + return $this; + } +} diff --git a/src/Form/Membre1Type.php b/src/Form/ContributionType.php similarity index 57% rename from src/Form/Membre1Type.php rename to src/Form/ContributionType.php index 0bd8d45..7143db3 100644 --- a/src/Form/Membre1Type.php +++ b/src/Form/ContributionType.php @@ -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, ]); } } diff --git a/src/Form/Membre2Type.php b/src/Form/Membre2Type.php new file mode 100644 index 0000000..42df1e6 --- /dev/null +++ b/src/Form/Membre2Type.php @@ -0,0 +1,45 @@ +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, + ]); + } +} diff --git a/src/Form/MembreType.php b/src/Form/MembreType.php deleted file mode 100644 index 650d9fd..0000000 --- a/src/Form/MembreType.php +++ /dev/null @@ -1,33 +0,0 @@ -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, - ]); - } -} diff --git a/src/Form/DroitType.php b/src/Form/ProjetType.php similarity index 73% rename from src/Form/DroitType.php rename to src/Form/ProjetType.php index b683c94..c7f27f0 100644 --- a/src/Form/DroitType.php +++ b/src/Form/ProjetType.php @@ -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, ]); } } diff --git a/templates/_bootstrap.html.twig b/templates/_bootstrap.html.twig new file mode 100644 index 0000000..1eb3e62 --- /dev/null +++ b/templates/_bootstrap.html.twig @@ -0,0 +1,13 @@ +{# + Shared partial to include Bootstrap. Use with: + {{ include('_bootstrap.html.twig', { part: 'css' }) }} in the
+ {{ include('_bootstrap.html.twig', { part: 'js' }) }} before closing +#} + +{% if part == 'css' %} + +{% elseif part == 'js' %} + +{% endif %} + + diff --git a/templates/base.html.twig b/templates/base.html.twig index 3cda30f..be2ad1b 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -5,13 +5,17 @@