src/Entity/Employee.php line 33

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EmployeeRepository;
  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\ApiProperty;
  9. use ApiPlatform\Metadata\Get;
  10. use ApiPlatform\Metadata\GetCollection;
  11. use ApiPlatform\Metadata\Delete;
  12. use ApiPlatform\Metadata\Post;
  13. use ApiPlatform\Metadata\Patch;
  14. use ApiPlatform\Metadata\Put;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassEmployeeRepository::class)]
  17. #[ApiResource(
  18.     normalizationContext: ['groups' => ['employee:read']],
  19.     denormalizationContext: ['groups' => ['employee:write']],
  20.     operations: [
  21.         new Get(),
  22.         new Put(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  23.         new Patch(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  24.         new Delete(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")'),
  25.         new GetCollection(),
  26.         new Post(security'is_granted("ROLE_SUPER_ADMIN") or is_granted("ROLE_ADMIN")')
  27.     ],
  28.     paginationEnabledfalse
  29. )]
  30. class Employee
  31. {
  32.     #[ORM\Id]
  33.     #[ORM\GeneratedValue]
  34.     #[ORM\Column]
  35.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read'])]
  36.     private ?int $id null;
  37.     #[ORM\Column(length255)]
  38.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  39.     private ?string $name null;
  40.     #[ORM\Column(length255)]
  41.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  42.     private ?string $surname null;
  43.     #[ORM\Column(length255)]
  44.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  45.     private ?string $ice null;
  46.     #[ORM\Column(length255)]
  47.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  48.     private ?string $address null;
  49.     #[ORM\Column(length255)]
  50.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  51.     private ?string $phone null;
  52.     #[ORM\Column(length255)]
  53.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  54.     private ?string $email null;
  55.     #[ORM\Column(nullabletrue)]
  56.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  57.     #[ApiProperty(readabletruewritabletrue)]
  58.     private ?string $invoice_number null;
  59.     #[ORM\Column(length255nullabletrue)]
  60.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  61.     #[ApiProperty(readabletruewritabletrue)]
  62.     private ?string $i_f null;
  63.     #[ORM\Column(length255)]
  64.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  65.     #[ApiProperty(readabletruewritabletrue)]
  66.     private ?string $professional_tax null;
  67.     #[ORM\OneToOne(targetEntityUser::class, mappedBy'employee'cascade:['persist'])]
  68.     #[Groups(['invoice:read''invoiceDetail:read''employee:read'])]
  69.     private ?User $user null;
  70.     #[ORM\Column(nullabletrue)]
  71.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  72.     private ?array $templates null;
  73.     #[ORM\Column(nullabletrue)]
  74.     #[Groups(['user:read''invoice:read''invoiceDetail:read''employee:read''employee:write'])]
  75.     private ?array $categories null;
  76.     #[ORM\OneToMany(mappedBy'employee'targetEntityInvoice::class)]
  77.     #[ApiProperty(readablefalse)]
  78.     private Collection $invoices;
  79.     public function __construct()
  80.     {
  81.         $this->invoices = new ArrayCollection();
  82.     }
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getName(): ?string
  88.     {
  89.         return $this->name;
  90.     }
  91.     public function setName(string $name): self
  92.     {
  93.         $this->name $name;
  94.         return $this;
  95.     }
  96.     public function getSurname(): ?string
  97.     {
  98.         return $this->surname;
  99.     }
  100.     public function setSurname(string $surname): self
  101.     {
  102.         $this->surname $surname;
  103.         return $this;
  104.     }
  105.     public function getIce(): ?string
  106.     {
  107.         return $this->ice;
  108.     }
  109.     public function setIce(string $ice): self
  110.     {
  111.         $this->ice $ice;
  112.         return $this;
  113.     }
  114.     public function getAddress(): ?string
  115.     {
  116.         return $this->address;
  117.     }
  118.     public function setAddress(string $address): self
  119.     {
  120.         $this->address $address;
  121.         return $this;
  122.     }
  123.     public function getPhone(): ?string
  124.     {
  125.         return $this->phone;
  126.     }
  127.     public function setPhone(string $phone): self
  128.     {
  129.         $this->phone $phone;
  130.         return $this;
  131.     }
  132.     public function getEmail(): ?string
  133.     {
  134.         return $this->email;
  135.     }
  136.     public function setEmail(string $email): self
  137.     {
  138.         $this->email $email;
  139.         return $this;
  140.     }
  141.     public function getInvoiceNumber(): ?int
  142.     {
  143.         return $this->invoice_number;
  144.     }
  145.     public function setInvoiceNumber(int $invoice_number): self
  146.     {
  147.         $this->invoice_number $invoice_number;
  148.         return $this;
  149.     }
  150.     public function getIF(): ?string
  151.     {
  152.         return $this->i_f;
  153.     }
  154.     public function setIF(?string $i_f): self
  155.     {
  156.         $this->i_f $i_f;
  157.         return $this;
  158.     }
  159.     public function getProfessionalTax(): ?string
  160.     {
  161.         return $this->professional_tax;
  162.     }
  163.     public function setProfessionalTax(string $professional_tax): self
  164.     {
  165.         $this->professional_tax $professional_tax;
  166.         return $this;
  167.     }
  168.     public function getTemplates(): array
  169.     {
  170.         $templates = [];
  171.         if(!is_null($this->templates)) {
  172.             foreach ($this->templates as $value) {
  173.                 array_push($templatesstrval($value));
  174.             }
  175.         }
  176.         return array_unique($templates);
  177.     }
  178.     public function setTemplates(?array $templates): self
  179.     {
  180.         $this->templates $templates;
  181.         return $this;
  182.     }
  183.     public function getCategories(): array
  184.     {
  185.         $categories = [];
  186.         if(!is_null($this->categories)) {
  187.             foreach ($this->categories as $value) {
  188.                 array_push($categoriesstrval($value));
  189.             }
  190.         }
  191.         return array_unique($categories);
  192.     }
  193.     public function setCategories(?array $categories): self
  194.     {
  195.         $this->categories $categories;
  196.         return $this;
  197.     }
  198.     public function getUser(): ?User
  199.     {
  200.         return $this->user;
  201.     }
  202.     public function setUser(?User $user): self
  203.     {
  204.         $this->user $user;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return Collection<int, Invoice>
  209.      */
  210.     public function getInvoices(): Collection
  211.     {
  212.         return $this->invoices;
  213.     }
  214.     public function addInvoice(Invoice $invoice): self
  215.     {
  216.         if (!$this->invoices->contains($invoice)) {
  217.             $this->invoices->add($invoice);
  218.             $invoice->setEmployee($this);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeInvoice(Invoice $invoice): self
  223.     {
  224.         if ($this->invoices->removeElement($invoice)) {
  225.             // set the owning side to null (unless already changed)
  226.             if ($invoice->getEmployee() === $this) {
  227.                 $invoice->setEmployee(null);
  228.             }
  229.         }
  230.         return $this;
  231.     }
  232.     public function __toString(){
  233.         return $this->name ' '$this->surname//or anything else
  234.       }
  235. }