src/Entity/Genealogy.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\GenealogyRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  12. /**
  13.  * @ApiResource(
  14.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  15.  *     normalizationContext={"groups"={"genealogy:read"}, "swagger_definition_name"="Read"},
  16.  *     denormalizationContext={"groups"={"genealogy:write"}, "swagger_definition_name"="Write"},
  17.  *     itemOperations={
  18.  *          "get"
  19.  *     },
  20.  *     collectionOperations={
  21.  *          "get"
  22.  *     },
  23.  *     attributes={
  24.  *          "pagination_items_per_page"=10,
  25.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  26.  *     }
  27.  * )
  28.  * @ApiFilter(SearchFilter::class, properties={
  29.  *     "collaborator.id" : "exact",
  30.  *     "collaborator.qualificationLevel.label": "exact"
  31.  * })
  32.  * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
  33.  * @Gedmo\Tree(type="nested")
  34.  */
  35. class Genealogy
  36. {
  37.     /**
  38.      * @ORM\Id
  39.      * @ORM\GeneratedValue
  40.      * @ORM\Column(type="integer")
  41.      *
  42.      * @Groups({
  43.      *   "genealogy:read"
  44.      * })
  45.      */
  46.     private $id;
  47.     /**
  48.      * @ORM\Column(type="integer")
  49.      * @Gedmo\TreeLeft
  50.      *
  51.      * @Groups({
  52.      *   "genealogy:read"
  53.      * })
  54.      */
  55.     private ?int $treeLeft;
  56.     /**
  57.      * @ORM\Column(type="integer")
  58.      *
  59.      * @Gedmo\TreeLevel
  60.      *
  61.      * @Groups({
  62.      *   "genealogy:read"
  63.      * })
  64.      */
  65.     private ?int $level;
  66.     /**
  67.      * @ORM\Column(type="integer")
  68.      *
  69.      * @Gedmo\TreeRight
  70.      *
  71.      * @Groups({
  72.      *   "genealogy:read"
  73.      * })
  74.      */
  75.     private ?int $treeRight;
  76.     /**
  77.      * @ORM\Column(type="integer", nullable=true)
  78.      *
  79.      * @Gedmo\TreeRoot
  80.      *
  81.      * @Groups({
  82.      *   "genealogy:read"
  83.      * })
  84.      */
  85.     private ?int $root;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity=Genealogy::class, inversedBy="students")
  88.      * @ORM\JoinColumn(nullable=true)
  89.      * @Gedmo\TreeParent
  90.      *
  91.      * @Groups({
  92.      *   "genealogy:read"
  93.      * })
  94.      */
  95.     private ?Genealogy $tutor;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity=Genealogy::class, mappedBy="tutor")
  98.      *
  99.      *  @Groups({
  100.      *   "genealogy:read"
  101.      * })
  102.      */
  103.     private $students;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="genealogies")
  106.      * @ORM\JoinColumn(nullable=false)
  107.      *
  108.      * @Groups({
  109.      *   "genealogy:read"
  110.      * })
  111.      */
  112.     private ?Agent $collaborator;
  113.     public function __construct()
  114.     {
  115.         $this->students = new ArrayCollection();
  116.     }
  117.     public function getId(): ?int
  118.     {
  119.         return $this->id;
  120.     }
  121.     public function getTreeLeft(): ?int
  122.     {
  123.         return $this->treeLeft;
  124.     }
  125.     public function setTreeLeft(int $treeLeft): self
  126.     {
  127.         $this->treeLeft $treeLeft;
  128.         return $this;
  129.     }
  130.     public function getLevel(): ?int
  131.     {
  132.         return $this->level;
  133.     }
  134.     public function setLevel(int $level): self
  135.     {
  136.         $this->level $level;
  137.         return $this;
  138.     }
  139.     public function getTreeRight(): ?int
  140.     {
  141.         return $this->treeRight;
  142.     }
  143.     public function setTreeRight(int $treeRight): self
  144.     {
  145.         $this->treeRight $treeRight;
  146.         return $this;
  147.     }
  148.     public function getRoot(): ?int
  149.     {
  150.         return $this->root;
  151.     }
  152.     public function setRoot(?int $root): self
  153.     {
  154.         $this->root $root;
  155.         return $this;
  156.     }
  157.     public function getTutor(): ?self
  158.     {
  159.         return $this->tutor;
  160.     }
  161.     /**
  162.      * @param Genealogy $tutor
  163.      * @return $this
  164.      */
  165.     public function setTutor(Genealogy $tutor null)
  166.     {
  167.         $this->tutor $tutor;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return Collection|self[]
  172.      */
  173.     public function getStudents(): Collection
  174.     {
  175.         return $this->students;
  176.     }
  177.     public function addStudent(self $student): self
  178.     {
  179.         if (!$this->students->contains($student)) {
  180.             $this->students[] = $student;
  181.             $student->setTutor($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeStudent(self $student): self
  186.     {
  187.         // set the owning side to null (unless already changed)
  188.         if ($this->students->removeElement($student) && $student->getTutor() === $this) {
  189.             $student->setTutor(null);
  190.         }
  191.         return $this;
  192.     }
  193.     public function getCollaborator(): ?Agent
  194.     {
  195.         return $this->collaborator;
  196.     }
  197.     public function setCollaborator(?Agent $collaborator): self
  198.     {
  199.         $this->collaborator $collaborator;
  200.         return $this;
  201.     }
  202. }