mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Added new models to pass to repositories when counting visits of any kind
This commit is contained in:
37
module/Core/src/Visit/Persistence/VisitsCountFiltering.php
Normal file
37
module/Core/src/Visit/Persistence/VisitsCountFiltering.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Persistence;
|
||||
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
class VisitsCountFiltering
|
||||
{
|
||||
private ?DateRange $dateRange;
|
||||
private bool $excludeBots;
|
||||
private ?Specification $spec;
|
||||
|
||||
public function __construct(?DateRange $dateRange = null, bool $excludeBots = false, ?Specification $spec = null)
|
||||
{
|
||||
$this->dateRange = $dateRange;
|
||||
$this->excludeBots = $excludeBots;
|
||||
$this->spec = $spec;
|
||||
}
|
||||
|
||||
public function dateRange(): ?DateRange
|
||||
{
|
||||
return $this->dateRange;
|
||||
}
|
||||
|
||||
public function excludeBots(): bool
|
||||
{
|
||||
return $this->excludeBots;
|
||||
}
|
||||
|
||||
public function spec(): ?Specification
|
||||
{
|
||||
return $this->spec;
|
||||
}
|
||||
}
|
||||
36
module/Core/src/Visit/Persistence/VisitsListFiltering.php
Normal file
36
module/Core/src/Visit/Persistence/VisitsListFiltering.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Persistence;
|
||||
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
final class VisitsListFiltering extends VisitsCountFiltering
|
||||
{
|
||||
private ?int $limit;
|
||||
private ?int $offset;
|
||||
|
||||
public function __construct(
|
||||
?DateRange $dateRange = null,
|
||||
bool $excludeBots = false,
|
||||
?Specification $spec = null,
|
||||
?int $limit = null,
|
||||
?int $offset = null
|
||||
) {
|
||||
parent::__construct($dateRange, $excludeBots, $spec);
|
||||
$this->limit = $limit;
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
public function limit(): ?int
|
||||
{
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
public function offset(): ?int
|
||||
{
|
||||
return $this->offset;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ use Shlinkio\Shlink\Core\Repository\TagRepository;
|
||||
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
||||
use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
|
||||
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
|
||||
class VisitsStatsHelper implements VisitsStatsHelperInterface
|
||||
@@ -38,7 +39,10 @@ class VisitsStatsHelper implements VisitsStatsHelperInterface
|
||||
/** @var VisitRepository $visitsRepo */
|
||||
$visitsRepo = $this->em->getRepository(Visit::class);
|
||||
|
||||
return new VisitsStats($visitsRepo->countVisits($apiKey), $visitsRepo->countOrphanVisits());
|
||||
return new VisitsStats(
|
||||
$visitsRepo->countVisits($apiKey),
|
||||
$visitsRepo->countOrphanVisits(new VisitsCountFiltering()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user