src/Entity/QuotaTier.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\QuotaTierPeriod;
  4. use App\Repository\QuotaPeriodRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. #[ORM\Entity(repositoryClassQuotaPeriodRepository::class)]
  10. class QuotaTier
  11. {
  12.     use TimestampableEntity;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $name null;
  19.     #[ORM\ManyToOne(inversedBy'quotaTiers')]
  20.     private ?Quota $quota null;
  21.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'children')]
  22.     private ?self $parent null;
  23.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade: ['persist''remove'])]
  24.     private Collection $children;
  25.     
  26.     #[ORM\Column]
  27.     private ?float $amount null;
  28.     #[ORM\Column(length255enumTypeQuotaTierPeriod::class)]
  29.     private ?QuotaTierPeriod $period null;
  30.     #[ORM\ManyToOne(inversedBy'quotaTiers')]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private ?Year $year null;
  33.     public function __construct()
  34.     {
  35.         $this->children = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(string $name): self
  46.     {
  47.         $this->name $name;
  48.         return $this;
  49.     }
  50.     public function getQuota(): ?Quota
  51.     {
  52.         return $this->quota;
  53.     }
  54.     public function setQuota(?Quota $quota): self
  55.     {
  56.         $this->quota $quota;
  57.         return $this;
  58.     }
  59.     public function getParent(): ?self
  60.     {
  61.         return $this->parent;
  62.     }
  63.     public function setParent(?self $parent): self
  64.     {
  65.         $this->parent $parent;
  66.         return $this;
  67.     }
  68.     /**
  69.      * @return Collection<int, self>
  70.      */
  71.     public function getChildren(): Collection
  72.     {
  73.         return $this->children;
  74.     }
  75.     public function setChildren(): self
  76.     {
  77.         $debug 0;
  78.     }
  79.     public function addChild(self $child): self
  80.     {
  81.         if (!$this->children->contains($child)) {
  82.             $this->children->add($child);
  83.             $child->setParent($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeChild(self $child): self
  88.     {
  89.         if ($this->children->removeElement($child)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($child->getParent() === $this) {
  92.                 $child->setParent(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     public function getAmount(): ?float
  98.     {
  99.         return $this->amount;
  100.     }
  101.     public function setAmount(float $amount): self
  102.     {
  103.         $this->amount $amount;
  104.         return $this;
  105.     }
  106.     public function __toString()
  107.     {
  108.         $check $this;
  109.         while(!$check->getQuota()) {
  110.             $check $check->getParent();
  111.         }
  112.         return $check->getQuota()->getName() . ' - ' $this->getName();
  113.     }
  114.     public function getPeriod(): ?QuotaTierPeriod
  115.     {
  116.         return $this->period;
  117.     }
  118.     public function setPeriod(?QuotaTierPeriod $period): self
  119.     {
  120.         $this->period $period;
  121.         return $this;
  122.     }
  123.     public function getYear(): ?Year
  124.     {
  125.         return $this->year;
  126.     }
  127.     public function setYear(?Year $year): self
  128.     {
  129.         $this->year $year;
  130.         return $this;
  131.     }
  132. }