|
4 | 4 |
|
5 | 5 | namespace Yokai\Batch\Storage;
|
6 | 6 |
|
| 7 | +use DateTimeInterface; |
7 | 8 | use Yokai\Batch\BatchStatus;
|
8 | 9 | use Yokai\Batch\Exception\UnexpectedValueException;
|
9 | 10 |
|
|
16 | 17 | * ->ids(['123', '456'])
|
17 | 18 | * ->jobs(['export', 'import'])
|
18 | 19 | * ->statuses([BatchStatus::RUNNING, BatchStatus::COMPLETED])
|
| 20 | + * ->startTime(new \DateTimeImmutable('2023-07-07 15:18'), new \DateTime('2023-07-07 16:30')) |
| 21 | + * ->endTime(new \DateTimeImmutable('2023-07-07 15:18'), new \DateTime('2023-07-07 16:30')) |
19 | 22 | * ->sort(Query::SORT_BY_END_DESC)
|
20 | 23 | * ->limit(6, 12)
|
21 | 24 | * ->getQuery();
|
|
26 | 29 | * $builder->ids(['123', '456']);
|
27 | 30 | * $builder->jobs(['export', 'import']);
|
28 | 31 | * $builder->statuses([BatchStatus::RUNNING, BatchStatus::COMPLETED]);
|
| 32 | + * $builder->startTime(new \DateTimeImmutable('2023-07-07 15:18'), new \DateTime('2023-07-07 16:30')); |
| 33 | + * $builder->endTime(new \DateTimeImmutable('2023-07-07 15:18'), new \DateTime('2023-07-07 16:30')); |
29 | 34 | * $builder->sort(Query::SORT_BY_END_DESC);
|
30 | 35 | * $builder->limit(6, 12);
|
31 | 36 | * $builder->getQuery();
|
@@ -63,6 +68,10 @@ final class QueryBuilder
|
63 | 68 | */
|
64 | 69 | private array $statuses = [];
|
65 | 70 |
|
| 71 | + private ?TimeFilter $startTime = null; |
| 72 | + |
| 73 | + private ?TimeFilter $endTime = null; |
| 74 | + |
66 | 75 | private ?string $sortBy = null;
|
67 | 76 |
|
68 | 77 | private int $limit = 10;
|
@@ -126,6 +135,44 @@ public function statuses(array $statuses): self
|
126 | 135 | return $this;
|
127 | 136 | }
|
128 | 137 |
|
| 138 | + /** |
| 139 | + * Filter executions that started in a frame. |
| 140 | + * Both frame boundaries are optional. |
| 141 | + * Calling this method with both null boundaries result in removing the filter. |
| 142 | + * |
| 143 | + * @param DateTimeInterface|null $from Beginning of the time frame |
| 144 | + * @param DateTimeInterface|null $to End of the time frame |
| 145 | + */ |
| 146 | + public function startTime(?DateTimeInterface $from, ?DateTimeInterface $to): self |
| 147 | + { |
| 148 | + if ($from === null && $to === null) { |
| 149 | + $this->startTime = null; |
| 150 | + } else { |
| 151 | + $this->startTime = new TimeFilter($from, $to); |
| 152 | + } |
| 153 | + |
| 154 | + return $this; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Filter executions that ended in a frame. |
| 159 | + * Both frame boundaries are optional. |
| 160 | + * Calling this method with both null boundaries result in removing the filter. |
| 161 | + * |
| 162 | + * @param DateTimeInterface|null $from Beginning of the time frame |
| 163 | + * @param DateTimeInterface|null $to End of the time frame |
| 164 | + */ |
| 165 | + public function endTime(?DateTimeInterface $from, ?DateTimeInterface $to): self |
| 166 | + { |
| 167 | + if ($from === null && $to === null) { |
| 168 | + $this->endTime = null; |
| 169 | + } else { |
| 170 | + $this->endTime = new TimeFilter($from, $to); |
| 171 | + } |
| 172 | + |
| 173 | + return $this; |
| 174 | + } |
| 175 | + |
129 | 176 | /**
|
130 | 177 | * Sort executions.
|
131 | 178 | *
|
@@ -165,6 +212,15 @@ public function limit(int $limit, int $offset): self
|
165 | 212 | */
|
166 | 213 | public function getQuery(): Query
|
167 | 214 | {
|
168 |
| - return new Query($this->jobNames, $this->ids, $this->statuses, $this->sortBy, $this->limit, $this->offset); |
| 215 | + return new Query( |
| 216 | + $this->jobNames, |
| 217 | + $this->ids, |
| 218 | + $this->statuses, |
| 219 | + $this->startTime, |
| 220 | + $this->endTime, |
| 221 | + $this->sortBy, |
| 222 | + $this->limit, |
| 223 | + $this->offset |
| 224 | + ); |
169 | 225 | }
|
170 | 226 | }
|
0 commit comments