|
|
|
|
|
|
|
|
|
|
|
|
|
|
$etablissement = Etablissement::findOne($id_etablissement) ; |
|
|
$etablissement = Etablissement::findOne($id_etablissement) ; |
|
|
|
|
|
|
|
|
if ($model_login->load(Yii::$app->request->post()) && $model_login->login()) |
|
|
|
|
|
|
|
|
if(Yii::$app->user->isGuest) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
// ajout de l'établissement en favoris si ce n'est pas encore le cas |
|
|
|
|
|
$user_etablissement_exist = UserEtablissement::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_user' => Yii::$app->user->id, |
|
|
|
|
|
'id_etablissement' => $id_etablissement |
|
|
|
|
|
])->one(); |
|
|
|
|
|
|
|
|
|
|
|
if(!$user_etablissement_exist) |
|
|
|
|
|
|
|
|
if ($model_login->load(Yii::$app->request->post()) && $model_login->login()) |
|
|
{ |
|
|
{ |
|
|
$etab_user = new UserEtablissement ; |
|
|
|
|
|
$etab_user->id_etablissement = $id_etablissement ; |
|
|
|
|
|
$etab_user->id_user = Yii::$app->user->id ; |
|
|
|
|
|
$etab_user->credit = 0 ; |
|
|
|
|
|
$etab_user->actif = 1 ; |
|
|
|
|
|
$etab_user->save() ; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if(!$user_etablissement_exist->actif) |
|
|
|
|
|
|
|
|
// ajout de l'établissement en favoris si ce n'est pas encore le cas |
|
|
|
|
|
$user_etablissement_exist = UserEtablissement::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_user' => Yii::$app->user->id, |
|
|
|
|
|
'id_etablissement' => $id_etablissement |
|
|
|
|
|
])->one(); |
|
|
|
|
|
|
|
|
|
|
|
if(!$user_etablissement_exist) |
|
|
{ |
|
|
{ |
|
|
$user_etablissement_exist->actif = 1 ; |
|
|
|
|
|
$user_etablissement_exist->save() ; |
|
|
|
|
|
|
|
|
$etab_user = new UserEtablissement ; |
|
|
|
|
|
$etab_user->id_etablissement = $id_etablissement ; |
|
|
|
|
|
$etab_user->id_user = Yii::$app->user->id ; |
|
|
|
|
|
$etab_user->credit = 0 ; |
|
|
|
|
|
$etab_user->actif = 1 ; |
|
|
|
|
|
$etab_user->save() ; |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if(!$user_etablissement_exist->actif) |
|
|
|
|
|
{ |
|
|
|
|
|
$user_etablissement_exist->actif = 1 ; |
|
|
|
|
|
$user_etablissement_exist->save() ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->redirect(['commande/index']) ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->redirect(['commande/index']) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($model_signup->load(Yii::$app->request->post())) { |
|
|
|
|
|
|
|
|
|
|
|
$model_signup->id_etablissement = $id_etablissement ; |
|
|
|
|
|
$model_signup->option_client_boulanger = 'client' ; |
|
|
|
|
|
|
|
|
|
|
|
if ($user = $model_signup->signup()) { |
|
|
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
|
|
$this->redirect(['commande/index']) ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($model_signup->load(Yii::$app->request->post())) { |
|
|
|
|
|
|
|
|
|
|
|
$model_signup->id_etablissement = $id_etablissement ; |
|
|
|
|
|
$model_signup->option_client_boulanger = 'client' ; |
|
|
|
|
|
|
|
|
|
|
|
if ($user = $model_signup->signup()) { |
|
|
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
|
|
$this->redirect(['commande/index']) ; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$this->redirect(['commande/create','id_etablissement' => $id_etablissement]) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->render('etablissement',[ |
|
|
return $this->render('etablissement',[ |
|
|
'model_login' => $model_login, |
|
|
'model_login' => $model_login, |