src/Entity/DocumentType.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\DocumentTypeRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  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: DocumentTypeRepository::class)]
  13. #[UniqueEntity(
  14.     fields: ['label',],
  15.     errorPath: 'label',
  16.     message: 'Le nom que vous avez saisi est déjà utilisé',
  17. )]
  18. #[ORM\HasLifecycleCallbacks]
  19. class DocumentType
  20. {
  21.     use TimeStampable;
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     #[Groups(["entity:write", "documentProjet:read","documentType:read"])]
  26.     private ?int $id = null;
  27.     #[ORM\Column(length: 255)]
  28.     #[Groups(["entity:write", "documentProjet:read", "documentType:read"])]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?string $label = null;
  31.     #[ORM\Column(length: 100)]
  32.     #[Groups(["entity:write", "documentType:read"])]
  33.     private ?string $category = null;
  34.     #[ORM\ManyToOne]
  35.     private ?User $createdBy = null;
  36.     #[ORM\OneToMany(mappedBy: 'typeDocument', targetEntity: Document::class)]
  37.     private Collection $documents;
  38.     public function __construct()
  39.     {
  40.         $this->createdAt = new DateTimeImmutable();
  41.         $this->updatedAt = new DateTimeImmutable();
  42.         $this->documents = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getLabel(): ?string
  49.     {
  50.         return $this->label;
  51.     }
  52.     public function setLabel(string $label): self
  53.     {
  54.         $this->label = $label;
  55.         return $this;
  56.     }
  57.     public function getCategory(): ?string
  58.     {
  59.         return $this->category;
  60.     }
  61.     public function setCategory(string $category): self
  62.     {
  63.         $this->category = $category;
  64.         return $this;
  65.     }
  66.     public function getCreatedBy(): ?User
  67.     {
  68.         return $this->createdBy;
  69.     }
  70.     public function setCreatedBy(?User $createdBy): self
  71.     {
  72.         $this->createdBy = $createdBy;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return Collection<int, Document>
  77.      */
  78.     public function getDocuments(): Collection
  79.     {
  80.         return $this->documents;
  81.     }
  82.     public function addDocument(Document $document): static
  83.     {
  84.         if (!$this->documents->contains($document)) {
  85.             $this->documents->add($document);
  86.             $document->setTypeDocument($this);
  87.         }
  88.         return $this;
  89.     }
  90.     public function removeDocument(Document $document): static
  91.     {
  92.         if ($this->documents->removeElement($document)) {
  93.             // set the owning side to null (unless already changed)
  94.             if ($document->getTypeDocument() === $this) {
  95.                 $document->setTypeDocument(null);
  96.             }
  97.         }
  98.         return $this;
  99.     }
  100.     public function __toString(): string
  101.     {
  102.         return $this->label;
  103.     }
  104.  
  105.   
  106. }