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.

58 satır
1.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\User;
  3. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  4. use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
  5. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  6. use Lc\CaracoleBundle\Solver\User\UserMerchantSolver;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\AbstractStore;
  9. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  10. class UserMerchantStore extends AbstractStore
  11. {
  12. use MerchantStoreTrait;
  13. protected UserMerchantRepositoryQuery $query;
  14. protected UserMerchantSolver $userMerchantSolver;
  15. public function __construct(UserMerchantRepositoryQuery $query, UserMerchantSolver $userMerchantSolver)
  16. {
  17. $this->query = $query;
  18. $this->userMerchantSolver = $userMerchantSolver;
  19. }
  20. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  21. {
  22. $query->orderBy('id');
  23. return $query;
  24. }
  25. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  26. {
  27. $query->filterByMerchant($this->merchant);
  28. return $query;
  29. }
  30. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  31. {
  32. return $query;
  33. }
  34. // getUserMerchant
  35. public function getOneByUser(UserInterface $user, $query = null): ?UserMerchantInterface
  36. {
  37. $query = $this->createDefaultQuery($query);
  38. $query->filterByUser($user);
  39. return $query->findOne();
  40. }
  41. public function isCreditActiveByUser(UserInterface $user, $query = null): bool
  42. {
  43. $userMerchant = $this->getOneByUser($user, $query);
  44. return $this->userMerchantSolver->isCreditActive($userMerchant);
  45. }
  46. }