src/Entity/Page.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PageRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass:PageRepository ::class)]
  8. class Page
  9. {
  10.     //Déclarations des variables
  11.     #[ORM\Id]
  12.     #[ORM\Column(name'id_page',type'integer'nullablefalse)]
  13.     //Spécifie que la valeur générée est un ID auto-incrémenté
  14.     #[ORM\GeneratedValue(strategy:'IDENTITY')]
  15.     private ?int $id;
  16.     #[ORM\Column(type'integer'nullablefalse)]
  17.     private ?int $numero;
  18.     //Associations
  19.     #[ORM\ManyToOne(targetEntityClasseur::class, fetch"EAGER"inversedBy'pages',)]
  20.     #[ORM\JoinColumn(referencedColumnName'id_classeur'nullablefalse)]
  21.     private ?Classeur $classeur null;
  22.     #[ORM\ManyToMany(targetEntityModel::class, mappedBy:'pages'orphanRemovaltrue)]
  23.     private ?Collection $models;
  24.     //Constructeur
  25.     public function __construct()
  26.     {
  27.         $this->models = new ArrayCollection();
  28.     }
  29.     //Getters et Setters
  30.     /**
  31.      * @return int|null
  32.      */
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     /**
  38.      * @param int|null $id
  39.      */
  40.     public function setId(?int $id): void
  41.     {
  42.         $this->id $id;
  43.     }
  44.     /**
  45.      * @return int|null
  46.      */
  47.     public function getNumero(): ?int
  48.     {
  49.         return $this->numero;
  50.     }
  51.     /**
  52.      * @param int|null $numero
  53.      */
  54.     public function setNumero(?int $numero): void
  55.     {
  56.         $this->numero $numero;
  57.     }
  58.     /**
  59.      * @return Classeur|null
  60.      */
  61.     public function getClasseur(): ?Classeur
  62.     {
  63.         return $this->classeur;
  64.     }
  65.     /**
  66.      * @param Classeur|null $classeur
  67.      */
  68.     public function setClasseur(?Classeur $classeur): void
  69.     {
  70.         $this->classeur $classeur;
  71.     }
  72.     //Fonctions des collections
  73.     /**
  74.      * @return Collection<int, Model>
  75.      */
  76.     public function getModels(): Collection
  77.     {
  78.         return $this->models;
  79.     }
  80.     public function addModel(Model $model): self
  81.     {
  82.         if (!$this->models->contains($model)) {
  83.             $this->models->add($model);
  84.             $model->addPage($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeModel(Model $model): self
  89.     {
  90.         if ($this->models->removeElement($model)) {
  91.             // set the owning side to null (unless already changed)
  92.             if ($model->getPages() === $this) {
  93.                 $model->addPage(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98. }