<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\NotificationTypeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=NotificationTypeRepository::class)
* @ApiResource(
* normalizationContext={"groups"={"notification_type:read"}},
* denormalizationContext={"groups"={"notification_type:write"}},
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')",
* "security_message"="You are not allowed to access this ressource"
* },
* "patch"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
* }
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
* },
* "post"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
* }
* }
* )
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class NotificationType
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"notification_type:read", "notification:read"})
*/
private $id;
/**
* @Assert\NotNull()
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"notification_type:read", "notification_type:write", "notification:read"})
*/
private $label;
/**
* @Assert\NotNull()
* @ORM\Column(type="string", length=255)
* @Groups({"notification_type:read", "notification_type:write", "notification:read"})
*/
private $name;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="create")
* @Groups({"notification_type:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Groups({"notification_type:read"})
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="type")
*/
private $notifications;
public function __construct()
{
$this->notifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(?string $label): self
{
$this->label = $label;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setType($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getType() === $this) {
$notification->setType(null);
}
}
return $this;
}
}