<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\WorkersRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use ApiPlatform\Core\Annotation\ApiProperty;
#[ApiFilter(SearchFilter::class, properties: [
'fullName' => 'ipartial',
'codeIpn' => 'exact',
'phone' => 'exact',
'code1c' => 'exact',
'email' => 'exact',
'accountWorkers.account.user.id' => 'exact',
'accountWorkers.account.id' => 'exact',
'accountWorkers.account.name' => 'ipartial',
'manager.id' => 'exact',
'manager.firstName' => 'ipartial',
'phone' => 'exact',
])]
#[ORM\Entity(repositoryClass: WorkersRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['worker:read']],
denormalizationContext: ['groups' => ['worker:write']],
order: ['id' => 'DESC'],
)]
class Workers
{
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(length: 255)]
private ?string $fullName = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(length: 100, nullable: true, unique: true)]
private ?string $codeIpn = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(length: 50, nullable: true)]
private ?string $phone = null;
#[Groups(['worker:read', 'worker:write', 'account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\Column(length: 50, nullable: true)]
private ?string $email = null;
#[ORM\OneToMany(mappedBy: 'worker', targetEntity: AccountWorker::class)]
private Collection $accountWorkers;
#[ORM\OneToMany(mappedBy: 'worker', targetEntity: JobWorker::class)]
private Collection $jobWorkers;
public function __construct()
{
$this->accountWorkers = new ArrayCollection();
$this->jobWorkers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
return $this;
}
public function getCodeIpn(): ?string
{
return $this->codeIpn;
}
public function setCodeIpn(?string $codeIpn): self
{
$this->codeIpn = $codeIpn;
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;
}
/**
* @return Collection<int, AccountWorker>
*/
public function getAccountWorkers(): Collection
{
return $this->accountWorkers;
}
public function addAccountWorker(AccountWorker $accountWorker): self
{
if (!$this->accountWorkers->contains($accountWorker)) {
$this->accountWorkers->add($accountWorker);
$accountWorker->setWorker($this);
}
return $this;
}
public function removeAccountWorker(AccountWorker $accountWorker): self
{
if ($this->accountWorkers->removeElement($accountWorker)) {
// set the owning side to null (unless already changed)
if ($accountWorker->getWorker() === $this) {
$accountWorker->setWorker(null);
}
}
return $this;
}
/**
* @return Collection<int, JobWorker>
*/
public function getJobWorkers(): Collection
{
return $this->jobWorkers;
}
public function addJobWorker(JobWorker $jobWorker): self
{
if (!$this->jobWorkers->contains($jobWorker)) {
$this->jobWorkers->add($jobWorker);
$jobWorker->setWorker($this);
}
return $this;
}
public function removeJobWorker(JobWorker $jobWorker): self
{
if ($this->jobWorkers->removeElement($jobWorker)) {
// set the owning side to null (unless already changed)
if ($jobWorker->getWorker() === $this) {
$jobWorker->setWorker(null);
}
}
return $this;
}
}