src/Entity/ElExamTag.php line 43

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