VisitsPaginatorAdapter.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Core\Paginator\Adapter;
  4. use Happyr\DoctrineSpecification\Specification\Specification;
  5. use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
  6. use Shlinkio\Shlink\Core\Model\VisitsParams;
  7. use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
  8. class VisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter
  9. {
  10. private VisitRepositoryInterface $visitRepository;
  11. private ShortUrlIdentifier $identifier;
  12. private VisitsParams $params;
  13. private ?Specification $spec;
  14. public function __construct(
  15. VisitRepositoryInterface $visitRepository,
  16. ShortUrlIdentifier $identifier,
  17. VisitsParams $params,
  18. ?Specification $spec
  19. ) {
  20. $this->visitRepository = $visitRepository;
  21. $this->params = $params;
  22. $this->identifier = $identifier;
  23. $this->spec = $spec;
  24. }
  25. public function getSlice($offset, $length): array // phpcs:ignore
  26. {
  27. return $this->visitRepository->findVisitsByShortCode(
  28. $this->identifier->shortCode(),
  29. $this->identifier->domain(),
  30. $this->params->getDateRange(),
  31. $length,
  32. $offset,
  33. $this->spec,
  34. );
  35. }
  36. protected function doCount(): int
  37. {
  38. return $this->visitRepository->countVisitsByShortCode(
  39. $this->identifier->shortCode(),
  40. $this->identifier->domain(),
  41. $this->params->getDateRange(),
  42. $this->spec,
  43. );
  44. }
  45. }