<?php
namespace App\Entity;
use App\Repository\RegateRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=RegateRepository::class)
*
* @Serializer\ExclusionPolicy("ALL")
*/
class Regate
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups ({
* "regate:id",
* "regate",
* "regate-list",
* "export_user_datatable",
* "export_regate_datatable"
* })
*/
private ?int $id = NULL;
/**
* @ORM\Column(type="string", length=64)
*
* @Expose
* @Groups ({
* "regate:name",
* "regate",
* "user",
* "regate-list",
* "export_regate_datatable"
* })
*/
private ?string $name = NULL;
/**
* @ORM\ManyToOne(targetEntity=Regate::class, inversedBy="childs")
* @ORM\JoinColumn(onDelete="CASCADE")
*
* @Expose
* @Groups ({
* "regate",
* "regate-list",
* "export_regate_datatable"
* })
*/
private ?Regate $parent = NULL;
/**
* @ORM\OneToMany(targetEntity=Regate::class, mappedBy="parent", cascade={"remove"})
*
* @Expose
* @Groups ({
* "regate:childs",
* "regate",
* "regate-list"
* })
*/
private Collection $childs;
/**
* @ORM\Column(type="text")
*
* @Expose
* @Groups ({
* "regate:affectation",
* "regate",
* "user",
* "regate-list",
* "export_user_datatable",
* "export_regate_datatable"
* })
*/
private ?string $affectation = NULL;
/**
* @ORM\Column(type="string", length=64)
*
* @Expose
* @Groups ({
* "regate:level",
* "regate",
* "user",
* "regate-list",
* "export_regate_datatable"})
*/
private ?string $level = NULL;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="regate")
*
* @Expose
* @Groups ({
* "regate:members",
* "regate-list"
* })
*/
private Collection $members;
/**
* @ORM\OneToOne(targetEntity=User::class, mappedBy="responsableRegate", cascade={"persist", "remove"})
*/
private ?User $responsable = NULL;
public function __construct()
{
$this->childs = new ArrayCollection();
$this->members = new ArrayCollection();
}
public function __toString()
{
return $this->getLevel().' : '.$this->name.' '.$this->affectation;
}
public function getLevel(): ?string
{
return $this->level;
}
public function setLevel(string $level): self
{
$this->level = $level;
return $this;
}
/**
* Permet de retourner un array avec les différents lvl attribués à la régate
*
* @return false|string[]
*/
public function getLevels()
{
return explode(';', $this->level);
}
public function setLevels(array $levels): self
{
$this->level = implode(';', $levels);
return $this;
}
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;
}
/**
* @return Collection|self[]
*/
public function getChilds(): Collection
{
return $this->childs;
}
public function addChild(self $child): self
{
if (!$this->childs->contains($child)) {
$this->childs[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->childs->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(NULL);
}
}
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getAffectation(): ?string
{
return $this->affectation;
}
public function setAffectation(string $affectation): self
{
$this->affectation = $affectation;
return $this;
}
/**
* @return Collection|User[]
*/
public function getMembers(): Collection
{
return $this->members;
}
public function addMember(User $member): self
{
if (!$this->members->contains($member)) {
$this->members[] = $member;
$member->setRegate($this);
}
return $this;
}
public function removeMember(User $member): self
{
if ($this->members->removeElement($member)) {
// set the owning side to null (unless already changed)
if ($member->getRegate() === $this) {
$member->setRegate(NULL);
}
}
return $this;
}
/**
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("get_first_parent_affectation")
* @return string|null
*
* @Expose()
* @Groups ({
* "regate:get_first_parent_affectation",
* "regate",
* "regate-list",
* "export_regate_datatable"
* })
*/
public function getFirstParentAffectation()
{
return $this->parent ? $this->parent->getAffectation() : '';
}
public function getResponsable(): ?User
{
return $this->responsable;
}
public function setResponsable(?User $responsable): self
{
// unset the owning side of the relation if necessary
if ($responsable === NULL && $this->responsable !== NULL) {
$this->responsable->setResponsableRegate(NULL);
}
// set the owning side of the relation if necessary
if ($responsable !== NULL && $responsable->getResponsableRegate() !== $this) {
$responsable->setResponsableRegate($this);
}
$this->responsable = $responsable;
return $this;
}
}