src/Entity/ElCourseTag.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\ElCourseTagRepository;
  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"={"ElCourseTag:Read"}, "skip_null_values"=false},
  21.  *      denormalizationContext={"groups"={"ElCourseTag:Write"}},
  22.  *      collectionOperations={
  23.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  24.  *          "get_for_public_page"={
  25.  *              "route_name"="api_pub_el_course_tags_get_for_public_page_collection",
  26.  *              "method"="GET",
  27.  *              "security"="is_granted('PUBLIC_ACCESS')",
  28.  *              "normalization_context"={"groups"={"ElCourseTag:PRead"}, "skip_null_values"=false}
  29.  *          },
  30.  *          "post"
  31.  *      },
  32.  *      itemOperations={
  33.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  34.  *          "put"={"security"="is_granted('IS_CO_OPR', object)"},
  35.  *          "patch"={"security"="is_granted('IS_CO_OPR', object)"},
  36.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"}
  37.  *     }
  38.  * )
  39.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "container.id": "exact", "elCourses.id": "exact"})
  40.  * @ApiFilter(OrderFilter::class, properties={"id": "ASC", "name"})
  41.  * @ORM\Entity(repositoryClass=ElCourseTagRepository::class)
  42.  * @UniqueEntity(
  43.  *     fields={"container", "name"},
  44.  *     errorPath="name"
  45.  * )
  46.  */
  47. class ElCourseTag implements ContainerMappedInterfaceElasticUpdateInterface
  48. {
  49.     /**
  50.      * Hook timestampable behavior
  51.      * updates createdAt, updatedAt fields
  52.      */
  53.     use TimestampableEntity;
  54.     /**
  55.      * @ORM\Id
  56.      * @ORM\GeneratedValue
  57.      * @ORM\Column(type="integer")
  58.      * @Groups({"ElCourseTag:Read", "ElCourse:Read", "ElCourseTag:PRead"})
  59.      */
  60.     private $id;
  61.     /**
  62.      * @ORM\Column(type="string", length=128)
  63.      * @Groups({"ElCourseTag:Read", "ElCourseTag:Write", "ElCourse:Read", "ElCourse:Write", "ElCourseTag:PRead"})
  64.      *
  65.      * @Assert\NotBlank(message="validation.elCourseTag:name.notBlank")
  66.      * @Assert\Length(max=128, maxMessage="validation.elCourseTag:name.max")
  67.      */
  68.     private $name;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity=Container::class)
  71.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  72.      * @Groups({"ElCourseTag:Write", "ElCourse:Write"})
  73.      */
  74.     private $container;
  75.     /**
  76.      * @ORM\ManyToMany(targetEntity=ElCourse::class, mappedBy="elCourseTags")
  77.      * @Groups({"ElCourseTag:Write"})
  78.      */
  79.     private $elCourses;
  80.     public function __construct()
  81.     {
  82.         $this->elCourses = new ArrayCollection();
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getName(): ?string
  89.     {
  90.         return $this->name;
  91.     }
  92.     public function setName(string $name): self
  93.     {
  94.         $this->name $name;
  95.         return $this;
  96.     }
  97.     public function getContainer(): ?Container
  98.     {
  99.         return $this->container;
  100.     }
  101.     public function setContainer(?Container $container): self
  102.     {
  103.         $this->container $container;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @return Collection|ElCourse[]
  108.      */
  109.     public function getElCourses(): Collection
  110.     {
  111.         return $this->elCourses;
  112.     }
  113.     public function addElCourse(ElCourse $elCourse): self
  114.     {
  115.         if (!$this->elCourses->contains($elCourse)) {
  116.             $this->elCourses[] = $elCourse;
  117.             $elCourse->addElCourseTag($this);
  118.         }
  119.         return $this;
  120.     }
  121.     public function removeElCourse(ElCourse $elCourse): self
  122.     {
  123.         if ($this->elCourses->removeElement($elCourse)) {
  124.             $elCourse->removeElCourseTag($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function getQueueInfo(): array
  129.     {
  130.         return [
  131.             'type' => 'ElCourseTag',
  132.             'id' => $this->getId()
  133.         ];
  134.     }
  135. }