src/Entity/ServiceCategories.php line 32
<?php
namespace App\Entity;
use App\Repository\ServiceCategoriesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ServiceCategoriesRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['serviceCategory:read']],
denormalizationContext: ['groups' => ['serviceCategory:write']],
operations: [
new Get(),
new Put(security: 'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
new Patch(security: 'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
new Delete(security: 'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
new GetCollection(),
new Post(security: 'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")')
],
paginationEnabled: false
)]
class ServiceCategories
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['generalInvoice:read', 'generalInvoiceDetail:read', 'invoice:read', 'invoiceDetail:read', 'service:read', 'serviceCategory:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['generalInvoice:read', 'generalInvoiceDetail:read', 'invoice:read', 'invoiceDetail:read', 'service:read', 'serviceCategory:read', 'serviceCategory:write'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['generalInvoice:read', 'generalInvoiceDetail:read', 'invoice:read', 'invoiceDetail:read', 'service:read', 'serviceCategory:read', 'serviceCategory:write'])]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'serviceCategories', targetEntity: GeneralInvoiceDetail::class)]
private Collection $generalInvoiceDetails;
#[ORM\OneToMany(mappedBy: 'serviceCategories', targetEntity: Services::class)]
private Collection $services;
public function __construct()
{
$this->services = new ArrayCollection();
$this->generalInvoiceDetails = 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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Services>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Services $service): self
{
if (!$this->services->contains($service)) {
$this->services->add($service);
$service->setServiceCategories($this);
}
return $this;
}
public function removeService(Services $service): self
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getServiceCategories() === $this) {
$service->setServiceCategories(null);
}
}
return $this;
}
/**
* @return Collection<int, General Invoices>
*/
public function getGeneralInvoiceDetails(): Collection
{
return $this->generalInvoiceDetails;
}
public function addGeneralInvoiceDetail(GeneralInvoiceDetail $generalInvoiceDetail): self
{
if (!$this->generalInvoiceDetails->contains($generalInvoiceDetail)) {
$this->generalInvoiceDetails->add($generalInvoiceDetail);
$generalInvoiceDetail->setServiceCategories($this);
}
return $this;
}
public function removeGeneralInvoiceDetail(GeneralInvoiceDetail $generalInvoiceDetail): self
{
if ($this->generalInvoiceDetails->removeElement($generalInvoiceDetail)) {
// set the owning side to null (unless already changed)
if ($generalInvoiceDetail->getServiceCategories() === $this) {
$generalInvoiceDetail->setServiceCategories(null);
}
}
return $this;
}
public function __toString(){
return $this->name; //or anything else
}
}