src/Domain/Entity/StatisticLog/YearlyStatistic.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity\StatisticLog;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Domain\Entity\Behavior\Identifiable;
  7. use Gedmo\Timestampable\Traits\Timestampable;
  8. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  9. /**
  10.  * Class YearlyStatistic
  11.  *
  12.  * @package App\Domain\Entity\StatisticLog
  13.  */
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new GetCollection(),
  18.     ],
  19.     normalizationContext: ['groups' => ['yearly_stats_read']],
  20.     filters: ['yearlyStatistic.search_filter'],
  21. )]
  22. class YearlyStatistic
  23. {
  24.     use Identifiable;
  25.     use Timestampable;
  26.     use SoftDeleteable;
  27.     private int $year;
  28.     private int $totalRead 0;
  29.     private int $totalReadList 0;
  30.     private int $totalClick 0;
  31.     private float $averageRead 0.0;
  32.     private float $averageReadList 0.0;
  33.     private float $averageClick 0.0;
  34.     private string $entity;
  35.     private ?int $entityId null;
  36.     public ?string $name;
  37.     public ?bool $isEntityPro false;
  38.     private ?array $data null;
  39.     public function __construct(
  40.         int $year,
  41.         string $entity,
  42.         ?int $entityId null,
  43.         ?string $name null,
  44.         ?bool $isEntityPro null,
  45.         ?array $data null
  46.     ) {
  47.         $this->year $year;
  48.         $this->entity $entity;
  49.         $this->entityId $entityId;
  50.         $this->name $name;
  51.         $this->isEntityPro $isEntityPro;
  52.         $this->data $data;
  53.     }
  54.     public function getYear(): int
  55.     {
  56.         return $this->year;
  57.     }
  58.     public function setYear(int $year): self
  59.     {
  60.         $this->year $year;
  61.         return $this;
  62.     }
  63.     public function getTotalRead(): int
  64.     {
  65.         return $this->totalRead;
  66.     }
  67.     public function setTotalRead(int $totalRead): self
  68.     {
  69.         $this->totalRead $totalRead;
  70.         return $this;
  71.     }
  72.     public function getTotalReadList(): int
  73.     {
  74.         return $this->totalReadList;
  75.     }
  76.     public function setTotalReadList(int $totalReadList): self
  77.     {
  78.         $this->totalReadList $totalReadList;
  79.         return $this;
  80.     }
  81.     public function getTotalClick(): int
  82.     {
  83.         return $this->totalClick;
  84.     }
  85.     public function setTotalClick(int $totalClick): self
  86.     {
  87.         $this->totalClick $totalClick;
  88.         return $this;
  89.     }
  90.     public function getAverageRead(): float
  91.     {
  92.         return $this->averageRead;
  93.     }
  94.     public function setAverageRead(float $averageRead): self
  95.     {
  96.         $this->averageRead $averageRead;
  97.         return $this;
  98.     }
  99.     public function getAverageReadList(): float
  100.     {
  101.         return $this->averageReadList;
  102.     }
  103.     public function setAverageReadList(float $averageReadList): self
  104.     {
  105.         $this->averageReadList $averageReadList;
  106.         return $this;
  107.     }
  108.     public function getAverageClick(): float
  109.     {
  110.         return $this->averageClick;
  111.     }
  112.     public function setAverageClick(float $averageClick): self
  113.     {
  114.         $this->averageClick $averageClick;
  115.         return $this;
  116.     }
  117.     public function getEntity(): string
  118.     {
  119.         return $this->entity;
  120.     }
  121.     public function setEntity(string $entity): self
  122.     {
  123.         $this->entity $entity;
  124.         return $this;
  125.     }
  126.     public function getEntityId(): ?int
  127.     {
  128.         return $this->entityId;
  129.     }
  130.     public function getName(): string
  131.     {
  132.         return $this->name;
  133.     }
  134.     public function setName(string $name): self
  135.     {
  136.         $this->name $name;
  137.         return $this;
  138.     }
  139.     public function setEntityId(?int $entityId): self
  140.     {
  141.         $this->entityId $entityId;
  142.         return $this;
  143.     }
  144.     public function getData(): ?array
  145.     {
  146.         return $this->data;
  147.     }
  148.     public function setData(?array $data): self
  149.     {
  150.         $this->data $data;
  151.         return $this;
  152.     }
  153.     public function incrementRead(int $amount 1): self
  154.     {
  155.         $this->totalRead += $amount;
  156.         return $this;
  157.     }
  158.     public function incrementReadList(int $amount 1): self
  159.     {
  160.         $this->totalReadList += $amount;
  161.         return $this;
  162.     }
  163.     public function incrementClick(int $amount 1): self
  164.     {
  165.         $this->totalClick += $amount;
  166.         return $this;
  167.     }
  168.     public function updateAverages(int $monthsInYear 12): void
  169.     {
  170.         $this->averageRead $this->totalRead $monthsInYear;
  171.         $this->averageReadList $this->totalReadList $monthsInYear;
  172.         $this->averageClick $this->totalClick $monthsInYear;
  173.     }
  174.     /**
  175.      * Reset all totals and averages to zero
  176.      */
  177.     public function resetStatistics(): void
  178.     {
  179.         $this->totalRead 0;
  180.         $this->totalReadList 0;
  181.         $this->totalClick 0;
  182.         $this->averageRead 0.0;
  183.         $this->averageReadList 0.0;
  184.         $this->averageClick 0.0;
  185.     }
  186.     public function isEntityPro(): ?bool
  187.     {
  188.         return $this->isEntityPro;
  189.     }
  190.     public function setIsEntityPro(?bool $isEntityPro): self
  191.     {
  192.         $this->isEntityPro $isEntityPro;
  193.         return $this;
  194.     }
  195. }