<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\JobsRepository;
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: JobsRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['job:read']],
denormalizationContext: ['groups' => ['job:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: [
'name' => 'ipartial',
'code1c' => 'exact',
'email' => 'exact',
'account.user.id' => 'exact',
'account.id' => 'exact',
'account.name' => 'ipartial'
])]
class Jobs
{
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write'])]
#[ORM\ManyToOne(inversedBy: 'jobs')]
private ?Accounts $account = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date = null;
#[Groups(['job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write', ])]
#[ORM\OneToMany(mappedBy: 'job', targetEntity: JobWorker::class)]
private Collection $jobWorkers;
public function __construct()
{
$this->jobWorkers = 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 getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
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 getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
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->setJob($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->getJob() === $this) {
$jobWorker->setJob(null);
}
}
return $this;
}
}