|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code |
|
|
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code |
|
|
else { |
|
|
else { |
|
|
$user_etablissement = UserEtablissement::find() |
|
|
|
|
|
|
|
|
$userProducer = UserProducer::find() |
|
|
->where([ |
|
|
->where([ |
|
|
'id_user' => Yii::$app->user->id, |
|
|
|
|
|
'id_etablissement' => $producer->id |
|
|
|
|
|
|
|
|
'id_user' => User::getId(), |
|
|
|
|
|
'id_producer' => $producer->id |
|
|
]) |
|
|
]) |
|
|
->one() ; |
|
|
->one() ; |
|
|
|
|
|
|
|
|
if(!$user_etablissement || ($user_etablissement && !$user_etablissement->actif)) { |
|
|
|
|
|
|
|
|
if(!$userProducer || ($userProducer && !$userProducer->active)) { |
|
|
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ; |
|
|
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->producer ; |
|
|
return $this->producer ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
$producer = Etablissement::find() |
|
|
|
|
|
|
|
|
$producer = Producer::find() |
|
|
->with('contact') |
|
|
->with('contact') |
|
|
->where(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) |
|
|
->where(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) |
|
|
->one() ; |
|
|
->one() ; |
|
|
|
|
|
|
|
|
return $this->producer ; |
|
|
return $this->producer ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
throw new \yii\web\HttpException(404, 'Établissement introuvable'); |
|
|
|
|
|
|
|
|
throw new \yii\web\HttpException(404, 'Producteur introuvable'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |