src/Entity/Task.php line 39

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