-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...tracts/Repository/Values/Content/Query/Aggregation/Ranges/DateTimeStepRangesGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
Check warning on line 1 in src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/DateTimeStepRangesGenerator.php GitHub Actions / Run code style check (8.0)
|
||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges; | ||
|
||
use DateInterval; | ||
use DateTime; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\DateRangeAggregation; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range; | ||
|
||
final class DateTimeStepRangesGenerator implements RangesGeneratorInterface | ||
{ | ||
private DateTimeInterface $start; | ||
|
||
private DateTimeInterface $end; | ||
|
||
private DateInterval $step; | ||
|
||
private bool $isLeftOpen = true; | ||
|
||
private bool $isRightOpen = true; | ||
|
||
|
||
public function __construct(DateTimeInterface $start, DateTimeInterface $end) | ||
{ | ||
$this->start = $start; | ||
$this->end = $end; | ||
$this->step = new DateInterval('P1D'); | ||
} | ||
|
||
public function getStart(): DateTimeInterface | ||
{ | ||
return $this->start; | ||
} | ||
|
||
public function setStart(DateTimeInterface $start): self | ||
{ | ||
$this->start = $start; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEnd(): DateTimeInterface | ||
{ | ||
return $this->end; | ||
} | ||
|
||
public function setEnd(DateTimeInterface $end): self | ||
{ | ||
$this->end = $end; | ||
|
||
return $this; | ||
} | ||
|
||
public function getStep(): DateInterval | ||
{ | ||
return $this->step; | ||
} | ||
|
||
public function setStep(DateInterval $step): self | ||
{ | ||
$this->step = $step; | ||
|
||
return $this; | ||
} | ||
|
||
public function isLeftOpen(): bool | ||
{ | ||
return $this->isLeftOpen; | ||
} | ||
|
||
public function setLeftOpen(bool $isLeftOpen): void | ||
{ | ||
$this->isLeftOpen = $isLeftOpen; | ||
} | ||
|
||
public function isRightOpen(): bool | ||
{ | ||
return $this->isRightOpen; | ||
} | ||
|
||
public function setRightOpen(bool $isRightOpen): self | ||
{ | ||
$this->isRightOpen = $isRightOpen; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] | ||
*/ | ||
public function generate(): array | ||
{ | ||
$ranges = []; | ||
|
||
if ($this->isLeftOpen) { | ||
$ranges[] = Range::ofDateTime(Range::INF, $this->start); | ||
} | ||
|
||
/** @var \DateTimeImmutable $current */ | ||
$current = $this->start; | ||
if ($current instanceof DateTime) { | ||
$current = DateTimeImmutable::createFromMutable($current); | ||
} | ||
|
||
while ($current <= $this->end) { | ||
$next = $current->add($this->step); | ||
$ranges[] = Range::ofDateTime($current, $next); | ||
$current = $next; | ||
} | ||
|
||
if ($this->isRightOpen) { | ||
$ranges[] = Range::ofDateTime($this->end, Range::INF); | ||
} | ||
|
||
return $ranges; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...contracts/Repository/Values/Content/Query/Aggregation/Ranges/FloatStepRangesGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range; | ||
|
||
final class FloatStepRangesGenerator implements RangesGeneratorInterface | ||
{ | ||
private float $start; | ||
|
||
private float $end; | ||
|
||
private float $step = 1; | ||
|
||
private bool $isLeftOpen = true; | ||
|
||
private bool $isRightOpen = true; | ||
|
||
public function __construct(float $start, float $end) | ||
{ | ||
$this->start = $start; | ||
$this->end = $end; | ||
} | ||
|
||
public function getStart(): float | ||
{ | ||
return $this->start; | ||
} | ||
|
||
public function setStart(float $start): self | ||
{ | ||
$this->start = $start; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEnd(): float | ||
{ | ||
return $this->end; | ||
} | ||
|
||
public function setEnd(float $end): self | ||
{ | ||
$this->end = $end; | ||
|
||
return $this; | ||
} | ||
|
||
public function getStep(): float | ||
{ | ||
return $this->step; | ||
} | ||
|
||
public function setStep(float $step): self | ||
{ | ||
$this->step = $step; | ||
|
||
return $this; | ||
} | ||
|
||
public function isLeftOpen(): bool | ||
{ | ||
return $this->isLeftOpen; | ||
} | ||
|
||
public function setLeftOpen(bool $isLeftOpen): void | ||
{ | ||
$this->isLeftOpen = $isLeftOpen; | ||
} | ||
|
||
public function isRightOpen(): bool | ||
{ | ||
return $this->isRightOpen; | ||
} | ||
|
||
public function setRightOpen(bool $isRightOpen): self | ||
{ | ||
$this->isRightOpen = $isRightOpen; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] | ||
*/ | ||
public function generate(): array | ||
{ | ||
$ranges = []; | ||
|
||
if ($this->isLeftOpen) { | ||
$ranges[] = Range::ofFloat(Range::INF, $this->start); | ||
} | ||
|
||
$values = range($this->start, $this->end, $this->step); | ||
for ($i = 1; $i < count($values); ++$i) { | ||
$ranges[] = Range::ofFloat($values[$i - 1], $values[$i]); | ||
} | ||
|
||
if ($this->isRightOpen) { | ||
$ranges[] = Range::ofFloat($this->end, Range::INF); | ||
} | ||
|
||
return $ranges; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...ntracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range; | ||
|
||
final class IntegerStepRangesGenerator implements RangesGeneratorInterface | ||
{ | ||
private int $start; | ||
|
||
private int $end; | ||
|
||
private int $step = 1; | ||
|
||
private bool $isLeftOpen = true; | ||
|
||
private bool $isRightOpen = true; | ||
|
||
public function __construct(int $start, int $end) | ||
{ | ||
$this->start = $start; | ||
$this->end = $end; | ||
} | ||
|
||
public function getStart(): int | ||
{ | ||
return $this->start; | ||
} | ||
|
||
public function setStart(int $start): self | ||
{ | ||
$this->start = $start; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEnd(): int | ||
{ | ||
return $this->end; | ||
} | ||
|
||
public function setEnd(int $end): self | ||
{ | ||
$this->end = $end; | ||
|
||
return $this; | ||
} | ||
|
||
public function getStep(): int | ||
{ | ||
return $this->step; | ||
} | ||
|
||
public function setStep(int $step): self | ||
{ | ||
$this->step = $step; | ||
|
||
return $this; | ||
} | ||
|
||
public function isLeftOpen(): bool | ||
{ | ||
return $this->isLeftOpen; | ||
} | ||
|
||
public function setLeftOpen(bool $isLeftOpen): void | ||
{ | ||
$this->isLeftOpen = $isLeftOpen; | ||
} | ||
|
||
public function isRightOpen(): bool | ||
{ | ||
return $this->isRightOpen; | ||
} | ||
|
||
public function setRightOpen(bool $isRightOpen): self | ||
{ | ||
$this->isRightOpen = $isRightOpen; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] | ||
*/ | ||
public function generate(): \Generator | ||
Check failure on line 92 in src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php GitHub Actions / Unit tests & SQLite integration tests (7.4)
Check failure on line 92 in src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php GitHub Actions / Unit tests & SQLite integration tests (8.0)
Check failure on line 92 in src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php GitHub Actions / Unit tests & SQLite integration tests (8.1)
|
||
{ | ||
if ($this->isLeftOpen) { | ||
yield Range::ofInt(Range::INF, $this->start); | ||
} | ||
|
||
$values = range($this->start, $this->end, $this->step); | ||
for ($i = 1; $i < count($values); ++$i) { | ||
yield Range::ofInt($values[$i - 1], $values[$i]); | ||
} | ||
|
||
if ($this->isRightOpen) { | ||
yield Range::ofInt($this->end, Range::INF); | ||
} | ||
} | ||
} |
Oops, something went wrong.