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.6KB

  1. <?php
  2. namespace domain\User\User;
  3. use domain\Producer\Producer\Producer;
  4. use domain\_\AbstractRepositoryQuery;
  5. class UserRepositoryQuery extends AbstractRepositoryQuery
  6. {
  7. protected UserDefinition $definition;
  8. public function loadDependencies(): void
  9. {
  10. $this->loadDefinition(UserDefinition::class);
  11. }
  12. public function filterByPasswordResetToken(string $token): self
  13. {
  14. $this->andWhere(['password_reset_token' => $token]);
  15. return $this;
  16. }
  17. public function filterByEmail(string $email): self
  18. {
  19. $this->andWhere(['email' => $email]);
  20. return $this;
  21. }
  22. public function filterByUsername(string $username): self
  23. {
  24. $this->andWhere(['username' => $username]);
  25. return $this;
  26. }
  27. public function filterByProducer(Producer $producer): self
  28. {
  29. $this->andWhere(['user.id_producer' => $producer->id]);
  30. return $this;
  31. }
  32. public function filterByStatus(string $status): self
  33. {
  34. $this->andWhere(['user.status' => $status]);
  35. return $this;
  36. }
  37. public function isStatusProducer(): self
  38. {
  39. return $this->filterByStatus(User::STATUS_PRODUCER);
  40. }
  41. public function isStatusUser(): self
  42. {
  43. return $this->filterByStatus(User::STATUS_ACTIVE);
  44. }
  45. public function filterByDateLastConnectionLessThanFewMinutes(): self
  46. {
  47. $date = new \DateTime('-5 minutes');
  48. $this->andWhere('user.date_last_connection >= :date')
  49. ->addParams(['date' => $date->format('Y-m-d H:i:s')]);
  50. return $this;
  51. }
  52. }