src/Entity/ConferenceTag.php line 49

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