mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-08 08:13:11 +08:00
Created methods to get orphan visits lists
This commit is contained in:
38
module/Core/src/Spec/InDateRange.php
Normal file
38
module/Core/src/Spec/InDateRange.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Spec;
|
||||
|
||||
use Happyr\DoctrineSpecification\BaseSpecification;
|
||||
use Happyr\DoctrineSpecification\Spec;
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
class InDateRange extends BaseSpecification
|
||||
{
|
||||
private ?DateRange $dateRange;
|
||||
private string $field;
|
||||
|
||||
public function __construct(?DateRange $dateRange, string $field = 'date')
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dateRange = $dateRange;
|
||||
$this->field = $field;
|
||||
}
|
||||
|
||||
protected function getSpec(): Specification
|
||||
{
|
||||
$criteria = [];
|
||||
|
||||
if ($this->dateRange !== null && $this->dateRange->getStartDate() !== null) {
|
||||
$criteria[] = Spec::gte($this->field, $this->dateRange->getStartDate()->toDateTimeString());
|
||||
}
|
||||
|
||||
if ($this->dateRange !== null && $this->dateRange->getEndDate() !== null) {
|
||||
$criteria[] = Spec::lte($this->field, $this->dateRange->getEndDate()->toDateTimeString());
|
||||
}
|
||||
|
||||
return Spec::andX(...$criteria);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user