<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\AccountWorkerRepository;
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;
#[ORM\Entity(repositoryClass: AccountWorkerRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['account_worker:read']],
denormalizationContext: ['groups' => ['account_worker:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'account.id' => 'exact',
// 'account.user.id' => 'exact',
'worker.id' => 'exact',
]
)]
class AccountWorker
{
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write', 'worker:read', 'worker:write'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['account_worker:read', 'account_worker:write', 'worker:read', 'worker:write'])]
#[ORM\ManyToOne(inversedBy: 'accountWorkers')]
#[ORM\JoinColumn(nullable: false)]
private ?Accounts $account = null;
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write'])]
#[ORM\ManyToOne(inversedBy: 'accountWorkers')]
private ?Workers $worker = null;
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write', 'worker:read', 'worker:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write', 'worker:read', 'worker:write'])]
#[ORM\OneToMany(mappedBy: 'accountWorker', targetEntity: MediaObject::class)]
private Collection $media;
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write', 'worker:read', 'worker:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['account_worker:read', 'account_worker:write', 'account:read', 'read', 'account:write', 'write', 'worker:read', 'worker:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
public function __construct()
{
$this->media = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
return $this;
}
public function getWorker(): ?Workers
{
return $this->worker;
}
public function setWorker(?Workers $worker): self
{
$this->worker = $worker;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
/**
* @return Collection<int, MediaObject>
*/
public function getMedia(): Collection
{
return $this->media;
}
public function addMedium(MediaObject $medium): self
{
if (!$this->media->contains($medium)) {
$this->media->add($medium);
$medium->setAccountWorker($this);
}
return $this;
}
public function removeMedium(MediaObject $medium): self
{
if ($this->media->removeElement($medium)) {
// set the owning side to null (unless already changed)
if ($medium->getAccountWorker() === $this) {
$medium->setAccountWorker(null);
}
}
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;
}
}