<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\GenealogyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"genealogy:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"genealogy:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get"
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ApiFilter(SearchFilter::class, properties={
* "collaborator.id" : "exact",
* "collaborator.qualificationLevel.label": "exact"
* })
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
* @Gedmo\Tree(type="nested")
*/
class Genealogy
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "genealogy:read"
* })
*/
private $id;
/**
* @ORM\Column(type="integer")
* @Gedmo\TreeLeft
*
* @Groups({
* "genealogy:read"
* })
*/
private ?int $treeLeft;
/**
* @ORM\Column(type="integer")
*
* @Gedmo\TreeLevel
*
* @Groups({
* "genealogy:read"
* })
*/
private ?int $level;
/**
* @ORM\Column(type="integer")
*
* @Gedmo\TreeRight
*
* @Groups({
* "genealogy:read"
* })
*/
private ?int $treeRight;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @Gedmo\TreeRoot
*
* @Groups({
* "genealogy:read"
* })
*/
private ?int $root;
/**
* @ORM\ManyToOne(targetEntity=Genealogy::class, inversedBy="students")
* @ORM\JoinColumn(nullable=true)
* @Gedmo\TreeParent
*
* @Groups({
* "genealogy:read"
* })
*/
private ?Genealogy $tutor;
/**
* @ORM\OneToMany(targetEntity=Genealogy::class, mappedBy="tutor")
*
* @Groups({
* "genealogy:read"
* })
*/
private $students;
/**
* @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="genealogies")
* @ORM\JoinColumn(nullable=false)
*
* @Groups({
* "genealogy:read"
* })
*/
private ?Agent $collaborator;
public function __construct()
{
$this->students = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTreeLeft(): ?int
{
return $this->treeLeft;
}
public function setTreeLeft(int $treeLeft): self
{
$this->treeLeft = $treeLeft;
return $this;
}
public function getLevel(): ?int
{
return $this->level;
}
public function setLevel(int $level): self
{
$this->level = $level;
return $this;
}
public function getTreeRight(): ?int
{
return $this->treeRight;
}
public function setTreeRight(int $treeRight): self
{
$this->treeRight = $treeRight;
return $this;
}
public function getRoot(): ?int
{
return $this->root;
}
public function setRoot(?int $root): self
{
$this->root = $root;
return $this;
}
public function getTutor(): ?self
{
return $this->tutor;
}
/**
* @param Genealogy $tutor
* @return $this
*/
public function setTutor(Genealogy $tutor = null)
{
$this->tutor = $tutor;
return $this;
}
/**
* @return Collection|self[]
*/
public function getStudents(): Collection
{
return $this->students;
}
public function addStudent(self $student): self
{
if (!$this->students->contains($student)) {
$this->students[] = $student;
$student->setTutor($this);
}
return $this;
}
public function removeStudent(self $student): self
{
// set the owning side to null (unless already changed)
if ($this->students->removeElement($student) && $student->getTutor() === $this) {
$student->setTutor(null);
}
return $this;
}
public function getCollaborator(): ?Agent
{
return $this->collaborator;
}
public function setCollaborator(?Agent $collaborator): self
{
$this->collaborator = $collaborator;
return $this;
}
}