<?php
namespace App\Domain\Entity\StatisticLog;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Domain\Entity\Behavior\Identifiable;
use Gedmo\Timestampable\Traits\Timestampable;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
/**
* Class YearlyStatistic
*
* @package App\Domain\Entity\StatisticLog
*/
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
],
normalizationContext: ['groups' => ['yearly_stats_read']],
filters: ['yearlyStatistic.search_filter'],
)]
class YearlyStatistic
{
use Identifiable;
use Timestampable;
use SoftDeleteable;
private int $year;
private int $totalRead = 0;
private int $totalReadList = 0;
private int $totalClick = 0;
private float $averageRead = 0.0;
private float $averageReadList = 0.0;
private float $averageClick = 0.0;
private string $entity;
private ?int $entityId = null;
public ?string $name;
public ?bool $isEntityPro = false;
private ?array $data = null;
public function __construct(
int $year,
string $entity,
?int $entityId = null,
?string $name = null,
?bool $isEntityPro = null,
?array $data = null
) {
$this->year = $year;
$this->entity = $entity;
$this->entityId = $entityId;
$this->name = $name;
$this->isEntityPro = $isEntityPro;
$this->data = $data;
}
public function getYear(): int
{
return $this->year;
}
public function setYear(int $year): self
{
$this->year = $year;
return $this;
}
public function getTotalRead(): int
{
return $this->totalRead;
}
public function setTotalRead(int $totalRead): self
{
$this->totalRead = $totalRead;
return $this;
}
public function getTotalReadList(): int
{
return $this->totalReadList;
}
public function setTotalReadList(int $totalReadList): self
{
$this->totalReadList = $totalReadList;
return $this;
}
public function getTotalClick(): int
{
return $this->totalClick;
}
public function setTotalClick(int $totalClick): self
{
$this->totalClick = $totalClick;
return $this;
}
public function getAverageRead(): float
{
return $this->averageRead;
}
public function setAverageRead(float $averageRead): self
{
$this->averageRead = $averageRead;
return $this;
}
public function getAverageReadList(): float
{
return $this->averageReadList;
}
public function setAverageReadList(float $averageReadList): self
{
$this->averageReadList = $averageReadList;
return $this;
}
public function getAverageClick(): float
{
return $this->averageClick;
}
public function setAverageClick(float $averageClick): self
{
$this->averageClick = $averageClick;
return $this;
}
public function getEntity(): string
{
return $this->entity;
}
public function setEntity(string $entity): self
{
$this->entity = $entity;
return $this;
}
public function getEntityId(): ?int
{
return $this->entityId;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function setEntityId(?int $entityId): self
{
$this->entityId = $entityId;
return $this;
}
public function getData(): ?array
{
return $this->data;
}
public function setData(?array $data): self
{
$this->data = $data;
return $this;
}
public function incrementRead(int $amount = 1): self
{
$this->totalRead += $amount;
return $this;
}
public function incrementReadList(int $amount = 1): self
{
$this->totalReadList += $amount;
return $this;
}
public function incrementClick(int $amount = 1): self
{
$this->totalClick += $amount;
return $this;
}
public function updateAverages(int $monthsInYear = 12): void
{
$this->averageRead = $this->totalRead / $monthsInYear;
$this->averageReadList = $this->totalReadList / $monthsInYear;
$this->averageClick = $this->totalClick / $monthsInYear;
}
/**
* Reset all totals and averages to zero
*/
public function resetStatistics(): void
{
$this->totalRead = 0;
$this->totalReadList = 0;
$this->totalClick = 0;
$this->averageRead = 0.0;
$this->averageReadList = 0.0;
$this->averageClick = 0.0;
}
public function isEntityPro(): ?bool
{
return $this->isEntityPro;
}
public function setIsEntityPro(?bool $isEntityPro): self
{
$this->isEntityPro = $isEntityPro;
return $this;
}
}