|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\User;
-
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
- use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
- use Lc\CaracoleBundle\Solver\User\UserMerchantSolver;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractStore;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
-
- class UserMerchantStore extends AbstractStore
- {
- use MerchantStoreTrait;
-
- protected UserMerchantRepositoryQuery $query;
- protected UserMerchantSolver $userMerchantSolver;
-
- public function __construct(UserMerchantRepositoryQuery $query, UserMerchantSolver $userMerchantSolver)
- {
- $this->query = $query;
- $this->userMerchantSolver = $userMerchantSolver;
- }
-
- public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->orderBy('id');
- return $query;
- }
-
- public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->filterByMerchant($this->merchant);
- return $query;
- }
-
- public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- return $query;
- }
-
- // getUserMerchant
- public function getOneByUser(UserInterface $user, $query = null): UserMerchantInterface
- {
- $query = $this->createDefaultQuery($query);
- $query->filterByUser($user);
- return $query->findOne();
- }
-
- public function isCreditActiveByUser(UserInterface $user, $query = null): bool
- {
- $userMerchant = $this->getOneByUser($user, $query);
- return $this->userMerchantSolver->isCreditActive($userMerchant);
- }
-
- }
|