src/Entity/CategorieProjet.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\CategorieProjetRepository;
  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\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. #[ORM\Entity(repositoryClass: CategorieProjetRepository::class)]
  13. #[UniqueEntity(
  14.     fields: ['title',],
  15.     errorPath: 'title',
  16.     message: 'Le nom que vous avez saisi est déjà utilisé',
  17. )]
  18. #[ORM\HasLifecycleCallbacks]
  19. class CategorieProjet
  20. {
  21.     use TimeStampable; 
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     #[Groups(["entity:write"])]
  26.     private ?int $id = null;
  27.     #[ORM\Column(length: 255)]
  28.     #[Groups(["entity:write"])]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?string $title = null;
  31.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  32.     #[Groups(["entity:write"])]
  33.     private ?string $description = null;
  34.     #[ORM\OneToMany(mappedBy: 'categorieProjet', targetEntity: Projet::class)]
  35.     private Collection $projets;
  36.     #[ORM\ManyToOne(inversedBy: 'categorieProjets')]
  37.     private ?User $createdBy = null;
  38.     public function __construct()
  39.     {
  40.         $this->projets = new ArrayCollection();
  41.         $this->isEnabled = false;
  42.         $this->createdAt = new \DateTimeImmutable();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getTitle(): ?string
  49.     {
  50.         return $this->title;
  51.     }
  52.     public function setTitle(string $title): self
  53.     {
  54.         $this->title = $title;
  55.         return $this;
  56.     }
  57.     public function getDescription(): ?string
  58.     {
  59.         return $this->description;
  60.     }
  61.     public function setDescription(string $description): self
  62.     {
  63.         $this->description = $description;
  64.         return $this;
  65.     }
  66.     /**
  67.      * @return Collection<int, Projet>
  68.      */
  69.     public function getProjets(): Collection
  70.     {
  71.         return $this->projets;
  72.     }
  73.     public function addProjet(Projet $projet): self
  74.     {
  75.         if (!$this->projets->contains($projet)) {
  76.             $this->projets->add($projet);
  77.             $projet->setCategorieProjet($this);
  78.         }
  79.         return $this;
  80.     }
  81.     public function removeProjet(Projet $projet): self
  82.     {
  83.         if ($this->projets->removeElement($projet)) {
  84.             // set the owning side to null (unless already changed)
  85.             if ($projet->getCategorieProjet() === $this) {
  86.                 $projet->setCategorieProjet(null);
  87.             }
  88.         }
  89.         return $this;
  90.     }
  91.     public function getCreatedBy(): ?User
  92.     {
  93.         return $this->createdBy;
  94.     }
  95.     public function setCreatedBy(?User $createdBy): static
  96.     {
  97.         $this->createdBy = $createdBy;
  98.         return $this;
  99.     }
  100.     
  101.     public function __toString()
  102.     {
  103.         return $this->title;
  104.     }
  105. }