src/Entity/NotificationType.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  6. use App\Repository\NotificationTypeRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity(repositoryClass=NotificationTypeRepository::class)
  15.  * @ApiResource(
  16.  *      normalizationContext={"groups"={"notification_type:read"}},
  17.  *      denormalizationContext={"groups"={"notification_type:write"}},
  18.  *      itemOperations={
  19.  *         "get"={
  20.  *              "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')",
  21.  *              "security_message"="You are not allowed to access this ressource"
  22.  *          },
  23.  *          "patch"={
  24.  *              "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
  25.  *          },
  26.  *          "delete"={
  27.  *              "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
  28.  *          }
  29.  *      },
  30.  *      collectionOperations={
  31.  *         "get"={
  32.  *              "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
  33.  *          },
  34.  *         "post"={
  35.  *              "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
  36.  *          }
  37.  *      }
  38.  * )
  39.  * @ApiFilter(PropertyFilter::class, 
  40.  *      arguments={
  41.  *          "parameterName"="fields", 
  42.  *          "overrideDefaultProperties"=true
  43.  *     }
  44.  * )
  45.  */
  46. class NotificationType
  47. {
  48.     /**
  49.      * @ORM\Id
  50.      * @ORM\GeneratedValue
  51.      * @ORM\Column(type="integer")
  52.      * @Groups({"notification_type:read", "notification:read"})
  53.      */
  54.     private $id;
  55.     /**
  56.      * @Assert\NotNull()
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      * @Groups({"notification_type:read", "notification_type:write", "notification:read"})
  59.      */
  60.     private $label;
  61.     /**
  62.      * @Assert\NotNull()
  63.      * @ORM\Column(type="string", length=255)
  64.      * @Groups({"notification_type:read", "notification_type:write", "notification:read"})
  65.      */
  66.     private $name;
  67.     /**
  68.      * @ORM\Column(type="datetime", nullable=true)
  69.      * @Gedmo\Timestampable(on="create")
  70.      * @Groups({"notification_type:read"})
  71.      */
  72.     private $createdAt;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      * @Gedmo\Timestampable(on="update")
  76.      * @Groups({"notification_type:read"})
  77.      */
  78.     private $updatedAt;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="type")
  81.      */
  82.     private $notifications;
  83.     public function __construct()
  84.     {
  85.         $this->notifications = new ArrayCollection();
  86.     }
  87.     public function getId(): ?int
  88.     {
  89.         return $this->id;
  90.     }
  91.     
  92.     public function getLabel(): ?string
  93.     {
  94.         return $this->label;
  95.     }
  96.     public function setLabel(?string $label): self
  97.     {
  98.         $this->label $label;
  99.         return $this;
  100.     }
  101.     public function getName(): ?string
  102.     {
  103.         return $this->name;
  104.     }
  105.     public function setName(string $name): self
  106.     {
  107.         $this->name $name;
  108.         return $this;
  109.     }
  110.     public function getCreatedAt(): ?\DateTimeInterface
  111.     {
  112.         return $this->createdAt;
  113.     }
  114.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  115.     {
  116.         $this->createdAt $createdAt;
  117.         return $this;
  118.     }
  119.     public function getUpdatedAt(): ?\DateTimeInterface
  120.     {
  121.         return $this->updatedAt;
  122.     }
  123.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  124.     {
  125.         $this->updatedAt $updatedAt;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, Notification>
  130.      */
  131.     public function getNotifications(): Collection
  132.     {
  133.         return $this->notifications;
  134.     }
  135.     public function addNotification(Notification $notification): self
  136.     {
  137.         if (!$this->notifications->contains($notification)) {
  138.             $this->notifications[] = $notification;
  139.             $notification->setType($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeNotification(Notification $notification): self
  144.     {
  145.         if ($this->notifications->removeElement($notification)) {
  146.             // set the owning side to null (unless already changed)
  147.             if ($notification->getType() === $this) {
  148.                 $notification->setType(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153. }