<?php
namespace App\Entity;
use App\Entity\Traits\TimeStampable;
use App\Repository\TypeObjectifRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: TypeObjectifRepository::class)]
#[UniqueEntity(
fields: ['code',],
errorPath: 'code',
message: 'Le code déjà utilisée',
)]
#[UniqueEntity(
fields: ['name',],
errorPath: 'name',
message: 'Le nom que vous avez saisi est déjà utilisé',
)]
#[ORM\HasLifecycleCallbacks]
class TypeObjectif
{
use TimeStampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["entity:write", "objectif:read"])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(["entity:write", "objectif:read"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $code = null;
#[ORM\Column(length: 255)]
#[Groups(["entity:write", "objectif:read"])]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT)]
#[Groups(["entity:write", "objectif:read"])]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'typeObjectif', targetEntity: Objectif::class)]
private Collection $objectifs;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->objectifs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, Objectif>
*/
public function getObjectifs(): Collection
{
return $this->objectifs;
}
public function addObjectif(Objectif $objectif): static
{
if (!$this->objectifs->contains($objectif)) {
$this->objectifs->add($objectif);
$objectif->setTypeObjectif($this);
}
return $this;
}
public function removeObjectif(Objectif $objectif): static
{
if ($this->objectifs->removeElement($objectif)) {
// set the owning side to null (unless already changed)
if ($objectif->getTypeObjectif() === $this) {
$objectif->setTypeObjectif(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name;
}
}