|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\controllers\CommonController;
- use domain\PointSale\PointSale\PointSale;
- use domain\Producer\Producer\Producer;
- use domain\Product\Product\Product;
-
- class BackendController extends CommonController
- {
- public function beforeAction($event)
- {
- $producerCurrent = $this->getProducerCurrent();
-
- if($producerCurrent) {
- $this->getLogic()->setProducerContext($producerCurrent);
- }
-
- if(!$producerCurrent) {
- $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['dashboard/index']));
- return false;
- }
-
- return parent::beforeAction($event);
- }
-
-
-
- public function checkProductsPointsSale()
- {
- if (!Product::searchCount() || !PointSale::searchCount()) {
- $this->redirect(['dashboard/index', 'error_products_points_sale' => 1]);
- }
- }
-
- public function getProducerCurrent(): ?Producer
- {
- return Producer::searchOne();
- }
-
- public function redirectDashboard()
- {
- return $this->redirect(['dashboard/index']);
- }
- }
-
- ?>
|