src/Entity/MeetingCategory.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\MeetingCategoryRepository;
  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\Validator\Constraints as Assert;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClass: MeetingCategoryRepository::class)]
  13. #[UniqueEntity(
  14.     fields: ['name',],
  15.     errorPath: 'name',
  16.     message: 'Le nom que vous avez saisi est déjà utilisé',
  17. )]
  18. #[ORM\HasLifecycleCallbacks]
  19. class MeetingCategory
  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: 65)]
  28.     #[Groups(["entity:write"])]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?string $name = null;
  31.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  32.     #[Groups(["entity:write"])]
  33.     private ?string $description = null;    
  34.     #[ORM\ManyToOne]
  35.     private ?User $createdBy = null;
  36.     #[ORM\Column(length: 16, nullable: true)]
  37.     #[Groups(["entity:write"])]
  38.     private ?string $code = null;
  39.     #[ORM\OneToMany(mappedBy: 'meetingCategories', targetEntity: Meeting::class)]
  40.     private Collection $meetings;
  41.     public function __construct()
  42.     {
  43.         $this->createdAt = new \DateTimeImmutable();
  44.         $this->updatedAt = new \DateTimeImmutable();
  45.         $this->meetings = new ArrayCollection();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getName(): ?string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setName(string $name): self
  56.     {
  57.         $this->name = $name;
  58.         return $this;
  59.     }
  60.     public function getDescription(): ?string
  61.     {
  62.         return $this->description;
  63.     }
  64.     public function setDescription(?string $description): self
  65.     {
  66.         $this->description = $description;
  67.         return $this;
  68.     }
  69.     public function setCreatedBy(?User $createdBy): self
  70.     {
  71.         $this->createdBy = $createdBy;
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function getCode(): ?string
  79.     {
  80.         return $this->code;
  81.     }
  82.     public function setCode(?string $code): self
  83.     {
  84.         $this->code = $code;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return Collection<int, Meeting>
  89.      */
  90.     public function getMeetings(): Collection
  91.     {
  92.         return $this->meetings;
  93.     }
  94.     public function addMeeting(Meeting $meeting): self
  95.     {
  96.         if (!$this->meetings->contains($meeting)) {
  97.             $this->meetings->add($meeting);
  98.             $meeting->setMeetingCategories($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeMeeting(Meeting $meeting): self
  103.     {
  104.         if ($this->meetings->removeElement($meeting)) {
  105.             // set the owning side to null (unless already changed)
  106.             if ($meeting->getMeetingCategories() === $this) {
  107.                 $meeting->setMeetingCategories(null);
  108.             }
  109.         }
  110.         return $this;
  111.     }
  112. }