src/Entity/TypeObjectif.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\TypeObjectifRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClass: TypeObjectifRepository::class)]
  13. #[UniqueEntity(
  14.     fields: ['code',],
  15.     errorPath: 'code',
  16.     message: 'Le code déjà utilisée',
  17. )]
  18. #[UniqueEntity(
  19.     fields: ['name',],
  20.     errorPath: 'name',
  21.     message: 'Le nom que vous avez saisi est déjà utilisé',
  22. )]
  23. #[ORM\HasLifecycleCallbacks]
  24. class TypeObjectif
  25. {
  26.     use TimeStampable;
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30.     #[Groups(["entity:write", "objectif:read"])]
  31.     private ?int $id = null;
  32.     #[ORM\Column(length: 255)]
  33.     #[Groups(["entity:write", "objectif:read"])]
  34.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  35.     private ?string $code = null;
  36.     #[ORM\Column(length: 255)]
  37.     #[Groups(["entity:write", "objectif:read"])]
  38.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  39.     private ?string $name = null;
  40.     #[ORM\Column(type: Types::TEXT)]
  41.     #[Groups(["entity:write", "objectif:read"])]
  42.     private ?string $description = null;
  43.     #[ORM\OneToMany(mappedBy: 'typeObjectif', targetEntity: Objectif::class)]
  44.     private Collection $objectifs;
  45.     public function __construct()
  46.     {
  47.         $this->createdAt = new \DateTimeImmutable();
  48.         $this->objectifs = new ArrayCollection();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getName(): ?string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setName(string $name): static
  59.     {
  60.         $this->name = $name;
  61.         return $this;
  62.     }
  63.     public function getDescription(): ?string
  64.     {
  65.         return $this->description;
  66.     }
  67.     public function setDescription(string $description): static
  68.     {
  69.         $this->description = $description;
  70.         return $this;
  71.     }
  72.     public function getCode(): ?string
  73.     {
  74.         return $this->code;
  75.     }
  76.     public function setCode(string $code): static
  77.     {
  78.         $this->code = $code;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection<int, Objectif>
  83.      */
  84.     public function getObjectifs(): Collection
  85.     {
  86.         return $this->objectifs;
  87.     }
  88.     public function addObjectif(Objectif $objectif): static
  89.     {
  90.         if (!$this->objectifs->contains($objectif)) {
  91.             $this->objectifs->add($objectif);
  92.             $objectif->setTypeObjectif($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeObjectif(Objectif $objectif): static
  97.     {
  98.         if ($this->objectifs->removeElement($objectif)) {
  99.             // set the owning side to null (unless already changed)
  100.             if ($objectif->getTypeObjectif() === $this) {
  101.                 $objectif->setTypeObjectif(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106.     public function __toString(): string
  107.     {
  108.         return $this->name;
  109.     }
  110. }