mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
34 lines
880 B
PHP
34 lines
880 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Core\Visit;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
|
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|
|
|
class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|
{
|
|
private EntityManagerInterface $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
}
|
|
|
|
public function getVisitsStats(?ApiKey $apiKey = null): VisitsStats
|
|
{
|
|
return new VisitsStats($this->getVisitsCount($apiKey));
|
|
}
|
|
|
|
private function getVisitsCount(?ApiKey $apiKey): int
|
|
{
|
|
/** @var VisitRepository $visitsRepo */
|
|
$visitsRepo = $this->em->getRepository(Visit::class);
|
|
return $visitsRepo->countVisits($apiKey);
|
|
}
|
|
}
|