|
- <?php
-
- namespace domain\Distribution\Distribution;
-
- use domain\Subscription\Subscription\Subscription;
- use domain\_\AbstractRepositoryQuery;
-
- class DistributionRepositoryQuery extends AbstractRepositoryQuery
- {
- protected DistributionDefinition $definition;
-
- public function loadDependencies(): void
- {
- $this->loadDefinition(DistributionDefinition::class);
- }
-
- public function filterByDate(string $date): self
- {
- $this->query->andWhere(['date' => $date]);
-
- return $this;
- }
-
- public function filterByActive(bool $active): self
- {
- $this->query->andWhere(['active' => $active]);
-
- return $this;
- }
-
- public function filterHasOrders(): self
- {
- $this->innerJoinWith('order');
- return $this;
- }
-
- public function filterByDateBetterThanToday(): self
- {
- $this->query
- ->andWhere('date > :date')
- ->addParams(['date' => date('Y-m-d') ]);
-
- return $this;
- }
-
- public function filterBySubscriptionDates(Subscription $subscription): self
- {
- $this->query
- ->andWhere('date >= :date_begin')
- ->addParams([
- 'date_begin' => date('Y-m-d', strtotime($subscription->date_begin)),
- ]);
-
- if($subscription->date_end) {
- $this->query
- ->andWhere('date <= :date_end')
- ->addParams([
- 'date_end' => date('Y-m-d', strtotime($subscription->date_end))
- ]);
- }
-
- return $this;
- }
- }
|