src/Entity/Child.php line 49
<?php
namespace App\Entity;
use App\Entity\enums\ChildStatus;
use DateTime;
use DateInterval;
use App\Entity\Classroom;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ChildRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ChildRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => [
'read:child:basic',
'read:section:basic',
'read:pointing:basic'
]
]
],
],
// itemOperations: [
// 'get' => [
// 'normalization_context' => [
// 'groups' => [
// 'read:child:basic',
// 'read:section:basic',
// 'read:pointing:basic',
// 'read:subscription:basic',
// 'read:familymember:basic'
// ]
// ]
// ],
// ],
)]
class Child
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:child:basic', 'read:child:export'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:child:basic', 'read:child:export'])]
private $first_name;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:child:basic', 'read:child:export'])]
private $last_name;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:child:basic', 'read:child:export'])]
private $gender;
#[ORM\Column(type: 'date')]
#[Groups(['read:child:basic', 'read:child:export'])]
private $birth_date;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:child:basic', 'read:child:export'])]
private $birth_place;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:child:basic', 'read:child:export'])]
private $blood;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $diseases;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $allergies;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $food_habit;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $behavior;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $fears;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:child:export'])]
private $interests;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:child:export'])]
private $description;
#[ORM\Column(type: 'string', length: 255, enumType: ChildStatus::class)]
private $status;
#[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'children')]
#[Groups(['read:child:export', 'read:child:basic'])]
private $section;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:child:basic'])]
private $photo;
#[ORM\ManyToMany(targetEntity: FamilyMember::class, inversedBy: 'children', cascade: ['persist'])]
private $family;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'children')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\OneToOne(inversedBy: 'child', targetEntity: Location::class, cascade: ['persist', 'remove'])]
private $address;
#[ORM\OneToMany(mappedBy: 'child', targetEntity: Subscription::class, orphanRemoval: true)]
private $subscriptions;
#[ORM\ManyToMany(targetEntity: Classroom::class, mappedBy: 'children')]
private $classrooms;
#[ORM\ManyToMany(targetEntity: Evenement::class, mappedBy: 'children')]
private $evenements;
#[ORM\ManyToMany(targetEntity: Task::class, mappedBy: 'children')]
private $tasks;
#[ORM\OneToMany(mappedBy: 'child', targetEntity: Post::class, orphanRemoval: true)]
private $posts;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $first_name_ar;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $last_name_ar;
#[ORM\ManyToOne(targetEntity: Season::class, inversedBy: 'children')]
#[ORM\JoinColumn(nullable: false)]
private $season;
#[ORM\OneToMany(mappedBy: 'child', targetEntity: Pointing::class, orphanRemoval: true, cascade: ["persist"])]
#[Groups(['read:child:basic'])]
private $pointings;
public function __construct()
{
$this->family = new ArrayCollection();
$this->status = ChildStatus::PREINSCRIPTION;
$this->subscriptions = new ArrayCollection();
$this->classrooms = new ArrayCollection();
$this->evenements = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->pointings = new ArrayCollection();
}
public function __toString()
{
return $this->first_name . " " . $this->last_name;
;
}
#[Groups(['read:child:basic'])]
public function getAge(): ?string
{
$currentDate = date("Y");
$birthdate = date($this->birth_date->format('Y'));
$age = $currentDate - $birthdate;
return ($age > 0) ? $age : 1;
}
public function getAgeMonths(): ?DateInterval
{
$now = new DateTime();
$diff = $now->diff($this->birth_date);
return $diff;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->first_name;
}
public function setFirstName(string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
public function getLastName(): ?string
{
return $this->last_name;
}
public function setLastName(string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birth_date;
}
public function setBirthDate(\DateTimeInterface $birth_date): self
{
$this->birth_date = $birth_date;
return $this;
}
public function getBirthPlace(): ?string
{
return $this->birth_place;
}
public function setBirthPlace(?string $birth_place): self
{
$this->birth_place = $birth_place;
return $this;
}
public function getBlood(): ?string
{
return $this->blood;
}
public function setBlood(string $blood): self
{
$this->blood = $blood;
return $this;
}
public function getDiseases(): ?string
{
return $this->diseases;
}
public function setDiseases(?string $diseases): self
{
$this->diseases = $diseases;
return $this;
}
public function getAllergies(): ?string
{
return $this->allergies;
}
public function setAllergies(?string $allergies): self
{
$this->allergies = $allergies;
return $this;
}
public function getFoodHabit(): ?string
{
return $this->food_habit;
}
public function setFoodHabit(?string $food_habit): self
{
$this->food_habit = $food_habit;
return $this;
}
public function getBehavior(): ?string
{
return $this->behavior;
}
public function setBehavior(?string $behavior): self
{
$this->behavior = $behavior;
return $this;
}
public function getFears(): ?string
{
return $this->fears;
}
public function setFears(?string $fears): self
{
$this->fears = $fears;
return $this;
}
public function getInterests(): ?string
{
return $this->interests;
}
public function setInterests(?string $interests): self
{
$this->interests = $interests;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getStatus(): ?ChildStatus
{
return $this->status;
}
public function setStatus(ChildStatus $status): self
{
$this->status = $status;
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @return Collection<int, FamilyMember>
*/
public function getFamily(): Collection
{
return $this->family;
}
public function addFamily(FamilyMember $family): self
{
if (!$this->family->contains($family)) {
$this->family[] = $family;
}
return $this;
}
public function removeFamily(FamilyMember $family): self
{
$this->family->removeElement($family);
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
public function getAddress(): ?Location
{
return $this->address;
}
public function setAddress(?Location $address): self
{
$this->address = $address;
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setChild($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getChild() === $this) {
$subscription->setChild(null);
}
}
return $this;
}
/**
* @return Collection<int, Classroom>
*/
public function getClassrooms(): Collection
{
return $this->classrooms;
}
public function addClassroom(Classroom $classroom): self
{
if (!$this->classrooms->contains($classroom)) {
$this->classrooms[] = $classroom;
$classroom->addChild($this);
}
return $this;
}
public function removeClassroom(Classroom $classroom): self
{
if ($this->classrooms->removeElement($classroom)) {
$classroom->removeChild($this);
}
return $this;
}
/**
* @return Collection<int, Evenement>
*/
public function getEvenements(): Collection
{
return $this->evenements;
}
public function addEvenement(Evenement $evenement): self
{
if (!$this->evenements->contains($evenement)) {
$this->evenements[] = $evenement;
$evenement->addChild($this);
}
return $this;
}
public function removeEvenement(Evenement $evenement): self
{
if ($this->evenements->removeElement($evenement)) {
$evenement->removeChild($this);
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->addChild($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
$task->removeChild($this);
}
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setChild($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getChild() === $this) {
$post->setChild(null);
}
}
return $this;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
public function getTotalSubscriptions(): float
{
$total = 0;
foreach ($this->subscriptions as $subscription) {
$total += $subscription->getTotalToPay();
}
return $total;
}
public function getTotalReste(): float
{
$total = 0;
foreach ($this->subscriptions as $subscription) {
$total += $subscription->getRestToPay();
}
return $total;
}
public function getTotalPayed(): float
{
return $this->getTotalSubscriptions() - $this->getTotalReste();
}
public function getFirstNameAr(): ?string
{
return $this->first_name_ar;
}
public function setFirstNameAr(?string $first_name_ar): self
{
$this->first_name_ar = $first_name_ar;
return $this;
}
public function getLastNameAr(): ?string
{
return $this->last_name_ar;
}
public function setLastNameAr(?string $last_name_ar): self
{
$this->last_name_ar = $last_name_ar;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
/**
* @return Collection<int, Pointing>
*/
public function getPointings(): Collection
{
return $this->pointings;
}
public function addPointing(Pointing $pointing): self
{
if (!$this->pointings->contains($pointing)) {
$this->pointings[] = $pointing;
$pointing->setChild($this);
}
return $this;
}
public function removePointing(Pointing $pointing): self
{
if ($this->pointings->removeElement($pointing)) {
// set the owning side to null (unless already changed)
if ($pointing->getChild() === $this) {
$pointing->setChild(null);
}
}
return $this;
}
}