src/Entity/Evenement.php line 36

  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use App\Entity\Child;
  5. use App\Entity\Employee;
  6. use App\Entity\enums\EventCategory;
  7. use Symfony\Component\Uid\Ulid;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Repository\EvenementRepository;
  10. use Doctrine\Common\Collections\Collection;
  11. use ApiPlatform\Core\Annotation\ApiResource;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. #[ORM\Entity(repositoryClassEvenementRepository::class)]
  17. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  18. #[ORM\HasLifecycleCallbacks()]
  19. #[ApiResource(
  20.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  21.     itemOperations: [
  22.         'get' => [
  23.             'normalization_context' => [
  24.                 'groups' => [
  25.                     'read:evenement:basic',
  26.                     'read:employee:basic',
  27.                     'read:child:basic'
  28.                 ]
  29.             ]
  30.         ],
  31.     ],
  32. )]
  33. class Evenement
  34. {
  35.     use Timestamps;
  36.     #[ORM\Id]
  37.     #[ORM\Column(type'ulid'uniquetrue)]
  38.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  39.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  40.     #[Groups('read:evenement:basic')]
  41.     private ?Ulid $id null;
  42.     #[ORM\Column(type'string'length255)]
  43.     #[Groups('read:evenement:basic')]
  44.     private $name;
  45.     #[ORM\Column(type'text'nullabletrue)]
  46.     #[Groups('read:evenement:basic')]
  47.     private $description;
  48.     #[ORM\Column(type'date')]
  49.     #[Groups('read:evenement:basic')]
  50.     private $date;
  51.     #[ORM\Column(type'string'length255enumTypeEventCategory::class)]
  52.     #[Groups('read:evenement:basic')]
  53.     private $type;
  54.     #[ORM\Column(type'string'length255nullabletrue)]
  55.     #[Groups('read:evenement:basic')]
  56.     private $tags;
  57.     #[ORM\ManyToMany(targetEntityChild::class, inversedBy'evenements')]
  58.     #[Groups('read:evenement:basic')]
  59.     private $children;
  60.     #[ORM\ManyToMany(targetEntityEmployee::class, inversedBy'evenements')]
  61.     #[Groups('read:evenement:basic')]
  62.     private $employees;
  63.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'evenements')]
  64.     #[ORM\JoinColumn(nullablefalse)]
  65.     private $owner;
  66.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'evenements')]
  67.     #[ORM\JoinColumn(nullablefalse)]
  68.     private $season;
  69.     public function __construct()
  70.     {
  71.         $this->children = new ArrayCollection();
  72.         $this->employees = new ArrayCollection();
  73.         $this->date = new DateTime();
  74.     }
  75.     public function __toString()
  76.     {
  77.         return $this->name;
  78.     }
  79.     public function getId(): ?Ulid
  80.     {
  81.         return $this->id;
  82.     }
  83.     public function getName(): ?string
  84.     {
  85.         return $this->name;
  86.     }
  87.     public function setName(string $name): self
  88.     {
  89.         $this->name $name;
  90.         return $this;
  91.     }
  92.     public function getDescription(): ?string
  93.     {
  94.         return $this->description;
  95.     }
  96.     public function setDescription(?string $description): self
  97.     {
  98.         $this->description $description;
  99.         return $this;
  100.     }
  101.     public function getDate(): ?\DateTimeInterface
  102.     {
  103.         return $this->date;
  104.     }
  105.     public function setDate(\DateTimeInterface $date): self
  106.     {
  107.         $this->date $date;
  108.         return $this;
  109.     }
  110.     public function getType(): ?EventCategory
  111.     {
  112.         return $this->type;
  113.     }
  114.     public function setType(EventCategory $type): self
  115.     {
  116.         $this->type $type;
  117.         return $this;
  118.     }
  119.     public function getTags(): ?string
  120.     {
  121.         return $this->tags;
  122.     }
  123.     public function setTags(?string $tags): self
  124.     {
  125.         $this->tags $tags;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, Child>
  130.      */
  131.     public function getChildren(): Collection
  132.     {
  133.         return $this->children;
  134.     }
  135.     public function addChild(Child $child): self
  136.     {
  137.         if (!$this->children->contains($child)) {
  138.             $this->children[] = $child;
  139.         }
  140.         return $this;
  141.     }
  142.     public function removeChild(Child $child): self
  143.     {
  144.         $this->children->removeElement($child);
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, Employee>
  149.      */
  150.     public function getEmployees(): Collection
  151.     {
  152.         return $this->employees;
  153.     }
  154.     public function addEmployee(Employee $employee): self
  155.     {
  156.         if (!$this->employees->contains($employee)) {
  157.             $this->employees[] = $employee;
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeEmployee(Employee $employee): self
  162.     {
  163.         $this->employees->removeElement($employee);
  164.         return $this;
  165.     }
  166.     public function getOwner(): ?Company
  167.     {
  168.         return $this->owner;
  169.     }
  170.     public function setOwner(?Company $owner): self
  171.     {
  172.         $this->owner $owner;
  173.         return $this;
  174.     }
  175.     public function getSeason(): ?Season
  176.     {
  177.         return $this->season;
  178.     }
  179.     public function setSeason(?Season $season): self
  180.     {
  181.         $this->season $season;
  182.         return $this;
  183.     }
  184. }