|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function beforeAction($event) |
|
|
public function beforeAction($event) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
$producer = $this->getProducer() ; |
|
|
$producer = $this->getProducer() ; |
|
|
|
|
|
|
|
|
|
|
|
$userProducer = UserProducer::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_user' => User::getCurrentId(), |
|
|
|
|
|
'id_producer' => $producer->id |
|
|
|
|
|
]) |
|
|
|
|
|
->one() ; |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Producteur protègé par un code |
|
|
* Producteur protègé par un code |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
// 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 { |
|
|
$userProducer = UserProducer::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_user' => User::getCurrentId(), |
|
|
|
|
|
'id_producer' => $producer->id |
|
|
|
|
|
]) |
|
|
|
|
|
->one() ; |
|
|
|
|
|
|
|
|
|
|
|
if(!$userProducer || ($userProducer && !$userProducer->active)) { |
|
|
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])) ; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Producteur hors ligne |
|
|
* Producteur hors ligne |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ; |
|
|
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!$userProducer) { |
|
|
|
|
|
Producer::addUser(User::getCurrentId(), $producer->id, 0) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return parent::beforeAction($event); |
|
|
return parent::beforeAction($event); |
|
|
} |
|
|
} |
|
|
|
|
|
|