|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
-
-
-
- namespace producer\controllers;
-
- class ProducerBaseController extends CommonController
- {
-
- var $producer ;
-
-
-
- public function behaviors()
- {
- return [];
- }
-
- public function actions()
- {
- return [];
- }
-
- public function beforeAction($event)
- {
- $producer = $this->getProducer() ;
-
- $userProducer = UserProducer::find()
- ->where([
- 'id_user' => User::getCurrentId(),
- 'id_producer' => $producer->id
- ])
- ->one() ;
-
-
-
- if(strlen($producer->code)) {
-
-
-
- if(Yii::$app->user->isGuest) {
- $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
- }
-
- else {
- if(!$userProducer || ($userProducer && !$userProducer->active)) {
- $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
- }
- }
- }
-
-
-
- if(!$producer->active && (Yii::$app->user->isGuest || Yii::$app->user->identity->id_producer != $producer->id)) {
- $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
- }
-
- return parent::beforeAction($event);
- }
-
-
-
- public function getProducer()
- {
- if($this->producer) {
- return $this->producer ;
- }
- else {
- $producer = Producer::find()
- ->with('contact')
- ->where(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')])
- ->one() ;
-
- if($producer) {
- $this->producer = $producer ;
- return $this->producer ;
- }
- else {
- throw new \yii\web\HttpException(404, 'Producteur introuvable');
- }
- }
- }
- }
-
- ?>
|