src/Domain/Entity/StatisticLog/DailyStatistic.php line 33

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 ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use App\Application\Controller\Api\Statistic\SearchAction;
  9. use App\Application\Dto\Statistic\StatisticSearchOutput;
  10. use App\Domain\Entity\Behavior\Identifiable;
  11. use Gedmo\Timestampable\Traits\Timestampable;
  12. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  13. /**
  14.  * Class DailyStatistic
  15.  *
  16.  * @package App\Domain\Entity\StatisticLog
  17.  */
  18. #[ApiResource(
  19.     operations: [
  20.         new GetCollection(
  21.             uriTemplate'/daily_statistics/elastic',
  22.             controllerSearchAction::class,
  23.             outputStatisticSearchOutput::class,
  24.             name'elastic_stats',
  25.         ),
  26.         new GetCollection(filters: ['dailyStatistic.date_filter''dailyStatistic.search_filter']),
  27.     ],
  28.     normalizationContext: ['groups' => ['daily_stats_read']],
  29. )]
  30. class DailyStatistic
  31. {
  32.     use Identifiable;
  33.     use Timestampable;
  34.     use SoftDeleteable;
  35.     public \DateTimeInterface $date;
  36.     public int $totalRead 0;
  37.     public int $totalReadList 0;
  38.     public int $totalClick 0;
  39.     public string $entity;
  40.     public ?int $entityId null;
  41.     public ?array $data null;
  42.     public ?bool $isEntityPro false;
  43.     public ?string $name;
  44.     public function __construct(
  45.         \DateTimeInterface $date,
  46.         string $entity,
  47.         ?int $entityId null,
  48.         ?string $name null,
  49.         ?bool $isEntityPro null,
  50.         ?array $data null
  51.     ) {
  52.         $this->date $date;
  53.         $this->entity $entity;
  54.         $this->entityId $entityId;
  55.         $this->name $name;
  56.         $this->isEntityPro $isEntityPro;
  57.         $this->data $data;
  58.     }
  59.     public function getDate(): \DateTimeInterface
  60.     {
  61.         return $this->date;
  62.     }
  63.     public function setDate(\DateTimeInterface $date): self
  64.     {
  65.         $this->date $date;
  66.         return $this;
  67.     }
  68.     public function getTotalRead(): int
  69.     {
  70.         return $this->totalRead;
  71.     }
  72.     public function setTotalRead(int $totalRead): self
  73.     {
  74.         $this->totalRead $totalRead;
  75.         return $this;
  76.     }
  77.     public function getTotalReadList(): int
  78.     {
  79.         return $this->totalReadList;
  80.     }
  81.     public function setTotalReadList(int $totalReadList): self
  82.     {
  83.         $this->totalReadList $totalReadList;
  84.         return $this;
  85.     }
  86.     public function getTotalClick(): int
  87.     {
  88.         return $this->totalClick;
  89.     }
  90.     public function setTotalClick(int $totalClick): self
  91.     {
  92.         $this->totalClick $totalClick;
  93.         return $this;
  94.     }
  95.     public function getEntity(): string
  96.     {
  97.         return $this->entity;
  98.     }
  99.     public function setEntity(string $entity): self
  100.     {
  101.         $this->entity $entity;
  102.         return $this;
  103.     }
  104.     public function getEntityId(): ?int
  105.     {
  106.         return $this->entityId;
  107.     }
  108.     public function setEntityId(?int $entityId): self
  109.     {
  110.         $this->entityId $entityId;
  111.         return $this;
  112.     }
  113.     public function getName(): string
  114.     {
  115.         return $this->name;
  116.     }
  117.     public function setName(string $name): self
  118.     {
  119.         $this->name $name;
  120.         return $this;
  121.     }
  122.     public function getData(): ?array
  123.     {
  124.         return $this->data;
  125.     }
  126.     public function setData(?array $data): self
  127.     {
  128.         $this->data $data;
  129.         return $this;
  130.     }
  131.     public function incrementRead(int $amount 1): self
  132.     {
  133.         $this->totalRead += $amount;
  134.         return $this;
  135.     }
  136.     public function incrementReadList(int $amount 1): self
  137.     {
  138.         $this->totalReadList += $amount;
  139.         return $this;
  140.     }
  141.     public function incrementClick(int $amount 1): self
  142.     {
  143.         $this->totalClick += $amount;
  144.         return $this;
  145.     }
  146.     public function isEntityPro(): ?bool
  147.     {
  148.         return $this->isEntityPro;
  149.     }
  150.     public function setIsEntityPro(?bool $isEntityPro): self
  151.     {
  152.         $this->isEntityPro $isEntityPro;
  153.         return $this;
  154.     }
  155.     public function isElasticSearchPublishable(): bool
  156.     {
  157.         return $this->isEntityPro;
  158.     }
  159. }