->find(); | ->find(); | ||||
} | } | ||||
public function findPointSalesByUserAccess(User $user) | |||||
{ | |||||
return $this->createDefaultQuery() | |||||
->filterIsOnline() | |||||
->filterByUserAccess($user) | |||||
->find(); | |||||
} | |||||
public function queryPointSalesPublic(Producer $producer) | public function queryPointSalesPublic(Producer $producer) | ||||
{ | { | ||||
return $this->createDefaultQuery() | return $this->createDefaultQuery() |
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\PointSale\PointSale\Service\PointSaleDefinition; | use common\logic\PointSale\PointSale\Service\PointSaleDefinition; | ||||
use common\logic\StatusInterface; | use common\logic\StatusInterface; | ||||
use common\logic\User\User\Model\User; | |||||
use yii\db\ActiveQuery; | use yii\db\ActiveQuery; | ||||
class PointSaleRepositoryQuery extends AbstractRepositoryQuery | class PointSaleRepositoryQuery extends AbstractRepositoryQuery | ||||
return $this; | return $this; | ||||
} | } | ||||
public function filterByUserAccess(User $user): self | |||||
{ | |||||
$this->andWhere('status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))'); | |||||
$this->addParams([':id_user' => $user->id]); | |||||
return $this; | |||||
} | |||||
} | } |
$params = []; | $params = []; | ||||
$productModule = $this->getProductModule(); | $productModule = $this->getProductModule(); | ||||
$subscriptionModule = $this->getSubscriptionModule(); | $subscriptionModule = $this->getSubscriptionModule(); | ||||
$user = GlobalParam::getCurrentUser(); | |||||
$user = $this->getUserCurrent(); | |||||
$userProducer = $this->getUserProducerModule()->findOneUserProducer($this->getUserCurrent()); | $userProducer = $this->getUserProducerModule()->findOneUserProducer($this->getUserCurrent()); | ||||
$pointSale = null; | $pointSale = null; | ||||
$params['products'] = $productsArray; | $params['products'] = $productsArray; | ||||
$pointsSaleArray = $this->getPointSaleModule()->findPointSales(); | |||||
$pointsSaleArray = $this->getPointSaleModule()->findPointSalesByUserAccess($user); | |||||
foreach ($pointsSaleArray as &$pointSale) { | foreach ($pointsSaleArray as &$pointSale) { | ||||
$pointSale = array_merge($pointSale->getAttributes(), [ | $pointSale = array_merge($pointSale->getAttributes(), [ | ||||
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '') | 'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '') |