Commit 1bf05123 authored by Anthony Gautreau's avatar Anthony Gautreau
Browse files

POC fonctionnel

parent 65c0fd14
Loading
Loading
Loading
Loading
+21 −2
Changes for src/Entity/Parametre.php: 21 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,11 +3,16 @@
namespace Unicaen\Parametre\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\OpenApi\Model\Operation;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'unicaen_parametre')]
#[ApiResource]
#[ORM\Table(name: 'unicaen_parametre_parametre')]
#[ApiResource(
    openapi: new Operation(
        tags: ['unicaen_parametre Parametres'],
    )
)]
class Parametre
{
    #[ORM\Id]
@@ -39,6 +44,10 @@ class Parametre
    #[ORM\Column(type: 'boolean')]
    private bool $affichable = true;

    #[ORM\ManyToOne(targetEntity: ParametreCategorie::class, inversedBy: 'parametres')]
    #[ORM\JoinColumn(name: 'categorie_id', referencedColumnName: 'id')]
    private ?ParametreCategorie $categorie = null;

    public function getId(): ?int
    {
        return $this->id;
@@ -139,4 +148,14 @@ class Parametre

        return $this;
    }

    public function getCategorie(): ?ParametreCategorie
    {
        return $this->categorie;
    }

    public function setCategorie(?ParametreCategorie $categorie): void
    {
        $this->categorie = $categorie;
    }
}
+36 −3
Changes for src/Entity/ParametreCategorie.php: 36 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -3,13 +3,19 @@
namespace Unicaen\Parametre\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\OpenApi\Model\Operation;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'unicaen_parametre_categorie')]
#[ApiResource]
class CategorieParametre
#[ApiResource(
    shortName: 'parametre-categories',
    openapi: new Operation(
        tags: ['unicaen_parametre Categorie'],
    )
)]
class ParametreCategorie
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
@@ -28,7 +34,7 @@ class CategorieParametre
    #[ORM\Column(type: 'integer')]
    private ?int $ordre;

    #[ORM\OneToMany(targetEntity: Parametre::class, mappedBy: 'categorie')]
    #[ORM\OneToMany(targetEntity: Parametre::class, mappedBy: 'categorie', cascade: ['remove'], orphanRemoval: true)]
    private Collection $parametres;

    public function getId(): ?int
@@ -83,4 +89,31 @@ class CategorieParametre

        return $this;
    }

    public function getParametres(): Collection
    {
        return $this->parametres;
    }

    public function addParametre(Parametre $parametre): static
    {
        if (!$this->parametres->contains($parametre)) {
            $this->parametres[] = $parametre;
            $parametre->setCategorie($this);
        }

        return $this;
    }

    public function removeParametre(Parametre $parametre): static
    {
        if ($this->parametres->removeElement($parametre)) {
            // set the owning side to null (unless already changed)
            if ($parametre->getCategorie() === $this) {
                $parametre->setCategorie(null);
            }
        }

        return $this;
    }
}