Ajout relation élève atelier pour inscription

This commit is contained in:
Zakarya BENJABALLAH 2023-02-09 10:23:12 +01:00
parent 0a44ed4297
commit 6f208133e3
4 changed files with 114 additions and 9 deletions

View File

@ -78,4 +78,11 @@ symfony console d:f:l
Pas de commandes, juste du code dans AtelierController Pas de commandes, juste du code dans AtelierController
### Question 10 et 11 ### Question 10 et 11
Pas de commandes. Pas de commandes.
### Question 12
```bash
symfony console make:entity
symfony console make:migration
symfony console d:m:m
```

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230209092109 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE user_atelier (user_id INTEGER NOT NULL, atelier_id INTEGER NOT NULL, PRIMARY KEY(user_id, atelier_id), CONSTRAINT FK_B9B60629A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B9B6062982E2CF35 FOREIGN KEY (atelier_id) REFERENCES atelier (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_B9B60629A76ED395 ON user_atelier (user_id)');
$this->addSql('CREATE INDEX IDX_B9B6062982E2CF35 ON user_atelier (atelier_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE user_atelier');
}
}

View File

@ -3,6 +3,8 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\AtelierRepository; use App\Repository\AtelierRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AtelierRepository::class)] #[ORM\Entity(repositoryClass: AtelierRepository::class)]
@ -19,10 +21,18 @@ class Atelier
#[ORM\Column(length: 1024, nullable: true)] #[ORM\Column(length: 1024, nullable: true)]
private ?string $description = null; private ?string $description = null;
#[ORM\ManyToOne(inversedBy: 'ateliersFormÃÃÃes')] #[ORM\ManyToOne(inversedBy: 'ateliersForm<EFBFBD><EFBFBD><EFBFBD>es')]
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false)]
private ?User $instructeur = null; private ?User $instructeur = null;
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'formationsSuivies')]
private Collection $eleves;
public function __construct()
{
$this->eleves = new ArrayCollection();
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -63,4 +73,31 @@ class Atelier
return $this; return $this;
} }
/**
* @return Collection<int, User>
*/
public function getEleves(): Collection
{
return $this->eleves;
}
public function addEleve(User $eleve): self
{
if (!$this->eleves->contains($eleve)) {
$this->eleves->add($eleve);
$eleve->addFormationsSuivie($this);
}
return $this;
}
public function removeEleve(User $eleve): self
{
if ($this->eleves->removeElement($eleve)) {
$eleve->removeFormationsSuivie($this);
}
return $this;
}
} }

View File

@ -38,11 +38,15 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?string $prenom = null; private ?string $prenom = null;
#[ORM\OneToMany(mappedBy: 'instructeur', targetEntity: Atelier::class, orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'instructeur', targetEntity: Atelier::class, orphanRemoval: true)]
private Collection $ateliersFormÃÃÃes; private Collection $ateliersForm<72><6D><EFBFBD>es;
#[ORM\ManyToMany(targetEntity: atelier::class, inversedBy: 'eleves')]
private Collection $formationsSuivies;
public function __construct() public function __construct()
{ {
$this->ateliersFormÃÃÃes = new ArrayCollection(); $this->ateliersForm<EFBFBD><EFBFBD><EFBFBD>es = new ArrayCollection();
$this->formationsSuivies = new ArrayCollection();
} }
public function getId(): ?int public function getId(): ?int
@ -143,15 +147,15 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
/** /**
* @return Collection<int, Atelier> * @return Collection<int, Atelier>
*/ */
public function getAteliersFormÃÃÃes(): Collection public function getAteliersForm<EFBFBD><EFBFBD><EFBFBD>es(): Collection
{ {
return $this->ateliersFormÃÃÃes; return $this->ateliersForm<EFBFBD><EFBFBD><EFBFBD>es;
} }
public function addAteliersFormE(Atelier $ateliersFormE): self public function addAteliersFormE(Atelier $ateliersFormE): self
{ {
if (!$this->ateliersFormÃÃÃes->contains($ateliersFormE)) { if (!$this->ateliersForm<EFBFBD><EFBFBD><EFBFBD>es->contains($ateliersFormE)) {
$this->ateliersFormÃÃÃes->add($ateliersFormE); $this->ateliersForm<EFBFBD><EFBFBD><EFBFBD>es->add($ateliersFormE);
$ateliersFormE->setInstructeur($this); $ateliersFormE->setInstructeur($this);
} }
@ -160,7 +164,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
public function removeAteliersFormE(Atelier $ateliersFormE): self public function removeAteliersFormE(Atelier $ateliersFormE): self
{ {
if ($this->ateliersFormÃÃÃes->removeElement($ateliersFormE)) { if ($this->ateliersForm<EFBFBD><EFBFBD><EFBFBD>es->removeElement($ateliersFormE)) {
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($ateliersFormE->getInstructeur() === $this) { if ($ateliersFormE->getInstructeur() === $this) {
$ateliersFormE->setInstructeur(null); $ateliersFormE->setInstructeur(null);
@ -169,4 +173,28 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this; return $this;
} }
/**
* @return Collection<int, atelier>
*/
public function getFormationsSuivies(): Collection
{
return $this->formationsSuivies;
}
public function addFormationsSuivie(atelier $formationsSuivie): self
{
if (!$this->formationsSuivies->contains($formationsSuivie)) {
$this->formationsSuivies->add($formationsSuivie);
}
return $this;
}
public function removeFormationsSuivie(atelier $formationsSuivie): self
{
$this->formationsSuivies->removeElement($formationsSuivie);
return $this;
}
} }