|
- <?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() ;
-
-
-
- if(strlen($producer->code)) {
-
-
-
- if(Yii::$app->user->isGuest) {
- $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
- }
-
- else {
- $user_etablissement = UserEtablissement::find()
- ->where([
- 'id_user' => Yii::$app->user->id,
- 'id_etablissement' => $producer->id
- ])
- ->one() ;
-
- if(!$user_etablissement || ($user_etablissement && !$user_etablissement->actif)) {
- $this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
- }
- }
- }
-
- return parent::beforeAction($event);
- }
-
- public function getProducer() {
- if($this->producer) {
- return $this->producer ;
- }
- else {
- $producer = Etablissement::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, 'Établissement introuvable');
- }
- }
- }
- }
-
- ?>
|