src/Entity/Child.php line 49

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\enums\ChildStatus;
  4. use DateTime;
  5. use DateInterval;
  6. use App\Entity\Classroom;
  7. use Symfony\Component\Uid\Ulid;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Repository\ChildRepository;
  10. use Doctrine\Common\Collections\Collection;
  11. use ApiPlatform\Core\Annotation\ApiResource;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. #[ORM\Entity(repositoryClassChildRepository::class)]
  17. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  18. #[ORM\HasLifecycleCallbacks]
  19. #[ApiResource(
  20.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  21.     collectionOperations: [
  22.         'get' => [
  23.             'normalization_context' => [
  24.                 'groups' => [
  25.                     'read:child:basic',
  26.                     'read:section:basic',
  27.                     'read:pointing:basic'
  28.                 ]
  29.             ]
  30.         ],
  31.     ],
  32.     // itemOperations: [
  33.     //     'get' => [
  34.     //         'normalization_context' => [
  35.     //             'groups' => [
  36.     //                 'read:child:basic',
  37.     //                 'read:section:basic',
  38.     //                 'read:pointing:basic',
  39.     //                 'read:subscription:basic',
  40.     //                 'read:familymember:basic'
  41.     //             ]
  42.     //         ]
  43.     //     ],
  44.     // ],
  45. )]
  46. class Child
  47. {
  48.     use Timestamps;
  49.     #[ORM\Id]
  50.     #[ORM\Column(type'ulid'uniquetrue)]
  51.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  52.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  53.     #[Groups(['read:child:basic''read:child:export'])]
  54.     private ?Ulid $id null;
  55.     #[ORM\Column(type'string'length255)]
  56.     #[Groups(['read:child:basic''read:child:export'])]
  57.     private $first_name;
  58.     #[ORM\Column(type'string'length255)]
  59.     #[Groups(['read:child:basic''read:child:export'])]
  60.     private $last_name;
  61.     #[ORM\Column(type'string'length255)]
  62.     #[Groups(['read:child:basic''read:child:export'])]
  63.     private $gender;
  64.     #[ORM\Column(type'date')]
  65.     #[Groups(['read:child:basic''read:child:export'])]
  66.     private $birth_date;
  67.     #[ORM\Column(type'string'length255nullabletrue)]
  68.     #[Groups(['read:child:basic''read:child:export'])]
  69.     private $birth_place;
  70.     #[ORM\Column(type'string'length255)]
  71.     #[Groups(['read:child:basic''read:child:export'])]
  72.     private $blood;
  73.     #[ORM\Column(type'text'nullabletrue)]
  74.     #[Groups(['read:child:export'])]
  75.     private $diseases;
  76.     #[ORM\Column(type'text'nullabletrue)]
  77.     #[Groups(['read:child:export'])]
  78.     private $allergies;
  79.     #[ORM\Column(type'text'nullabletrue)]
  80.     #[Groups(['read:child:export'])]
  81.     private $food_habit;
  82.     #[ORM\Column(type'text'nullabletrue)]
  83.     #[Groups(['read:child:export'])]
  84.     private $behavior;
  85.     #[ORM\Column(type'text'nullabletrue)]
  86.     #[Groups(['read:child:export'])]
  87.     private $fears;
  88.     #[ORM\Column(type'text'nullabletrue)]
  89.     #[Groups(['read:child:export'])]
  90.     private $interests;
  91.     #[ORM\Column(type'string'length255nullabletrue)]
  92.     #[Groups(['read:child:export'])]
  93.     private $description;
  94.     #[ORM\Column(type'string'length255enumTypeChildStatus::class)]
  95.     private $status;
  96.     #[ORM\ManyToOne(targetEntitySection::class, inversedBy'children')]
  97.     #[Groups(['read:child:export''read:child:basic'])]
  98.     private $section;
  99.     #[ORM\Column(type'string'length255nullabletrue)]
  100.     #[Groups(['read:child:basic'])]
  101.     private $photo;
  102.     #[ORM\ManyToMany(targetEntityFamilyMember::class, inversedBy'children'cascade: ['persist'])]
  103.     private $family;
  104.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'children')]
  105.     #[ORM\JoinColumn(nullablefalse)]
  106.     private $owner;
  107.     #[ORM\OneToOne(inversedBy'child'targetEntityLocation::class, cascade: ['persist''remove'])]
  108.     private $address;
  109.     #[ORM\OneToMany(mappedBy'child'targetEntitySubscription::class, orphanRemovaltrue)]
  110.     private $subscriptions;
  111.     #[ORM\ManyToMany(targetEntityClassroom::class, mappedBy'children')]
  112.     private $classrooms;
  113.     #[ORM\ManyToMany(targetEntityEvenement::class, mappedBy'children')]
  114.     private $evenements;
  115.     #[ORM\ManyToMany(targetEntityTask::class, mappedBy'children')]
  116.     private $tasks;
  117.     #[ORM\OneToMany(mappedBy'child'targetEntityPost::class, orphanRemovaltrue)]
  118.     private $posts;
  119.     #[ORM\Column(type'string'length255nullabletrue)]
  120.     private $first_name_ar;
  121.     #[ORM\Column(type'string'length255nullabletrue)]
  122.     private $last_name_ar;
  123.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'children')]
  124.     #[ORM\JoinColumn(nullablefalse)]
  125.     private $season;
  126.     #[ORM\OneToMany(mappedBy'child'targetEntityPointing::class, orphanRemovaltruecascade: ["persist"])]
  127.     #[Groups(['read:child:basic'])]
  128.     private $pointings;
  129.     public function __construct()
  130.     {
  131.         $this->family = new ArrayCollection();
  132.         $this->status ChildStatus::PREINSCRIPTION;
  133.         $this->subscriptions = new ArrayCollection();
  134.         $this->classrooms = new ArrayCollection();
  135.         $this->evenements = new ArrayCollection();
  136.         $this->tasks = new ArrayCollection();
  137.         $this->posts = new ArrayCollection();
  138.         $this->pointings = new ArrayCollection();
  139.     }
  140.     public function __toString()
  141.     {
  142.         return $this->first_name " " $this->last_name;
  143.         ;
  144.     }
  145.     #[Groups(['read:child:basic'])]
  146.     public function getAge(): ?string
  147.     {
  148.         $currentDate date("Y");
  149.         $birthdate date($this->birth_date->format('Y'));
  150.         $age $currentDate $birthdate;
  151.         return ($age 0) ? $age 1;
  152.     }
  153.     public function getAgeMonths(): ?DateInterval
  154.     {
  155.         $now = new DateTime();
  156.         $diff $now->diff($this->birth_date);
  157.         return $diff;
  158.     }
  159.     public function getId(): ?Ulid
  160.     {
  161.         return $this->id;
  162.     }
  163.     public function getFirstName(): ?string
  164.     {
  165.         return $this->first_name;
  166.     }
  167.     public function setFirstName(string $first_name): self
  168.     {
  169.         $this->first_name $first_name;
  170.         return $this;
  171.     }
  172.     public function getLastName(): ?string
  173.     {
  174.         return $this->last_name;
  175.     }
  176.     public function setLastName(string $last_name): self
  177.     {
  178.         $this->last_name $last_name;
  179.         return $this;
  180.     }
  181.     public function getBirthDate(): ?\DateTimeInterface
  182.     {
  183.         return $this->birth_date;
  184.     }
  185.     public function setBirthDate(\DateTimeInterface $birth_date): self
  186.     {
  187.         $this->birth_date $birth_date;
  188.         return $this;
  189.     }
  190.     public function getBirthPlace(): ?string
  191.     {
  192.         return $this->birth_place;
  193.     }
  194.     public function setBirthPlace(?string $birth_place): self
  195.     {
  196.         $this->birth_place $birth_place;
  197.         return $this;
  198.     }
  199.     public function getBlood(): ?string
  200.     {
  201.         return $this->blood;
  202.     }
  203.     public function setBlood(string $blood): self
  204.     {
  205.         $this->blood $blood;
  206.         return $this;
  207.     }
  208.     public function getDiseases(): ?string
  209.     {
  210.         return $this->diseases;
  211.     }
  212.     public function setDiseases(?string $diseases): self
  213.     {
  214.         $this->diseases $diseases;
  215.         return $this;
  216.     }
  217.     public function getAllergies(): ?string
  218.     {
  219.         return $this->allergies;
  220.     }
  221.     public function setAllergies(?string $allergies): self
  222.     {
  223.         $this->allergies $allergies;
  224.         return $this;
  225.     }
  226.     public function getFoodHabit(): ?string
  227.     {
  228.         return $this->food_habit;
  229.     }
  230.     public function setFoodHabit(?string $food_habit): self
  231.     {
  232.         $this->food_habit $food_habit;
  233.         return $this;
  234.     }
  235.     public function getBehavior(): ?string
  236.     {
  237.         return $this->behavior;
  238.     }
  239.     public function setBehavior(?string $behavior): self
  240.     {
  241.         $this->behavior $behavior;
  242.         return $this;
  243.     }
  244.     public function getFears(): ?string
  245.     {
  246.         return $this->fears;
  247.     }
  248.     public function setFears(?string $fears): self
  249.     {
  250.         $this->fears $fears;
  251.         return $this;
  252.     }
  253.     public function getInterests(): ?string
  254.     {
  255.         return $this->interests;
  256.     }
  257.     public function setInterests(?string $interests): self
  258.     {
  259.         $this->interests $interests;
  260.         return $this;
  261.     }
  262.     public function getDescription(): ?string
  263.     {
  264.         return $this->description;
  265.     }
  266.     public function setDescription(?string $description): self
  267.     {
  268.         $this->description $description;
  269.         return $this;
  270.     }
  271.     public function getGender(): ?string
  272.     {
  273.         return $this->gender;
  274.     }
  275.     public function setGender(string $gender): self
  276.     {
  277.         $this->gender $gender;
  278.         return $this;
  279.     }
  280.     public function getStatus(): ?ChildStatus
  281.     {
  282.         return $this->status;
  283.     }
  284.     public function setStatus(ChildStatus $status): self
  285.     {
  286.         $this->status $status;
  287.         return $this;
  288.     }
  289.     public function getPhoto(): ?string
  290.     {
  291.         return $this->photo;
  292.     }
  293.     public function setPhoto(?string $photo): self
  294.     {
  295.         $this->photo $photo;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection<int, FamilyMember>
  300.      */
  301.     public function getFamily(): Collection
  302.     {
  303.         return $this->family;
  304.     }
  305.     public function addFamily(FamilyMember $family): self
  306.     {
  307.         if (!$this->family->contains($family)) {
  308.             $this->family[] = $family;
  309.         }
  310.         return $this;
  311.     }
  312.     public function removeFamily(FamilyMember $family): self
  313.     {
  314.         $this->family->removeElement($family);
  315.         return $this;
  316.     }
  317.     public function getOwner(): ?Company
  318.     {
  319.         return $this->owner;
  320.     }
  321.     public function setOwner(?Company $owner): self
  322.     {
  323.         $this->owner $owner;
  324.         return $this;
  325.     }
  326.     public function getAddress(): ?Location
  327.     {
  328.         return $this->address;
  329.     }
  330.     public function setAddress(?Location $address): self
  331.     {
  332.         $this->address $address;
  333.         return $this;
  334.     }
  335.     /**
  336.      * @return Collection<int, Subscription>
  337.      */
  338.     public function getSubscriptions(): Collection
  339.     {
  340.         return $this->subscriptions;
  341.     }
  342.     public function addSubscription(Subscription $subscription): self
  343.     {
  344.         if (!$this->subscriptions->contains($subscription)) {
  345.             $this->subscriptions[] = $subscription;
  346.             $subscription->setChild($this);
  347.         }
  348.         return $this;
  349.     }
  350.     public function removeSubscription(Subscription $subscription): self
  351.     {
  352.         if ($this->subscriptions->removeElement($subscription)) {
  353.             // set the owning side to null (unless already changed)
  354.             if ($subscription->getChild() === $this) {
  355.                 $subscription->setChild(null);
  356.             }
  357.         }
  358.         return $this;
  359.     }
  360.     /**
  361.      * @return Collection<int, Classroom>
  362.      */
  363.     public function getClassrooms(): Collection
  364.     {
  365.         return $this->classrooms;
  366.     }
  367.     public function addClassroom(Classroom $classroom): self
  368.     {
  369.         if (!$this->classrooms->contains($classroom)) {
  370.             $this->classrooms[] = $classroom;
  371.             $classroom->addChild($this);
  372.         }
  373.         return $this;
  374.     }
  375.     public function removeClassroom(Classroom $classroom): self
  376.     {
  377.         if ($this->classrooms->removeElement($classroom)) {
  378.             $classroom->removeChild($this);
  379.         }
  380.         return $this;
  381.     }
  382.     /**
  383.      * @return Collection<int, Evenement>
  384.      */
  385.     public function getEvenements(): Collection
  386.     {
  387.         return $this->evenements;
  388.     }
  389.     public function addEvenement(Evenement $evenement): self
  390.     {
  391.         if (!$this->evenements->contains($evenement)) {
  392.             $this->evenements[] = $evenement;
  393.             $evenement->addChild($this);
  394.         }
  395.         return $this;
  396.     }
  397.     public function removeEvenement(Evenement $evenement): self
  398.     {
  399.         if ($this->evenements->removeElement($evenement)) {
  400.             $evenement->removeChild($this);
  401.         }
  402.         return $this;
  403.     }
  404.     /**
  405.      * @return Collection<int, Task>
  406.      */
  407.     public function getTasks(): Collection
  408.     {
  409.         return $this->tasks;
  410.     }
  411.     public function addTask(Task $task): self
  412.     {
  413.         if (!$this->tasks->contains($task)) {
  414.             $this->tasks[] = $task;
  415.             $task->addChild($this);
  416.         }
  417.         return $this;
  418.     }
  419.     public function removeTask(Task $task): self
  420.     {
  421.         if ($this->tasks->removeElement($task)) {
  422.             $task->removeChild($this);
  423.         }
  424.         return $this;
  425.     }
  426.     /**
  427.      * @return Collection<int, Post>
  428.      */
  429.     public function getPosts(): Collection
  430.     {
  431.         return $this->posts;
  432.     }
  433.     public function addPost(Post $post): self
  434.     {
  435.         if (!$this->posts->contains($post)) {
  436.             $this->posts[] = $post;
  437.             $post->setChild($this);
  438.         }
  439.         return $this;
  440.     }
  441.     public function removePost(Post $post): self
  442.     {
  443.         if ($this->posts->removeElement($post)) {
  444.             // set the owning side to null (unless already changed)
  445.             if ($post->getChild() === $this) {
  446.                 $post->setChild(null);
  447.             }
  448.         }
  449.         return $this;
  450.     }
  451.     public function getSection(): ?Section
  452.     {
  453.         return $this->section;
  454.     }
  455.     public function setSection(?Section $section): self
  456.     {
  457.         $this->section $section;
  458.         return $this;
  459.     }
  460.     public function getTotalSubscriptions(): float
  461.     {
  462.         $total 0;
  463.         foreach ($this->subscriptions as $subscription) {
  464.             $total += $subscription->getTotalToPay();
  465.         }
  466.         return $total;
  467.     }
  468.     public function getTotalReste(): float
  469.     {
  470.         $total 0;
  471.         foreach ($this->subscriptions as $subscription) {
  472.             $total += $subscription->getRestToPay();
  473.         }
  474.         return $total;
  475.     }
  476.     public function getTotalPayed(): float
  477.     {
  478.         return $this->getTotalSubscriptions() - $this->getTotalReste();
  479.     }
  480.     public function getFirstNameAr(): ?string
  481.     {
  482.         return $this->first_name_ar;
  483.     }
  484.     public function setFirstNameAr(?string $first_name_ar): self
  485.     {
  486.         $this->first_name_ar $first_name_ar;
  487.         return $this;
  488.     }
  489.     public function getLastNameAr(): ?string
  490.     {
  491.         return $this->last_name_ar;
  492.     }
  493.     public function setLastNameAr(?string $last_name_ar): self
  494.     {
  495.         $this->last_name_ar $last_name_ar;
  496.         return $this;
  497.     }
  498.     public function getSeason(): ?Season
  499.     {
  500.         return $this->season;
  501.     }
  502.     public function setSeason(?Season $season): self
  503.     {
  504.         $this->season $season;
  505.         return $this;
  506.     }
  507.     /**
  508.      * @return Collection<int, Pointing>
  509.      */
  510.     public function getPointings(): Collection
  511.     {
  512.         return $this->pointings;
  513.     }
  514.     public function addPointing(Pointing $pointing): self
  515.     {
  516.         if (!$this->pointings->contains($pointing)) {
  517.             $this->pointings[] = $pointing;
  518.             $pointing->setChild($this);
  519.         }
  520.         return $this;
  521.     }
  522.     public function removePointing(Pointing $pointing): self
  523.     {
  524.         if ($this->pointings->removeElement($pointing)) {
  525.             // set the owning side to null (unless already changed)
  526.             if ($pointing->getChild() === $this) {
  527.                 $pointing->setChild(null);
  528.             }
  529.         }
  530.         return $this;
  531.     }
  532. }