<?php
namespace App\Entity;
use App\Repository\JobRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(indexes={ @ORM\Index(name="idx_job_program_id", columns={"program_id"}) })
* @ORM\Entity(repositoryClass=JobRepository::class)
* @Serializer\ExclusionPolicy("ALL")
* @UniqueEntity(
* fields={"label"},
* errorPath="label",
* message="Un métier existe avec le même libellé"
* )
*/
class Job extends BaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Expose
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Expose
*/
private $label;
/**
* @ORM\Column(type="text", nullable=true)
* @Serializer\Expose
*/
private $description;
/**
* @ORM\ManyToMany(targetEntity=Office::class, inversedBy="jobs")
*/
private $offices;
/**
* @ORM\ManyToOne(targetEntity=Program::class, inversedBy="jobs")
* @ORM\JoinColumn(name="program_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private $program;
/**
* @ORM\OneToOne(targetEntity=ImageManager::class, cascade={"persist", "remove"})
*/
private $cover;
/**
* @ORM\ManyToOne(targetEntity=Live::class, inversedBy="jobs")
*/
private $live;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="job", fetch="EXTRA_LAZY")
*/
private $users;
/**
* @ORM\ManyToMany(targetEntity=Module::class, mappedBy="jobs")
*/
private $modules;
/**
* @Gedmo\Slug(fields={"label"})
* @ORM\Column(length=191)
*/
private $slug;
/**
* @ORM\OneToMany(targetEntity=Target::class, mappedBy="job", fetch="EXTRA_LAZY")
*/
private $targets;
public function __construct()
{
$this->offices = new ArrayCollection();
$this->users = new ArrayCollection();
$this->modules = new ArrayCollection();
$this->targets = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Office>
*/
public function getOffices(): Collection
{
return $this->offices;
}
public function addOffice(Office $office): self
{
if (!$this->offices->contains($office)) {
$this->offices[] = $office;
}
return $this;
}
public function removeOffice(Office $office): self
{
$this->offices->removeElement($office);
return $this;
}
public function getProgram(): ?Program
{
return $this->program;
}
public function setProgram(?Program $program): self
{
$this->program = $program;
return $this;
}
public function getCover(): ?ImageManager
{
return $this->cover;
}
public function setCover(?ImageManager $cover): self
{
$this->cover = $cover;
return $this;
}
public function getLive(): ?Live
{
return $this->live;
}
public function setLive(?Live $live): self
{
$this->live = $live;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setJob($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getJob() === $this) {
$user->setJob(null);
}
}
return $this;
}
/**
* @return Collection<int, Module>
*/
public function getModules(): Collection
{
return $this->modules;
}
public function addModule(Module $module): self
{
if (!$this->modules->contains($module)) {
$this->modules[] = $module;
$module->addJob($this);
}
return $this;
}
public function removeModule(Module $module): self
{
if ($this->modules->removeElement($module)) {
$module->removeJob($this);
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Target>
*/
public function getTarges(): Collection
{
return $this->targets;
}
public function addTarget(Target $target): self
{
if (!$this->targets->contains($target)) {
$this->targets[] = $target;
$target->setJob($this);
}
return $this;
}
public function removeTarget(Target $target): self
{
if ($this->targets->removeElement($target)) {
// set the owning side to null (unless already changed)
if ($target->getJob() === $this) {
$target->setJob(null);
}
}
return $this;
}
}