<?php
namespace App\Entity;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\PeriodRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PeriodRepository::class)]
#[ORM\Table(name: 'period')]
class Period
{
use TimestampableTrait;
public const ROUND_UP = 'up';
public const ROUND_DOWN = 'down';
public const ROUND_HALF_UP = 'half_up';
public const ROUND_HALF_DOWN = 'half_down';
public const ROUND_TO_ZERO = 0;
public const ROUND_TO_FIVE = 5;
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
#[ORM\Column(name: 'start_date', type: 'date')]
private ?\DateTimeInterface $start_date = null;
#[ORM\Column(name: 'end_date', type: 'date')]
private ?\DateTimeInterface $end_date = null;
#[ORM\Column(name: 'month_payment', type: 'string', length: 255, nullable: true)]
private ?string $month_payment = null;
#[ORM\Column(type: 'integer')]
private ?int $minExams = null;
#[ORM\Column(type: 'float')]
private ?float $pointsPerExam = null;
#[ORM\Column(type: 'float')]
private ?float $eurosPerPoint = null;
#[ORM\Column(type: 'integer')]
private ?int $roundTo = null;
#[ORM\Column(type: 'string', length: 32)]
private ?string $roundDirection = null;
#[ORM\OneToMany(mappedBy: 'Period', targetEntity: Calculation::class)]
private Collection $calculations;
#[ORM\OneToMany(mappedBy: 'period', targetEntity: SubPeriod::class, orphanRemoval: true)]
#[ORM\OrderBy(['start_date' => 'ASC'])]
private Collection $subPeriods;
public function __construct()
{
$this->calculations = new ArrayCollection();
$this->subPeriods = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->start_date;
}
public function setStartDate(mixed $start_date): self
{
$this->start_date = $start_date;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->end_date;
}
public function setEndDate(?\DateTimeInterface $end_date): self
{
$this->end_date = $end_date;
return $this;
}
public function getMonthPayment(): ?string
{
return $this->month_payment;
}
public function setMonthPayment(?string $month_payment): self
{
$this->month_payment = $month_payment;
return $this;
}
public function getMinExams(): ?int
{
return $this->minExams;
}
public function setMinExams(int $minExams): self
{
$this->minExams = $minExams;
return $this;
}
public function getPointsPerExam(): ?float
{
return $this->pointsPerExam;
}
public function setPointsPerExam(float $pointsPerExam): self
{
$this->pointsPerExam = $pointsPerExam;
return $this;
}
public function getEurosPerPoint(): ?float
{
return $this->eurosPerPoint;
}
public function setEurosPerPoint(float $eurosPerPoint): self
{
$this->eurosPerPoint = $eurosPerPoint;
return $this;
}
public function getRoundTo(): ?int
{
if (!in_array($this->roundTo, [self::ROUND_TO_FIVE, self::ROUND_TO_ZERO])) {
$this->roundTo = self::ROUND_TO_ZERO;
}
return $this->roundTo;
}
public function setRoundTo(int $roundTo): self
{
$roundTo = (int) $roundTo;
if (!in_array($this->roundTo, [self::ROUND_TO_FIVE, self::ROUND_TO_ZERO])) {
$roundTo = self::ROUND_TO_ZERO;
}
$this->roundTo = $roundTo;
return $this;
}
public function getRoundDirection(): ?string
{
$this->roundDirection = trim(strtolower((string) $this->roundDirection));
if (!in_array($this->roundDirection, [self::ROUND_DOWN, self::ROUND_UP, self::ROUND_HALF_DOWN, self::ROUND_HALF_UP])) {
$this->roundDirection = self::ROUND_UP;
}
return $this->roundDirection;
}
public function setRoundDirection(string $roundDirection): self
{
$roundDirection = trim(strtolower($roundDirection));
if (!in_array($roundDirection, [self::ROUND_DOWN, self::ROUND_UP, self::ROUND_HALF_DOWN, self::ROUND_HALF_UP])) {
$roundDirection = self::ROUND_UP;
}
$this->roundDirection = $roundDirection;
return $this;
}
public function getCalculations(): Collection
{
return $this->calculations;
}
public function addCalculation(Calculation $calculation): self
{
if (!$this->calculations->contains($calculation)) {
$this->calculations[] = $calculation;
$calculation->setPeriod($this);
}
return $this;
}
public function removeCalculation(Calculation $calculation): self
{
if ($this->calculations->removeElement($calculation)) {
// set the owning side to null (unless already changed)
if ($calculation->getPeriod() === $this) {
$calculation->setPeriod(null);
}
}
return $this;
}
public function getSubPeriods(): Collection
{
return $this->subPeriods;
}
public function addSubPeriod(SubPeriod $subPeriod): self
{
if (!$this->subPeriods->contains($subPeriod)) {
$this->subPeriods[] = $subPeriod;
$subPeriod->setPeriod($this);
}
return $this;
}
public function removeSubPeriod(SubPeriod $subPeriod): self
{
if ($this->subPeriods->removeElement($subPeriod)) {
// set the owning side to null (unless already changed)
if ($subPeriod->getPeriod() === $this) {
$subPeriod->setPeriod(null);
}
}
return $this;
}
}