|
- <?php
-
-
-
- namespace common\helpers;
-
- use domain\Producer\Producer\ProducerModule;
- use domain\User\User\UserSolver;
-
- class GlobalParam
- {
- public static function get($key)
- {
- if ($key == 'producer') {
- return self::getCurrentProducer();
- } else {
-
- return \Yii::$app->parameterBag->get($key);
- }
- }
-
- public static function getSoukeVersion()
- {
- return self::get('version');
- }
-
- public static function getCurrentProducer()
- {
- if(\Yii::$app->controller->module->id == 'app-console') {
- return \Yii::$app->logic->getProducerContext();
- }
-
- $producerModule = ProducerModule::getInstance();
- if(!\Yii::$app->parameterBag->has('producer') || !\Yii::$app->parameterBag->get('producer')) {
- \Yii::$app->parameterBag->set('producer', $producerModule->findOneProducerById(self::getCurrentProducerId()));
- }
-
- return \Yii::$app->parameterBag->get('producer');
- }
-
-
-
- public static function getCurrentProducerId()
- {
- if (\Yii::$app->controller->module->id == 'app-backend') {
- if (!\Yii::$app->user->isGuest) {
- return \Yii::$app->user->identity->id_producer;
- }
- }
- elseif(\Yii::$app->controller->module->id == 'app-console') {
- return \Yii::$app->logic->getProducerContext()->id;
- }
- else {
- return \Yii::$app->controller->getProducerCurrent()->id;
- }
-
- return false;
- }
-
- public static function getCurrentUser()
- {
- $userSolver = UserSolver::getInstance();
- return $userSolver->getCurrent();
- }
-
- public static function getCurrentUserId()
- {
- $userSolver = UserSolver::getInstance();
- return $userSolver->getCurrentId();
- }
- }
|