<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\EngineerRepository;
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: EngineerRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['enginneer:read']],
denormalizationContext: ['groups' => ['enginneer:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: [
'name' => 'ipartial',
'code1c' => 'exact',
])]
class Engineer
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['factory:read', 'enginneer:read', 'job:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write','account_worker:read'])]
private ?int $id = null;
#[Groups(['factory:read', 'enginneer:read', 'job:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write','account_worker:read' ])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['factory:read', 'enginneer:read', 'job:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write','account_worker:read' ])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['factory:read', 'enginneer:read', 'job:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write','account_worker:read' ])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
#[Groups(['enginneer:read', 'job:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write' ])]
#[ORM\ManyToOne(inversedBy: 'engineers')]
private ?Factory $factory = null;
#[Groups(['factory:read', 'enginneer:read', 'worker:read', 'account_worker:read', 'account:read', 'read', 'account:write', 'enginneer:write' ])]
#[ORM\OneToMany(mappedBy: 'engineer', targetEntity: Jobs::class)]
private Collection $jobs;
public function __construct()
{
$this->jobs = 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 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 getFactory(): ?Factory
{
return $this->factory;
}
public function setFactory(?Factory $factory): self
{
$this->factory = $factory;
return $this;
}
/**
* @return Collection<int, Jobs>
*/
public function getJobs(): Collection
{
return $this->jobs;
}
public function addJob(Jobs $job): self
{
if (!$this->jobs->contains($job)) {
$this->jobs->add($job);
$job->setEngineer($this);
}
return $this;
}
public function removeJob(Jobs $job): self
{
if ($this->jobs->removeElement($job)) {
// set the owning side to null (unless already changed)
if ($job->getEngineer() === $this) {
$job->setEngineer(null);
}
}
return $this;
}
}