src/Entity/ReportSnapshot.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Timestampable\Traits\TimestampableEntity;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\ReportSnapshotRepository")
  9.  * @ORM\Table(name="`report_snapshot`")
  10.  */
  11. class ReportSnapshot
  12. {
  13.     use TimestampableEntity;
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private ?int $id null;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity="App\Entity\Report", inversedBy="snapshots")
  22.      * @ORM\JoinColumn(name="report_id", referencedColumnName="id")
  23.      */
  24.     private Report $report;
  25.     /**
  26.      * @ORM\Column(type="date", nullable=true)
  27.      */
  28.     private ?\DateTime $periodStart null;
  29.     /**
  30.      * @ORM\Column(type="date", nullable=true)
  31.      */
  32.     private ?\DateTime $periodEnd null;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity="App\Entity\ReportCountryStatistic", mappedBy="snapshot", cascade={"persist", "remove"}, orphanRemoval=true)
  35.      */
  36.     private ?Collection $countryStatistics;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity="App\Entity\ReportPageStatistic", mappedBy="snapshot", cascade={"persist", "remove"}, orphanRemoval=true)
  39.      * @ORM\OrderBy({"tCO2" = "DESC"})
  40.      */
  41.     private ?Collection $pageStatistics;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     protected ?\DateTime $completedAt null;
  46.     /**
  47.      * @ORM\Column(type="float", nullable=true)
  48.      */
  49.     private ?float $views null;
  50.     /**
  51.      * @ORM\Column(type="float", nullable=true)
  52.      */
  53.     private ?float $tCO2 null;
  54.     /**
  55.      * @ORM\Column(type="float", nullable=true)
  56.      */
  57.     private ?float $kWh null;
  58.     /**
  59.      * @ORM\Column(type="float", nullable=true)
  60.      */
  61.     private ?float $tCO2Device null;
  62.     /**
  63.      * @ORM\Column(type="float", nullable=true)
  64.      */
  65.     private ?float $tCO2Network null;
  66.     /**
  67.      * @ORM\Column(type="float", nullable=true)
  68.      */
  69.     private ?float $wastePercentage null;
  70.     public function __construct()
  71.     {
  72.         $this->countryStatistics = new ArrayCollection();
  73.         $this->pageStatistics = new ArrayCollection();
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getReport(): Report
  80.     {
  81.         return $this->report;
  82.     }
  83.     public function setReport(Report $report): void
  84.     {
  85.         $this->report $report;
  86.     }
  87.     public function getPeriodStart(): ?\DateTime
  88.     {
  89.         return $this->periodStart;
  90.     }
  91.     public function setPeriodStart(?\DateTime $periodStart): void
  92.     {
  93.         $this->periodStart $periodStart;
  94.     }
  95.     public function getPeriodEnd(): ?\DateTime
  96.     {
  97.         return $this->periodEnd;
  98.     }
  99.     public function setPeriodEnd(?\DateTime $periodEnd): void
  100.     {
  101.         $this->periodEnd $periodEnd;
  102.     }
  103.     public function getCountryStatistics(): ?Collection
  104.     {
  105.         return $this->countryStatistics;
  106.     }
  107.     public function setCountryStatistics(?Collection $countryStatistics): void
  108.     {
  109.         $this->countryStatistics $countryStatistics;
  110.     }
  111.     public function getPageStatistics(): ?Collection
  112.     {
  113.         return $this->pageStatistics;
  114.     }
  115.     public function setPageStatistics(?Collection $pageStatistics): void
  116.     {
  117.         $this->pageStatistics $pageStatistics;
  118.     }
  119.     public function getCompletedAt(): ?\DateTime
  120.     {
  121.         return $this->completedAt;
  122.     }
  123.     public function setCompletedAt(?\DateTime $completedAt): void
  124.     {
  125.         $this->completedAt $completedAt;
  126.     }
  127.     public function getViews(): ?float
  128.     {
  129.         return $this->views;
  130.     }
  131.     public function setViews(?float $views): void
  132.     {
  133.         $this->views $views;
  134.     }
  135.     public function getTCO2(): ?float
  136.     {
  137.         return $this->tCO2;
  138.     }
  139.     public function setTCO2(?float $tCO2): void
  140.     {
  141.         $this->tCO2 $tCO2;
  142.     }
  143.     public function getKWh(): ?float
  144.     {
  145.         return $this->kWh;
  146.     }
  147.     public function setKWh(?float $kWh): void
  148.     {
  149.         $this->kWh $kWh;
  150.     }
  151.     public function getTCO2Device(): ?float
  152.     {
  153.         return $this->tCO2Device;
  154.     }
  155.     public function setTCO2Device(?float $tCO2Device): void
  156.     {
  157.         $this->tCO2Device $tCO2Device;
  158.     }
  159.     public function getTCO2Network(): ?float
  160.     {
  161.         return $this->tCO2Network;
  162.     }
  163.     public function setTCO2Network(?float $tCO2Network): void
  164.     {
  165.         $this->tCO2Network $tCO2Network;
  166.     }
  167.     public function getWastePercentage(): ?float
  168.     {
  169.         return $this->wastePercentage;
  170.     }
  171.     public function setWastePercentage(?float $wastePercentage): void
  172.     {
  173.         $this->wastePercentage $wastePercentage;
  174.     }
  175.     public function isEmpty(): bool
  176.     {
  177.         return $this->countryStatistics->isEmpty() || $this->pageStatistics->isEmpty();
  178.     }
  179.     public function getCarbonIndex(): ?float
  180.     {
  181.         if ($this->views == || $this->tCO2 == 0) {
  182.             return 0;
  183.         }
  184.         return round(($this->tCO2 $this->views) * 10000002);
  185.     }
  186.     public function __toString(): string
  187.     {
  188.         return $this->email ?? 'New Snapshot';
  189.     }
  190. }