選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UserMerchantStore.php 1.9KB

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