src/Entity/Period.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimestampableTrait;
  4. use App\Repository\PeriodRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClass: PeriodRepository::class)]
  9. #[ORM\Table(name: 'period')]
  10. class Period
  11. {
  12.     use TimestampableTrait;
  13.     public const ROUND_UP = 'up';
  14.     public const ROUND_DOWN = 'down';
  15.     public const ROUND_HALF_UP = 'half_up';
  16.     public const ROUND_HALF_DOWN = 'half_down';
  17.     public const ROUND_TO_ZERO = 0;
  18.     public const ROUND_TO_FIVE = 5;
  19.     #[ORM\Column(name: 'id', type: 'integer')]
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  22.     private ?int $id = null;
  23.     #[ORM\Column(name: 'start_date', type: 'date')]
  24.     private ?\DateTimeInterface $start_date = null;
  25.     #[ORM\Column(name: 'end_date', type: 'date')]
  26.     private ?\DateTimeInterface $end_date = null;
  27.     #[ORM\Column(name: 'month_payment', type: 'string', length: 255, nullable: true)]
  28.     private ?string $month_payment = null;
  29.     #[ORM\Column(type: 'integer')]
  30.     private ?int $minExams = null;
  31.     #[ORM\Column(type: 'float')]
  32.     private ?float $pointsPerExam = null;
  33.     #[ORM\Column(type: 'float')]
  34.     private ?float $eurosPerPoint = null;
  35.     #[ORM\Column(type: 'integer')]
  36.     private ?int $roundTo = null;
  37.     #[ORM\Column(type: 'string', length: 32)]
  38.     private ?string $roundDirection = null;
  39.     #[ORM\OneToMany(mappedBy: 'Period', targetEntity: Calculation::class)]
  40.     private Collection $calculations;
  41.     #[ORM\OneToMany(mappedBy: 'period', targetEntity: SubPeriod::class, orphanRemoval: true)]
  42.     #[ORM\OrderBy(['start_date' => 'ASC'])]
  43.     private Collection $subPeriods;
  44.     public function __construct()
  45.     {
  46.         $this->calculations = new ArrayCollection();
  47.         $this->subPeriods = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function setId(int $id): void
  54.     {
  55.         $this->id = $id;
  56.     }
  57.     public function getStartDate(): ?\DateTimeInterface
  58.     {
  59.         return $this->start_date;
  60.     }
  61.     public function setStartDate(mixed $start_date): self
  62.     {
  63.         $this->start_date = $start_date;
  64.         return $this;
  65.     }
  66.     public function getEndDate(): ?\DateTimeInterface
  67.     {
  68.         return $this->end_date;
  69.     }
  70.     public function setEndDate(?\DateTimeInterface $end_date): self
  71.     {
  72.         $this->end_date = $end_date;
  73.         return $this;
  74.     }
  75.     public function getMonthPayment(): ?string
  76.     {
  77.         return $this->month_payment;
  78.     }
  79.     public function setMonthPayment(?string $month_payment): self
  80.     {
  81.         $this->month_payment = $month_payment;
  82.         return $this;
  83.     }
  84.     public function getMinExams(): ?int
  85.     {
  86.         return $this->minExams;
  87.     }
  88.     public function setMinExams(int $minExams): self
  89.     {
  90.         $this->minExams = $minExams;
  91.         return $this;
  92.     }
  93.     public function getPointsPerExam(): ?float
  94.     {
  95.         return $this->pointsPerExam;
  96.     }
  97.     public function setPointsPerExam(float $pointsPerExam): self
  98.     {
  99.         $this->pointsPerExam = $pointsPerExam;
  100.         return $this;
  101.     }
  102.     public function getEurosPerPoint(): ?float
  103.     {
  104.         return $this->eurosPerPoint;
  105.     }
  106.     public function setEurosPerPoint(float $eurosPerPoint): self
  107.     {
  108.         $this->eurosPerPoint = $eurosPerPoint;
  109.         return $this;
  110.     }
  111.     public function getRoundTo(): ?int
  112.     {
  113.         if (!in_array($this->roundTo, [self::ROUND_TO_FIVE, self::ROUND_TO_ZERO])) {
  114.             $this->roundTo = self::ROUND_TO_ZERO;
  115.         }
  116.         return $this->roundTo;
  117.     }
  118.     public function setRoundTo(int $roundTo): self
  119.     {
  120.         $roundTo = (int) $roundTo;
  121.         if (!in_array($this->roundTo, [self::ROUND_TO_FIVE, self::ROUND_TO_ZERO])) {
  122.             $roundTo = self::ROUND_TO_ZERO;
  123.         }
  124.         $this->roundTo = $roundTo;
  125.         return $this;
  126.     }
  127.     public function getRoundDirection(): ?string
  128.     {
  129.         $this->roundDirection = trim(strtolower((string) $this->roundDirection));
  130.         if (!in_array($this->roundDirection, [self::ROUND_DOWN, self::ROUND_UP, self::ROUND_HALF_DOWN, self::ROUND_HALF_UP])) {
  131.             $this->roundDirection = self::ROUND_UP;
  132.         }
  133.         return $this->roundDirection;
  134.     }
  135.     public function setRoundDirection(string $roundDirection): self
  136.     {
  137.         $roundDirection = trim(strtolower($roundDirection));
  138.         if (!in_array($roundDirection, [self::ROUND_DOWN, self::ROUND_UP, self::ROUND_HALF_DOWN, self::ROUND_HALF_UP])) {
  139.             $roundDirection = self::ROUND_UP;
  140.         }
  141.         $this->roundDirection = $roundDirection;
  142.         return $this;
  143.     }
  144.     public function getCalculations(): Collection
  145.     {
  146.         return $this->calculations;
  147.     }
  148.     public function addCalculation(Calculation $calculation): self
  149.     {
  150.         if (!$this->calculations->contains($calculation)) {
  151.             $this->calculations[] = $calculation;
  152.             $calculation->setPeriod($this);
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeCalculation(Calculation $calculation): self
  157.     {
  158.         if ($this->calculations->removeElement($calculation)) {
  159.             // set the owning side to null (unless already changed)
  160.             if ($calculation->getPeriod() === $this) {
  161.                 $calculation->setPeriod(null);
  162.             }
  163.         }
  164.         return $this;
  165.     }
  166.     public function getSubPeriods(): Collection
  167.     {
  168.         return $this->subPeriods;
  169.     }
  170.     public function addSubPeriod(SubPeriod $subPeriod): self
  171.     {
  172.         if (!$this->subPeriods->contains($subPeriod)) {
  173.             $this->subPeriods[] = $subPeriod;
  174.             $subPeriod->setPeriod($this);
  175.         }
  176.         return $this;
  177.     }
  178.     public function removeSubPeriod(SubPeriod $subPeriod): self
  179.     {
  180.         if ($this->subPeriods->removeElement($subPeriod)) {
  181.             // set the owning side to null (unless already changed)
  182.             if ($subPeriod->getPeriod() === $this) {
  183.                 $subPeriod->setPeriod(null);
  184.             }
  185.         }
  186.         return $this;
  187.     }
  188. }