<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass:PageRepository ::class)]
class Page
{
//Déclarations des variables
#[ORM\Id]
#[ORM\Column(name: 'id_page',type: 'integer', nullable: false)]
//Spécifie que la valeur générée est un ID auto-incrémenté
#[ORM\GeneratedValue(strategy:'IDENTITY')]
private ?int $id;
#[ORM\Column(type: 'integer', nullable: false)]
private ?int $numero;
//Associations
#[ORM\ManyToOne(targetEntity: Classeur::class, fetch: "EAGER", inversedBy: 'pages',)]
#[ORM\JoinColumn(referencedColumnName: 'id_classeur', nullable: false)]
private ?Classeur $classeur = null;
#[ORM\ManyToMany(targetEntity: Model::class, mappedBy:'pages', orphanRemoval: true)]
private ?Collection $models;
//Constructeur
public function __construct()
{
$this->models = new ArrayCollection();
}
//Getters et Setters
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int|null $id
*/
public function setId(?int $id): void
{
$this->id = $id;
}
/**
* @return int|null
*/
public function getNumero(): ?int
{
return $this->numero;
}
/**
* @param int|null $numero
*/
public function setNumero(?int $numero): void
{
$this->numero = $numero;
}
/**
* @return Classeur|null
*/
public function getClasseur(): ?Classeur
{
return $this->classeur;
}
/**
* @param Classeur|null $classeur
*/
public function setClasseur(?Classeur $classeur): void
{
$this->classeur = $classeur;
}
//Fonctions des collections
/**
* @return Collection<int, Model>
*/
public function getModels(): Collection
{
return $this->models;
}
public function addModel(Model $model): self
{
if (!$this->models->contains($model)) {
$this->models->add($model);
$model->addPage($this);
}
return $this;
}
public function removeModel(Model $model): self
{
if ($this->models->removeElement($model)) {
// set the owning side to null (unless already changed)
if ($model->getPages() === $this) {
$model->addPage(null);
}
}
return $this;
}
}