|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\User;
-
- 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\CaracoleBundle\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);
- }
-
- }
|