src/Entity/EstimatedReach.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * @ORM\Entity(repositoryClass="App\Repository\EstimatedReachRepository")
  6.  */
  7. class EstimatedReach
  8. {
  9.     /**
  10.      * @ORM\Id()
  11.      * @ORM\GeneratedValue()
  12.      * @ORM\Column(type="integer")
  13.      */
  14.     private $id;
  15.     /**
  16.      * @ORM\Column(type="date")
  17.      */
  18.     private $dateFrom;
  19.     /**
  20.      * @ORM\Column(type="date")
  21.      */
  22.     private $dateTo;
  23.     /**
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $nbAt5 0;
  27.     /**
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $nbAt20 0;
  31.     /**
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $nbAt30 0;
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getNbAt5(): ?int
  40.     {
  41.         return $this->nbAt5;
  42.     }
  43.     public function getAverageReachAt5(): ?float
  44.     {
  45.         return $this->getAverageReach($this->nbAt5);
  46.     }
  47.     public function setNbAt5(int $nbAt5): self
  48.     {
  49.         $this->nbAt5 $nbAt5;
  50.         return $this;
  51.     }
  52.     public function getNbAt20(): ?int
  53.     {
  54.         return $this->nbAt20;
  55.     }
  56.     public function getAverageReachAt20(): ?float
  57.     {
  58.         return $this->getAverageReach($this->nbAt20);
  59.     }
  60.     public function setNbAt20(int $nbAt20): self
  61.     {
  62.         $this->nbAt20 $nbAt20;
  63.         return $this;
  64.     }
  65.     public function getNbAt30(): ?int
  66.     {
  67.         return $this->nbAt30;
  68.     }
  69.     public function getAverageReachAt30(): ?float
  70.     {
  71.         return $this->getAverageReach($this->nbAt30);
  72.     }
  73.     public function setNbAt30(int $nbAt30): self
  74.     {
  75.         $this->nbAt30 $nbAt30;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return mixed
  80.      */
  81.     public function getDateFrom()
  82.     {
  83.         return $this->dateFrom;
  84.     }
  85.     /**
  86.      * @param mixed $dateFrom
  87.      */
  88.     public function setDateFrom($dateFrom): void
  89.     {
  90.         $this->dateFrom $dateFrom;
  91.     }
  92.     /**
  93.      * @return mixed
  94.      */
  95.     public function getDateTo()
  96.     {
  97.         return $this->dateTo;
  98.     }
  99.     /**
  100.      * @param mixed $dateTo
  101.      */
  102.     public function setDateTo($dateTo): void
  103.     {
  104.         $this->dateTo $dateTo;
  105.     }
  106.     /**
  107.      * Return the averga nb of reach by month
  108.      * @param int $nb
  109.      * @return float|null
  110.      */
  111.     private function getAverageReach(int $nb): ?float
  112.     {
  113.         $nbDays = (int)$this->dateTo->diff($this->dateFrom)->format('%a');
  114.         $average $nb / ($nbDays/30.5);
  115.         $average round($average);
  116.         //display 5 at minumum
  117.         if($average<=5){
  118.             $average 5;
  119.         }
  120.         return $average;
  121.     }
  122. }