<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\AlertCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: AlertCategoryRepository::class)]
#[ApiResource(
collectionOperations: [
'get' => [
'path' => '/public/alert_categories',
],
],
itemOperations: [
'get'
],
normalizationContext: [
'groups' => 'read:alertCategory'
]
)]
class AlertCategory
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups([
'read:alertCategory',
'read:alert'
])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups([
'read:alertCategory',
'read:alert'
])]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'alertCategory', targetEntity: Alert::class)]
private Collection $alerts;
#[ORM\Column(length: 255, nullable: true)]
#[Groups([
'read:alertCategory',
'read:alert'
])]
private ?string $iconName = null;
public function __construct()
{
$this->alerts = new ArrayCollection();
}
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Alert>
*/
public function getAlerts(): Collection
{
return $this->alerts;
}
public function addAlert(Alert $alert): static
{
if (!$this->alerts->contains($alert)) {
$this->alerts->add($alert);
$alert->setAlertCategory($this);
}
return $this;
}
public function removeAlert(Alert $alert): static
{
if ($this->alerts->removeElement($alert)) {
// set the owning side to null (unless already changed)
if ($alert->getAlertCategory() === $this) {
$alert->setAlertCategory(null);
}
}
return $this;
}
public function getIconName(): ?string
{
return $this->iconName;
}
public function setIconName(?string $iconName): static
{
$this->iconName = $iconName;
return $this;
}
}