src/Entity/ElTaskTag.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\ElTaskTagRepository;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use App\Entity\Traits\TimestampableEntity;
  7. use Doctrine\Common\Collections\Collection;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use App\Entity\Interfaces\ElasticUpdateInterface;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use App\Entity\Interfaces\ContainerMappedInterface;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * @ApiResource(
  19.  *      attributes={"security"="is_granted('ROLE_OPERATOR')"},
  20.  *      normalizationContext={"groups"={"ElTaskTag:Read"}, "skip_null_values"=false},
  21.  *      denormalizationContext={"groups"={"ElTaskTag:Write"}},
  22.  *      collectionOperations={
  23.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  24.  *          "post"
  25.  *      },
  26.  *      itemOperations={
  27.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  28.  *          "put"={"security"="is_granted('IS_CO_OPR', object)"},
  29.  *          "patch"={"security"="is_granted('IS_CO_OPR', object)"},
  30.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"}
  31.  *     }
  32.  * )
  33.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "container.id": "exact", "elTasks.id": "exact"})
  34.  * @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
  35.  * @ORM\Entity(repositoryClass=ElTaskTagRepository::class)
  36.  * @UniqueEntity(
  37.  *     fields={"container", "name"},
  38.  *     errorPath="name"
  39.  * )
  40.  */
  41. class ElTaskTag implements ContainerMappedInterfaceElasticUpdateInterface
  42. {
  43.     /**
  44.      * Hook timestampable behavior
  45.      * updates createdAt, updatedAt fields
  46.      */
  47.     use TimestampableEntity;
  48.     /**
  49.      * @ORM\Id
  50.      * @ORM\GeneratedValue
  51.      * @ORM\Column(type="integer")
  52.      * @Groups({"ElTaskTag:Read", "ElTask:Read"})
  53.      */
  54.     private $id;
  55.     /**
  56.      * @ORM\Column(type="string", length=128)
  57.      * @Groups({"ElTaskTag:Read", "ElTaskTag:Write", "ElTask:Read", "ElTask:Read-My", "ElTask:Write"})
  58.      *
  59.      * @Assert\NotBlank(message="validation.elCourseTag:name.notBlank")
  60.      * @Assert\Length(max=128, maxMessage="validation.elCourseTag:name.max")
  61.      */
  62.     private $name;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=Container::class)
  65.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  66.      * @Groups({"ElTaskTag:Write", "ElTask:Write"})
  67.      */
  68.     private $container;
  69.     /**
  70.      * @ORM\ManyToMany(targetEntity=ElTask::class, mappedBy="elTaskTags")
  71.      * @Groups({"ElTaskTag:Write"})
  72.      */
  73.     private $elTasks;
  74.     public function __construct()
  75.     {
  76.         $this->elTasks = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function setName(string $name): self
  87.     {
  88.         $this->name $name;
  89.         return $this;
  90.     }
  91.     public function getContainer(): ?Container
  92.     {
  93.         return $this->container;
  94.     }
  95.     public function setContainer(?Container $container): self
  96.     {
  97.         $this->container $container;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection|ElTask[]
  102.      */
  103.     public function getElTasks(): Collection
  104.     {
  105.         return $this->elTasks;
  106.     }
  107.     public function addElTask(ElTask $elTask): self
  108.     {
  109.         if (!$this->elTasks->contains($elTask)) {
  110.             $this->elTasks[] = $elTask;
  111.             $elTask->addElTaskTag($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeElTask(ElTask $elTask): self
  116.     {
  117.         if ($this->elTasks->removeElement($elTask)) {
  118.             $elTask->removeElTaskTag($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function getQueueInfo(): array
  123.     {
  124.         return [
  125.             'type' => 'ElTaskTag',
  126.             'id' => $this->getId()
  127.         ];
  128.     }
  129. }