src/Entity/AlertCategory.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\AlertCategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassAlertCategoryRepository::class)]
  10. #[ApiResource(
  11.     collectionOperations: [
  12.         'get' => [
  13.             'path' => '/public/alert_categories',
  14.         ],
  15.     ],
  16.     itemOperations: [
  17.         'get'
  18.     ],
  19.     normalizationContext: [
  20.         'groups' => 'read:alertCategory'
  21.     ]
  22. )]
  23. class AlertCategory
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     #[Groups([
  29.         'read:alertCategory',
  30.         'read:alert'
  31.     ])]
  32.     private ?int $id null;
  33.     #[ORM\Column(length255)]
  34.     #[Groups([
  35.         'read:alertCategory',
  36.         'read:alert'
  37.     ])]
  38.     private ?string $name null;
  39.     #[ORM\OneToMany(mappedBy'alertCategory'targetEntityAlert::class)]
  40.     private Collection $alerts;
  41.     #[ORM\Column(length255nullabletrue)]
  42.     #[Groups([
  43.         'read:alertCategory',
  44.         'read:alert'
  45.     ])]
  46.     private ?string $iconName null;
  47.     public function __construct()
  48.     {
  49.         $this->alerts = new ArrayCollection();
  50.     }
  51.     public function __toString(): string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getName(): ?string
  60.     {
  61.         return $this->name;
  62.     }
  63.     public function setName(string $name): static
  64.     {
  65.         $this->name $name;
  66.         return $this;
  67.     }
  68.     /**
  69.      * @return Collection<int, Alert>
  70.      */
  71.     public function getAlerts(): Collection
  72.     {
  73.         return $this->alerts;
  74.     }
  75.     public function addAlert(Alert $alert): static
  76.     {
  77.         if (!$this->alerts->contains($alert)) {
  78.             $this->alerts->add($alert);
  79.             $alert->setAlertCategory($this);
  80.         }
  81.         return $this;
  82.     }
  83.     public function removeAlert(Alert $alert): static
  84.     {
  85.         if ($this->alerts->removeElement($alert)) {
  86.             // set the owning side to null (unless already changed)
  87.             if ($alert->getAlertCategory() === $this) {
  88.                 $alert->setAlertCategory(null);
  89.             }
  90.         }
  91.         return $this;
  92.     }
  93.     public function getIconName(): ?string
  94.     {
  95.         return $this->iconName;
  96.     }
  97.     public function setIconName(?string $iconName): static
  98.     {
  99.         $this->iconName $iconName;
  100.         return $this;
  101.     }
  102. }