src/Entity/Task.php line 39
<?php
namespace App\Entity;
use DateTime;
use App\Entity\Child;
use App\Entity\Company;
use App\Entity\Employee;
use App\Entity\enums\TaskStatus;
use App\Entity\Timestamps;
use App\Entity\enums\TaskPriority;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\TaskRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: TaskRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
itemOperations: [
'get' => [
'normalization_context' => [
'groups' => [
'read:task:basic',
'read:employee:basic',
'read:child:basic'
]
]
],
],
)]
class Task
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:task:basic'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:task:basic'])]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:task:basic'])]
private $description;
#[ORM\Column(type: 'date')]
#[Groups(['read:task:basic'])]
private $date;
#[ORM\Column(type: 'string', length: 255, enumType: TaskStatus::class)]
#[Groups(['read:task:basic'])]
private $status;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:task:basic'])]
private $tags;
#[ORM\Column(type: 'string', length: 255, enumType: TaskPriority::class)]
#[Groups(['read:task:basic'])]
private $priority;
#[ORM\ManyToMany(targetEntity: Child::class, inversedBy: 'tasks')]
#[Groups(['read:task:basic'])]
private $children;
#[ORM\ManyToMany(targetEntity: Employee::class, inversedBy: 'tasks')]
#[Groups(['read:task:basic'])]
private $employees;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'tasks')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\ManyToOne(targetEntity: Season::class, inversedBy: 'tasks')]
#[ORM\JoinColumn(nullable: false)]
private $season;
public function __construct()
{
$this->children = new ArrayCollection();
$this->employees = new ArrayCollection();
$this->date = new DateTime();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getStatus(): ?TaskStatus
{
return $this->status;
}
public function setStatus(TaskStatus $status): self
{
$this->status = $status;
return $this;
}
public function getTags(): ?string
{
return $this->tags;
}
public function setTags(?string $tags): self
{
$this->tags = $tags;
return $this;
}
public function getPriority(): ?TaskPriority
{
return $this->priority;
}
public function setPriority(TaskPriority $priority): self
{
$this->priority = $priority;
return $this;
}
/**
* @return Collection<int, Child>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Child $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
}
return $this;
}
public function removeChild(Child $child): self
{
$this->children->removeElement($child);
return $this;
}
/**
* @return Collection<int, Employee>
*/
public function getEmployees(): Collection
{
return $this->employees;
}
public function addEmployee(Employee $employee): self
{
if (!$this->employees->contains($employee)) {
$this->employees[] = $employee;
}
return $this;
}
public function removeEmployee(Employee $employee): self
{
$this->employees->removeElement($employee);
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
}