You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 line
1.5KB

  1. <?php
  2. namespace domain\Distribution\Distribution;
  3. use domain\Subscription\Subscription\Subscription;
  4. use domain\_\AbstractRepositoryQuery;
  5. class DistributionRepositoryQuery extends AbstractRepositoryQuery
  6. {
  7. protected DistributionDefinition $definition;
  8. public function loadDependencies(): void
  9. {
  10. $this->loadDefinition(DistributionDefinition::class);
  11. }
  12. public function filterByDate(string $date): self
  13. {
  14. $this->query->andWhere(['date' => $date]);
  15. return $this;
  16. }
  17. public function filterByActive(bool $active): self
  18. {
  19. $this->query->andWhere(['active' => $active]);
  20. return $this;
  21. }
  22. public function filterHasOrders(): self
  23. {
  24. $this->innerJoinWith('order');
  25. return $this;
  26. }
  27. public function filterByDateBetterThanToday(): self
  28. {
  29. $this->query
  30. ->andWhere('date > :date')
  31. ->addParams(['date' => date('Y-m-d') ]);
  32. return $this;
  33. }
  34. public function filterBySubscriptionDates(Subscription $subscription): self
  35. {
  36. $this->query
  37. ->andWhere('date >= :date_begin')
  38. ->addParams([
  39. 'date_begin' => date('Y-m-d', strtotime($subscription->date_begin)),
  40. ]);
  41. if($subscription->date_end) {
  42. $this->query
  43. ->andWhere('date <= :date_end')
  44. ->addParams([
  45. 'date_end' => date('Y-m-d', strtotime($subscription->date_end))
  46. ]);
  47. }
  48. return $this;
  49. }
  50. }