src/Entity/Stat/Report.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Stat;
  3. use App\Entity\HearingBrand;
  4. use App\Entity\Store;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\Stat\ReportRepository")
  10.  * @ORM\Table(name="stat_report")
  11.  * @ORM\HasLifecycleCallbacks()
  12.  */
  13. class Report
  14. {
  15.     const TYPE_MONTHLY 'monthly';
  16.     const TYPE_YEARLY 'yearly';
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=190, unique=true)
  25.      */
  26.     private $token;
  27.     /**
  28.      * @ORM\Column(type="datetime")
  29.      * @Gedmo\Timestampable(on="update")
  30.      */
  31.     private $generatedDate;
  32.     /**
  33.      * @ORM\Column(type="string", length=25)
  34.      */
  35.     private $type;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Store")
  38.      */
  39.     private $store;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\HearingBrand", inversedBy="reports")
  42.      */
  43.     private $brand;
  44.     /**
  45.      * @ORM\Column(type="date")
  46.      */
  47.     private $startDate;
  48.     /**
  49.      * @ORM\Column(type="date")
  50.      */
  51.     private $endDate;
  52.     /**
  53.      * @ORM\Column(type="integer")
  54.      */
  55.     private $nbDisplay;
  56.     /**
  57.      * @ORM\Column(type="integer")
  58.      */
  59.     private $nbPhoneDisplay;
  60.     /**
  61.      * @ORM\Column(type="integer")
  62.      */
  63.     private $nbCheckup;
  64.     /**
  65.      * @ORM\Column(type="integer")
  66.      */
  67.     private $nbAppointement;
  68.     /**
  69.      * @ORM\OneToOne(targetEntity="App\Entity\Stat\Report", inversedBy="nextReport")
  70.      */
  71.     private $previousReport;
  72.     /**
  73.      * @ORM\OneToOne(targetEntity="App\Entity\Stat\Report", mappedBy="previousReport")
  74.      */
  75.     private $nextReport;
  76.     public static function getAvailableTypes(){
  77.         return [
  78.             self::TYPE_MONTHLY=>self::TYPE_MONTHLY,
  79.             self::TYPE_YEARLY=>self::TYPE_YEARLY,
  80.         ];
  81.     }
  82.     /**
  83.      * Représente l'entité dans le BO
  84.      * @return string
  85.      */
  86.     public function getLabel()
  87.     {
  88.         return 'Rapport de ' $this->getStartDate()->format('m/y');
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getType(): ?string
  95.     {
  96.         return $this->type;
  97.     }
  98.     public function setType(string $type): self
  99.     {
  100.         $this->type $type;
  101.         return $this;
  102.     }
  103.     public function getStore(): ?Store
  104.     {
  105.         return $this->store;
  106.     }
  107.     public function setStore(?Store $store): self
  108.     {
  109.         $this->store $store;
  110.         return $this;
  111.     }
  112.     public function getStartDate(): ?\DateTimeInterface
  113.     {
  114.         return $this->startDate;
  115.     }
  116.     public function setStartDate(\DateTimeInterface $startDate): self
  117.     {
  118.         $this->startDate $startDate;
  119.         return $this;
  120.     }
  121.     public function getEndDate(): ?\DateTimeInterface
  122.     {
  123.         return $this->endDate;
  124.     }
  125.     public function setEndDate(\DateTimeInterface $endDate): self
  126.     {
  127.         $this->endDate $endDate;
  128.         return $this;
  129.     }
  130.     public function getNbDisplay(): ?int
  131.     {
  132.         return $this->nbDisplay;
  133.     }
  134.     public function setNbDisplay(int $nbDisplay): self
  135.     {
  136.         $this->nbDisplay $nbDisplay;
  137.         return $this;
  138.     }
  139.     public function getNbPhoneDisplay(): ?int
  140.     {
  141.         return $this->nbPhoneDisplay;
  142.     }
  143.     public function setNbPhoneDisplay(int $nbPhoneDisplay): self
  144.     {
  145.         $this->nbPhoneDisplay $nbPhoneDisplay;
  146.         return $this;
  147.     }
  148.     public function getNbCheckup(): ?int
  149.     {
  150.         return $this->nbCheckup;
  151.     }
  152.     public function setNbCheckup(int $nbCheckup): self
  153.     {
  154.         $this->nbCheckup $nbCheckup;
  155.         return $this;
  156.     }
  157.     public function getNbAppointement(): ?int
  158.     {
  159.         return $this->nbAppointement;
  160.     }
  161.     public function setNbAppointement(int $nbAppointement): self
  162.     {
  163.         $this->nbAppointement $nbAppointement;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return mixed
  168.      */
  169.     public function getGeneratedDate()
  170.     {
  171.         return $this->generatedDate;
  172.     }
  173.     /**
  174.      * @param mixed $generatedDate
  175.      */
  176.     public function setGeneratedDate($generatedDate): void
  177.     {
  178.         $this->generatedDate $generatedDate;
  179.     }
  180.     /**
  181.      * @return mixed
  182.      */
  183.     public function getBrand()
  184.     {
  185.         return $this->brand;
  186.     }
  187.     /**
  188.      * @param mixed $brand
  189.      */
  190.     public function setBrand($brand): void
  191.     {
  192.         $this->brand $brand;
  193.     }
  194.     public function hasExpired()
  195.     {
  196.         $now = new DateTime();
  197.         //if report has been generated afetr its enddate, not expired
  198.         if ($this->getEndDate() > $this->getGeneratedDate()) {
  199.             //if generated less than an hour ago, still valid
  200.             $diff $now->diff($this->getGeneratedDate());
  201.             $hours $diff->h;
  202.             $hours $hours + ($diff->days 24);
  203.             if ($hours >= 1) {
  204.                 return true;
  205.             }
  206.         }
  207.         return false;
  208.     }
  209.     /**
  210.      * @return mixed
  211.      */
  212.     public function getToken()
  213.     {
  214.         return $this->token;
  215.     }
  216.     /**
  217.      * @ORM\PrePersist
  218.      */
  219.     public function initToken(): void
  220.     {
  221.         $token time() . '-' rand(11000);
  222.         if ($this->getBrand()) {
  223.             $token .= 'b' $this->getBrand()->getId();
  224.         } elseif ($this->getStore()) {
  225.             $token .= 's' $this->getStore()->getId();
  226.         }
  227.         $this->token md5($token);
  228.     }
  229.     /**
  230.      * @return mixed
  231.      */
  232.     public function getPreviousReport()
  233.     {
  234.         return $this->previousReport;
  235.     }
  236.     /**
  237.      * @param mixed $previousReport
  238.      */
  239.     public function setPreviousReport($previousReport): void
  240.     {
  241.         $this->previousReport $previousReport;
  242.     }
  243.     /**
  244.      * @return mixed
  245.      */
  246.     public function getNextReport()
  247.     {
  248.         return $this->nextReport;
  249.     }
  250.     /**
  251.      * @param mixed $nextReport
  252.      */
  253.     public function setNextReport($nextReport): void
  254.     {
  255.         $this->nextReport $nextReport;
  256.     }
  257.     public function setToken(string $token): self
  258.     {
  259.         $this->token $token;
  260.         return $this;
  261.     }
  262. }