-
Notifications
You must be signed in to change notification settings - Fork 14
IBX-6827: Aggregation API improvements #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f53dc5b
IBX-6827: Added method to get all available terms and ranges from agg…
adamwojs 7a4a32b
IBX-6827: Allow to add label aggregation ranges
adamwojs ce5abff
IBX-6827: Introduced Range::INF const
adamwojs 6aecb0b
IBX-6827: Ranges generators
adamwojs fcc30f7
fixup! IBX-6827: Ranges generators
adamwojs ca2d9b6
IBX-6827: Added unit tests
adamwojs 92f2d75
fixup! IBX-6827: Ranges generators
adamwojs 2f10844
Applied code review suggestions
adamwojs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
129 changes: 129 additions & 0 deletions
129
...tracts/Repository/Values/Content/Query/Aggregation/Ranges/DateTimeStepRangesGenerator.php
This file contains hidden or 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,129 @@ | ||
<?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 DateInterval; | ||
use DateTime; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
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 | ||
{ | ||
if ($this->start == $this->end && $this->isLeftOpen && $this->isRightOpen) { | ||
return [ | ||
new Range(Range::INF, Range::INF), | ||
]; | ||
} | ||
|
||
$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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.