<?phpnamespace App\Entity;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\EstimatedReachRepository") */class EstimatedReach{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="date") */ private $dateFrom; /** * @ORM\Column(type="date") */ private $dateTo; /** * @ORM\Column(type="integer") */ private $nbAt5 = 0; /** * @ORM\Column(type="integer") */ private $nbAt20 = 0; /** * @ORM\Column(type="integer") */ private $nbAt30 = 0; public function getId(): ?int { return $this->id; } public function getNbAt5(): ?int { return $this->nbAt5; } public function getAverageReachAt5(): ?float { return $this->getAverageReach($this->nbAt5); } public function setNbAt5(int $nbAt5): self { $this->nbAt5 = $nbAt5; return $this; } public function getNbAt20(): ?int { return $this->nbAt20; } public function getAverageReachAt20(): ?float { return $this->getAverageReach($this->nbAt20); } public function setNbAt20(int $nbAt20): self { $this->nbAt20 = $nbAt20; return $this; } public function getNbAt30(): ?int { return $this->nbAt30; } public function getAverageReachAt30(): ?float { return $this->getAverageReach($this->nbAt30); } public function setNbAt30(int $nbAt30): self { $this->nbAt30 = $nbAt30; return $this; } /** * @return mixed */ public function getDateFrom() { return $this->dateFrom; } /** * @param mixed $dateFrom */ public function setDateFrom($dateFrom): void { $this->dateFrom = $dateFrom; } /** * @return mixed */ public function getDateTo() { return $this->dateTo; } /** * @param mixed $dateTo */ public function setDateTo($dateTo): void { $this->dateTo = $dateTo; } /** * Return the averga nb of reach by month * @param int $nb * @return float|null */ private function getAverageReach(int $nb): ?float { $nbDays = (int)$this->dateTo->diff($this->dateFrom)->format('%a'); $average = $nb / ($nbDays/30.5); $average = round($average); //display 5 at minumum if($average<=5){ $average = 5; } return $average; }}