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.
|
- <?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\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractStore;
-
- class UserMerchantStore extends AbstractStore
- {
- use MerchantStoreTrait;
-
- protected UserMerchantRepositoryQuery $query;
-
- public function __construct(UserMerchantRepositoryQuery $query)
- {
- $this->query = $query;
- }
-
- // getUserMerchant
- public function getOneByUser(UserInterface $user)
- {
- $query = $this->query->create();
-
- $query
- ->filterByMerchant($this->merchant)
- ->filterByUser($user);
-
- return $query->findOne();
- }
-
- public function isCreditActive(UserMerchantInterface $userMerchant = null)
- {
- if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
- return false;
- }
-
- return true;
- }
-
- public function isCreditActiveByUser(UserInterface $user)
- {
- $userMerchant = $this->getOneByUser($user);
- return $this->isCreditActive($userMerchant);
- }
-
- public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount)
- {
- if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) {
- return true;
- }
-
- return false;
- }
- }
|