<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\ConferenceTagRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
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"={"ConferenceTag:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"ConferenceTag:Write"}},
* collectionOperations={
* "post",
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "get_for_public_page"={
* "route_name"="api_pub_conference_tags_get_for_public_page_collection",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"ConferenceTag:PRead"}, "skip_null_values"=false}
* }
* },
* 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={"container.id": "exact", "name": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id": "ASC", "name"})
* @ORM\Entity(repositoryClass=ConferenceTagRepository::class)
* @UniqueEntity(
* fields={"container", "name"},
* errorPath="name"
* )
*/
class ConferenceTag implements ContainerMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"ConferenceTag:Read", "ConferenceTag:PRead", "Conference:Read", "Conference:PRead"})
*/
private $id;
/**
* @ORM\Column(type="string", length=64)
* @Groups({"ConferenceTag:Read", "ConferenceTag:PRead", "ConferenceTag:Write", "Conference:Read", "Conference:Write", "Conference:PRead"})
*
* @Assert\NotBlank(message="validation.conferenceTag:name.notBlank")
* @Assert\Length(max=64, maxMessage="validation.conferenceTag:name.max")
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"ConferenceTag:Read", "ConferenceTag:Write", "Conference:Write"})
*/
private $container;
/**
* @ORM\ManyToMany(targetEntity=Conference::class, mappedBy="conferenceTags")
*
* @Groups({"ConferenceTag:Write"})
*/
private $conferences;
public function __construct()
{
$this->conferences = 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|Conference[]
*/
public function getConferences(): Collection
{
return $this->conferences;
}
public function addConference(Conference $conference): self
{
if (!$this->conferences->contains($conference)) {
$this->conferences[] = $conference;
$conference->addConferenceTag($this);
}
return $this;
}
public function removeConference(Conference $conference): self
{
if ($this->conferences->removeElement($conference)) {
$conference->removeConferenceTag($this);
}
return $this;
}
}