namespace common\models; | namespace common\models; | ||||
use Yii; | use Yii; | ||||
use common\helpers\Departements ; | |||||
use yii\helpers\Html ; | |||||
/** | /** | ||||
* This is the model class for table "etablissement". | * This is the model class for table "etablissement". | ||||
'ville' => 'Ville', | 'ville' => 'Ville', | ||||
]; | ]; | ||||
} | } | ||||
public static function getEtablissementsPopulateDropdown() | |||||
{ | |||||
$etablissements_dispos = Etablissement::find() | |||||
->orderby('code_postal, ville ASC') | |||||
->all() ; | |||||
$departements = Departements::get() ; | |||||
$data_etablissements_dispos = [] ; | |||||
$options_etablissements_dispos = [] ; | |||||
foreach($etablissements_dispos as $e) | |||||
{ | |||||
if(!key_exists('d'. substr($e['code_postal'], 0, 2), $data_etablissements_dispos)) | |||||
{ | |||||
$data_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = '<strong>'.$departements[substr($e['code_postal'], 0, 2)].'</strong>' ; | |||||
$options_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = ['disabled' => true] ; | |||||
} | |||||
$data_etablissements_dispos[$e['id']] = Html::encode($e['nom']).' - '.Html::encode($e['code_postal']).' '.Html::encode($e['ville']) ; | |||||
} | |||||
return ['data' => $data_etablissements_dispos, 'options' => $options_etablissements_dispos] ; | |||||
} | |||||
} | } |
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | $etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | ||||
// liste des boulangeries disponibles | // liste des boulangeries disponibles | ||||
$etablissements_dispos = Etablissement::find() | |||||
->orderby('code_postal, ville ASC') | |||||
->all() ; | |||||
$departements = Departements::get() ; | |||||
$data_etablissements_dispos = [] ; | |||||
$options_etablissements_dispos = [] ; | |||||
foreach($etablissements_dispos as $e) | |||||
{ | |||||
if(!key_exists('d'. substr($e['code_postal'], 0, 2), $data_etablissements_dispos)) | |||||
{ | |||||
$data_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = '<strong>'.$departements[substr($e['code_postal'], 0, 2)].'</strong>' ; | |||||
$options_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = ['disabled' => true] ; | |||||
} | |||||
$data_etablissements_dispos[$e['id']] = Html::encode($e['nom']).' - '.Html::encode($e['code_postal']).' '.Html::encode($e['ville']) ; | |||||
} | |||||
$arr_etablissements = Etablissement::getEtablissementsPopulateDropdown() ; | |||||
$data_etablissements_dispos = $arr_etablissements['data'] ; | |||||
$options_etablissements_dispos = $arr_etablissements['options'] ; | |||||
// liste des commandes | // liste des commandes | ||||
$commandes = Commande::find() | $commandes = Commande::find() |
use Yii; | use Yii; | ||||
use common\models\Produit; | use common\models\Produit; | ||||
use common\models\LoginForm; | use common\models\LoginForm; | ||||
use common\models\Etablissement; | |||||
use frontend\models\PasswordResetRequestForm; | use frontend\models\PasswordResetRequestForm; | ||||
use frontend\models\ResetPasswordForm; | use frontend\models\ResetPasswordForm; | ||||
use frontend\models\SignupForm; | use frontend\models\SignupForm; | ||||
} | } | ||||
} | } | ||||
// liste des boulangeries disponibles | |||||
$etablissements = Etablissement::getEtablissementsPopulateDropdown() ; | |||||
$data_etablissements_dispos = $etablissements['data'] ; | |||||
$options_etablissements_dispos = $etablissements['options'] ; | |||||
return $this->render('signup', [ | return $this->render('signup', [ | ||||
'model' => $model, | 'model' => $model, | ||||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||||
]); | ]); | ||||
} | } | ||||
<?php | <?php | ||||
namespace frontend\models; | namespace frontend\models; | ||||
use Yii; | |||||
use common\models\User; | use common\models\User; | ||||
use common\models\Etablissement; | use common\models\Etablissement; | ||||
use yii\base\Model; | use yii\base\Model; | ||||
use Yii; | |||||
use common\models\UserEtablissement ; | |||||
/** | /** | ||||
* Signup form | * Signup form | ||||
public $nom_magasin; | public $nom_magasin; | ||||
public $code_postal; | public $code_postal; | ||||
public $ville; | public $ville; | ||||
public $id_etablissement ; | |||||
public $option_client_boulanger ; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
['email', 'email'], | ['email', 'email'], | ||||
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | ||||
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'],'required','message'=>'Champs obligatoire'], | |||||
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'], 'string', 'min' => 2, 'max' => 255], | |||||
[['nom', 'prenom', 'telephone'],'required','message'=>'Champs obligatoire'], | |||||
[['nom', 'prenom', 'telephone', 'option_client_boulanger'], 'string', 'min' => 2, 'max' => 255], | |||||
['password', 'required','message'=>'Champs obligatoire'], | ['password', 'required','message'=>'Champs obligatoire'], | ||||
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | ['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | ||||
['is_boulanger', 'boolean'], | ['is_boulanger', 'boolean'], | ||||
['id_etablissement', 'integer'], | |||||
['code_postal', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | |||||
}"], | |||||
['ville', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | |||||
return $('#option-boulanger').prop('checked') ; | |||||
}"], | |||||
['nom_magasin', 'string'], | ['nom_magasin', 'string'], | ||||
['nom_magasin', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | ['nom_magasin', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | ||||
return $model->is_boulanger ; | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | },'whenClient' => "function (attribute, value) { | ||||
return $('#signupform-is_boulanger').prop('checked') ; | |||||
return $('#option-boulanger').prop('checked') ; | |||||
}"], | }"], | ||||
['siret', 'string'], | ['siret', 'string'], | ||||
['siret', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | ['siret', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | ||||
return $model->is_boulanger ; | |||||
return $model->option_client_boulanger == 'boulanger' ; | |||||
},'whenClient' => "function (attribute, value) { | },'whenClient' => "function (attribute, value) { | ||||
return $('#signupform-is_boulanger').prop('checked') ; | |||||
return $('#option-boulanger').prop('checked') ; | |||||
}"], | }"], | ||||
['siret', function($attribute, $params) { | ['siret', function($attribute, $params) { | ||||
$user->telephone = $this->telephone ; | $user->telephone = $this->telephone ; | ||||
$user->confiance = 1 ; | $user->confiance = 1 ; | ||||
if($this->is_boulanger) | |||||
if($this->option_client_boulanger == 'boulanger') | |||||
{ | { | ||||
// etablissement | |||||
$etablissement = new Etablissement ; | $etablissement = new Etablissement ; | ||||
$etablissement->nom = $this->nom_magasin ; | $etablissement->nom = $this->nom_magasin ; | ||||
$etablissement->siret = $this->siret; | $etablissement->siret = $this->siret; | ||||
$etablissement->ville = $this->ville; | $etablissement->ville = $this->ville; | ||||
$etablissement->save() ; | $etablissement->save() ; | ||||
// user | |||||
$user->id_etablissement = $etablissement->id ; | $user->id_etablissement = $etablissement->id ; | ||||
$user->status = User::STATUS_BOULANGER ; | $user->status = User::STATUS_BOULANGER ; | ||||
} | } | ||||
$user->generateAuthKey(); | $user->generateAuthKey(); | ||||
if ($user->save()) { | if ($user->save()) { | ||||
// envoi d'un mail de confirmation | // envoi d'un mail de confirmation | ||||
$message = "Bonjour, | |||||
/*$message = "Bonjour, | |||||
Votre inscription sur le site du Chat des Noisette a bien été prise en compte ! | |||||
Votre inscription sur le site de la boîte à pain a bien été prise en compte ! | |||||
Ce compte vous permet de passer vos commandes directement sur le site internet. | Ce compte vous permet de passer vos commandes directement sur le site internet. | ||||
Si vous avez des questions, n'hésitez pas à me contacter. | Si vous avez des questions, n'hésitez pas à me contacter. | ||||
À bientôt, | À bientôt, | ||||
Matthieu" ; | |||||
Guillaume" ; | |||||
Yii::$app->mailer->compose() | Yii::$app->mailer->compose() | ||||
->setTo($user->email) | ->setTo($user->email) | ||||
->setFrom(['matthieu@lechatdesnoisettes.com' => 'Matthieu Bourgeois']) | |||||
->setSubject("Votre inscription sur le site du Chat des Noisettes") | |||||
->setFrom(['contact@laboiteapain.net' => 'Guillaume Bourgeois']) | |||||
->setSubject("Votre inscription sur la boîte à pain") | |||||
->setTextBody($message) | ->setTextBody($message) | ||||
->send(); | |||||
->send();*/ | |||||
// on ajoute la boulangerie sélectionnée par l'user en favoris | |||||
if($this->option_client_boulanger == 'client') | |||||
{ | |||||
if($this->id_etablissement) | |||||
{ | |||||
$etablissement = Etablissement::find()->where(['id'=>$this->id_etablissement])->one() ; | |||||
if($etablissement) | |||||
{ | |||||
$etab_user = new UserEtablissement ; | |||||
$etab_user->id_etablissement = $this->id_etablissement ; | |||||
$etab_user->id_user = $user->id ; | |||||
$etab_user->save() ; | |||||
} | |||||
} | |||||
} | |||||
if($this->option_client_boulanger == 'boulanger') | |||||
{ | |||||
$etab_user = new UserEtablissement ; | |||||
$etab_user->id_etablissement = $etablissement->id ; | |||||
$etab_user->id_user = $user->id ; | |||||
$etab_user->save() ; | |||||
} | |||||
return $user; | return $user; | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
'nom_magasin' => 'Nom de la boulangerie', | 'nom_magasin' => 'Nom de la boulangerie', | ||||
'siret' => 'Numéro SIRET', | 'siret' => 'Numéro SIRET', | ||||
'code_postal' => 'Code postal', | 'code_postal' => 'Code postal', | ||||
'ville' => 'Commune' | |||||
'ville' => 'Commune', | |||||
'id_etablissement' => 'Ma boulangerie', | |||||
]; | ]; | ||||
} | } | ||||
} | } |
<?= $form->field($model, 'nom') ?> | <?= $form->field($model, 'nom') ?> | ||||
<?= $form->field($model, 'prenom') ?> | <?= $form->field($model, 'prenom') ?> | ||||
<?= $form->field($model, 'telephone') ?> | <?= $form->field($model, 'telephone') ?> | ||||
<?= $form->field($model, 'is_boulanger')->checkbox() ?> | |||||
<?php //$form->field($model, 'is_boulanger')->checkbox() ?> | |||||
<div id="client-boulanger" class="btn-group" data-toggle="buttons"> | |||||
<label class="btn btn-default <?php if($model->option_client_boulanger == 'client' || !$model->option_client_boulanger): ?>active<?php endif; ?>"> | |||||
<input type="radio" name="SignupForm[option_client_boulanger]" value="client" id="option-client" autocomplete="off" <?php if($model->option_client_boulanger == 'client' || !$model->option_client_boulanger): ?>checked<?php endif; ?>> Je suis client | |||||
</label> | |||||
<label class="btn btn-default <?php if($model->option_client_boulanger == 'boulanger'): ?>active<?php endif; ?>"> | |||||
<input type="radio" name="SignupForm[option_client_boulanger]" value="boulanger" id="option-boulanger" autocomplete="off" <?php if($model->option_client_boulanger == 'boulanger'): ?>checked<?php endif; ?>> Je suis boulanger | |||||
</label> | |||||
</div> | |||||
<div id="champs-boulanger"> | <div id="champs-boulanger"> | ||||
<?= $form->field($model, 'nom_magasin') ?> | <?= $form->field($model, 'nom_magasin') ?> | ||||
<?= $form->field($model, 'siret') ?> | <?= $form->field($model, 'siret') ?> | ||||
<?= $form->field($model, 'code_postal') ?> | <?= $form->field($model, 'code_postal') ?> | ||||
<?= $form->field($model, 'ville') ?> | <?= $form->field($model, 'ville') ?> | ||||
</div> | </div> | ||||
<div class="form-group"> | |||||
<div id="champs-client"> | |||||
<?= $form->field($model, 'id_etablissement')->dropDownList($data_etablissements_dispos, ['prompt' => '--','encode' => false,'options' => $options_etablissements_dispos]) ?> | |||||
</div> | |||||
<div class="form-group" id="boutons-inscrire"> | |||||
<?= Html::submitButton("S'inscrire", ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?> | <?= Html::submitButton("S'inscrire", ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?> | ||||
</div> | </div> | ||||
<?php ActiveForm::end(); ?> | <?php ActiveForm::end(); ?> |
/* signup */ | /* signup */ | ||||
/* line 453, ../sass/screen.scss */ | /* line 453, ../sass/screen.scss */ | ||||
#form-signup #client-boulanger { | |||||
margin-bottom: 30px; | |||||
} | |||||
/* line 458, ../sass/screen.scss */ | |||||
#form-signup #signupform-id_etablissement option:disabled { | |||||
font-weight: bold; | |||||
color: black; | |||||
} | |||||
/* line 464, ../sass/screen.scss */ | |||||
#form-signup #champs-boulanger { | #form-signup #champs-boulanger { | ||||
display: none; | display: none; | ||||
} | } | ||||
/* line 468, ../sass/screen.scss */ | |||||
#form-signup #boutons-inscrire { | |||||
margin-top: 30px; | |||||
} | |||||
/* line 2, ../sass/_systeme_commandes.scss */ | /* line 2, ../sass/_systeme_commandes.scss */ | ||||
h1.title-systeme-commande { | h1.title-systeme-commande { |
if($('#form-signup').size()) | if($('#form-signup').size()) | ||||
{ | { | ||||
boulange_signup_champs_boulanger() ; | boulange_signup_champs_boulanger() ; | ||||
$('#signupform-is_boulanger').change(function() { | |||||
$('#option-client, #option-boulanger').change(function() { | |||||
boulange_signup_champs_boulanger() ; | boulange_signup_champs_boulanger() ; | ||||
}) ; | }) ; | ||||
} | } | ||||
function boulange_signup_champs_boulanger() | function boulange_signup_champs_boulanger() | ||||
{ | { | ||||
if($('#signupform-is_boulanger').prop('checked')) | |||||
if($('#option-boulanger').prop('checked')) | |||||
{ | { | ||||
$('#champs-boulanger').fadeIn() ; | $('#champs-boulanger').fadeIn() ; | ||||
$('#champs-client').hide() ; | |||||
} | } | ||||
else { | else { | ||||
$('#champs-boulanger').hide() ; | $('#champs-boulanger').hide() ; | ||||
$('#champs-client').fadeIn() ; | |||||
} | } | ||||
} | } | ||||
/* signup */ | /* signup */ | ||||
#form-signup { | #form-signup { | ||||
#client-boulanger { | |||||
margin-bottom: 30px ; | |||||
} | |||||
#signupform-id_etablissement { | |||||
option:disabled { | |||||
font-weight: bold ; | |||||
color: black ; | |||||
} | |||||
} | |||||
#champs-boulanger { | #champs-boulanger { | ||||
display: none ; | display: none ; | ||||
} | } | ||||
#boutons-inscrire { | |||||
margin-top: 30px; | |||||
} | |||||
} | } | ||||
@import "_systeme_commandes.scss" ; | @import "_systeme_commandes.scss" ; |