<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ElTaskTagRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\ElasticUpdateInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Interfaces\ContainerMappedInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_OPERATOR')"},
* normalizationContext={"groups"={"ElTaskTag:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"ElTaskTag:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CO_OPR', object)"},
* "put"={"security"="is_granted('IS_CO_OPR', object)"},
* "patch"={"security"="is_granted('IS_CO_OPR', object)"},
* "delete"={"security"="is_granted('IS_CO_OPR', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"name": "partial", "container.id": "exact", "elTasks.id": "exact"})
* @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
* @ORM\Entity(repositoryClass=ElTaskTagRepository::class)
* @UniqueEntity(
* fields={"container", "name"},
* errorPath="name"
* )
*/
class ElTaskTag implements ContainerMappedInterface, ElasticUpdateInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"ElTaskTag:Read", "ElTask:Read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Groups({"ElTaskTag:Read", "ElTaskTag:Write", "ElTask:Read", "ElTask:Read-My", "ElTask:Write"})
*
* @Assert\NotBlank(message="validation.elCourseTag:name.notBlank")
* @Assert\Length(max=128, maxMessage="validation.elCourseTag:name.max")
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"ElTaskTag:Write", "ElTask:Write"})
*/
private $container;
/**
* @ORM\ManyToMany(targetEntity=ElTask::class, mappedBy="elTaskTags")
* @Groups({"ElTaskTag:Write"})
*/
private $elTasks;
public function __construct()
{
$this->elTasks = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
/**
* @return Collection|ElTask[]
*/
public function getElTasks(): Collection
{
return $this->elTasks;
}
public function addElTask(ElTask $elTask): self
{
if (!$this->elTasks->contains($elTask)) {
$this->elTasks[] = $elTask;
$elTask->addElTaskTag($this);
}
return $this;
}
public function removeElTask(ElTask $elTask): self
{
if ($this->elTasks->removeElement($elTask)) {
$elTask->removeElTaskTag($this);
}
return $this;
}
public function getQueueInfo(): array
{
return [
'type' => 'ElTaskTag',
'id' => $this->getId()
];
}
}