src/Entity/Services.php line 38

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ServicesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use ApiPlatform\Metadata\ApiResource;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Delete;
  11. use ApiPlatform\Metadata\Post;
  12. use ApiPlatform\Metadata\Patch;
  13. use ApiPlatform\Metadata\Put;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use App\Controller\Api\UserController;
  16. #[ORM\Entity(repositoryClassServicesRepository::class)]
  17. #[ApiResource(
  18.     normalizationContext: ['groups' => ['service:read']],
  19.     denormalizationContext: ['groups' => ['service:write']],
  20.     operations: [
  21.         new Get(),
  22.         new Get(
  23.             name'user_services',
  24.             routeName'api_user_services',
  25.             controllerUserController::class
  26.         ),
  27.         new Put(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  28.         new Patch(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  29.         new Delete(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  30.         new GetCollection(),
  31.         new Post(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")')
  32.     ],
  33.     paginationEnabledfalse
  34. )]
  35. class Services
  36. {
  37.     #[ORM\Id]
  38.     #[ORM\GeneratedValue]
  39.     #[ORM\Column]
  40.     #[Groups(['invoice:read''invoiceDetail:read''service:read'])]
  41.     private ?int $id null;
  42.     #[ORM\Column(length255)]
  43.     #[Groups(['invoice:read''invoiceDetail:read''service:read''service:write'])]
  44.     private ?string $name null;
  45.     #[ORM\Column(length255)]
  46.     #[Groups(['invoice:read''invoiceDetail:read''service:read''service:write'])]
  47.     private ?string $description null;
  48.     #[ORM\Column]
  49.     #[Groups(['invoice:read''invoiceDetail:read''service:read''service:write'])]
  50.     private ?float $price null;
  51.     #[ORM\OneToMany(mappedBy'service'targetEntityInvoiceDetail::class)]
  52.     private Collection $invoiceDetails;
  53.     #[ORM\ManyToOne(inversedBy'services')]
  54.     #[Groups(['invoice:read''invoiceDetail:read''service:read''service:write'])]
  55.     private ?ServiceCategories $serviceCategories null;
  56.     public function __construct()
  57.     {
  58.         $this->invoiceDetails = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getName(): ?string
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName(string $name): self
  69.     {
  70.         $this->name $name;
  71.         return $this;
  72.     }
  73.     public function getDescription(): ?string
  74.     {
  75.         return $this->description;
  76.     }
  77.     public function setDescription(string $description): self
  78.     {
  79.         $this->description $description;
  80.         return $this;
  81.     }
  82.     public function getPrice(): ?float
  83.     {
  84.         return $this->price;
  85.     }
  86.     public function setPrice(float $price): self
  87.     {
  88.         $this->price $price;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return Collection<int, InvoiceDetail>
  93.      */
  94.     public function getInvoiceDetails(): Collection
  95.     {
  96.         return $this->invoiceDetails;
  97.     }
  98.     public function addInvoiceDetail(InvoiceDetail $invoiceDetail): self
  99.     {
  100.         if (!$this->invoiceDetails->contains($invoiceDetail)) {
  101.             $this->invoiceDetails->add($invoiceDetail);
  102.             $invoiceDetail->setService($this);
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeInvoiceDetail(InvoiceDetail $invoiceDetail): self
  107.     {
  108.         if ($this->invoiceDetails->removeElement($invoiceDetail)) {
  109.             // set the owning side to null (unless already changed)
  110.             if ($invoiceDetail->getService() === $this) {
  111.                 $invoiceDetail->setService(null);
  112.             }
  113.         }
  114.         return $this;
  115.     }
  116.     public function __toString(){
  117.         if(!is_null($this->serviceCategories)){
  118.             return strval($this->serviceCategories).' : '.$this->name//or anything else
  119.         }
  120.         else {
  121.             return $this->name//or anything else
  122.         }
  123.       }
  124.     public function getServiceCategories(): ?ServiceCategories
  125.     {
  126.         return $this->serviceCategories;
  127.     }
  128.     public function setServiceCategories(?ServiceCategories $serviceCategories): self
  129.     {
  130.         $this->serviceCategories $serviceCategories;
  131.         return $this;
  132.     }
  133. }