src/Entity/Employee.php line 33
<?php
namespace App\Entity;
use App\Repository\EmployeeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
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: EmployeeRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['employee:read']],
denormalizationContext: ['groups' => ['employee: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 Employee
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $name = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $surname = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $ice = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $address = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?string $email = null;
#[ORM\Column(nullable: true)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
#[ApiProperty(readable: true, writable: true)]
private ?string $invoice_number = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
#[ApiProperty(readable: true, writable: true)]
private ?string $i_f = null;
#[ORM\Column(length: 255)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
#[ApiProperty(readable: true, writable: true)]
private ?string $professional_tax = null;
#[ORM\OneToOne(targetEntity: User::class, mappedBy: 'employee', cascade:['persist'])]
#[Groups(['invoice:read', 'invoiceDetail:read', 'employee:read'])]
private ?User $user = null;
#[ORM\Column(nullable: true)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?array $templates = null;
#[ORM\Column(nullable: true)]
#[Groups(['user:read', 'invoice:read', 'invoiceDetail:read', 'employee:read', 'employee:write'])]
private ?array $categories = null;
#[ORM\OneToMany(mappedBy: 'employee', targetEntity: Invoice::class)]
#[ApiProperty(readable: false)]
private Collection $invoices;
public function __construct()
{
$this->invoices = 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 getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getIce(): ?string
{
return $this->ice;
}
public function setIce(string $ice): self
{
$this->ice = $ice;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getInvoiceNumber(): ?int
{
return $this->invoice_number;
}
public function setInvoiceNumber(int $invoice_number): self
{
$this->invoice_number = $invoice_number;
return $this;
}
public function getIF(): ?string
{
return $this->i_f;
}
public function setIF(?string $i_f): self
{
$this->i_f = $i_f;
return $this;
}
public function getProfessionalTax(): ?string
{
return $this->professional_tax;
}
public function setProfessionalTax(string $professional_tax): self
{
$this->professional_tax = $professional_tax;
return $this;
}
public function getTemplates(): array
{
$templates = [];
if(!is_null($this->templates)) {
foreach ($this->templates as $value) {
array_push($templates, strval($value));
}
}
return array_unique($templates);
}
public function setTemplates(?array $templates): self
{
$this->templates = $templates;
return $this;
}
public function getCategories(): array
{
$categories = [];
if(!is_null($this->categories)) {
foreach ($this->categories as $value) {
array_push($categories, strval($value));
}
}
return array_unique($categories);
}
public function setCategories(?array $categories): self
{
$this->categories = $categories;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $invoice): self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
$invoice->setEmployee($this);
}
return $this;
}
public function removeInvoice(Invoice $invoice): self
{
if ($this->invoices->removeElement($invoice)) {
// set the owning side to null (unless already changed)
if ($invoice->getEmployee() === $this) {
$invoice->setEmployee(null);
}
}
return $this;
}
public function __toString(){
return $this->name . ' '. $this->surname; //or anything else
}
}