@@ -3,6 +3,8 @@ | |||
namespace common\models; | |||
use Yii; | |||
use common\helpers\Departements ; | |||
use yii\helpers\Html ; | |||
/** | |||
* This is the model class for table "etablissement". | |||
@@ -54,4 +56,31 @@ class Etablissement extends \yii\db\ActiveRecord | |||
'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] ; | |||
} | |||
} |
@@ -148,24 +148,9 @@ class CommandeController extends \yii\web\Controller { | |||
$etablissements = Yii::$app->user->identity->getEtablissementsFavoris(); | |||
// 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 | |||
$commandes = Commande::find() |
@@ -4,6 +4,7 @@ namespace frontend\controllers; | |||
use Yii; | |||
use common\models\Produit; | |||
use common\models\LoginForm; | |||
use common\models\Etablissement; | |||
use frontend\models\PasswordResetRequestForm; | |||
use frontend\models\ResetPasswordForm; | |||
use frontend\models\SignupForm; | |||
@@ -187,8 +188,15 @@ class SiteController extends Controller | |||
} | |||
} | |||
// liste des boulangeries disponibles | |||
$etablissements = Etablissement::getEtablissementsPopulateDropdown() ; | |||
$data_etablissements_dispos = $etablissements['data'] ; | |||
$options_etablissements_dispos = $etablissements['options'] ; | |||
return $this->render('signup', [ | |||
'model' => $model, | |||
'data_etablissements_dispos' => $data_etablissements_dispos, | |||
'options_etablissements_dispos' => $options_etablissements_dispos, | |||
]); | |||
} | |||
@@ -1,10 +1,11 @@ | |||
<?php | |||
namespace frontend\models; | |||
use Yii; | |||
use common\models\User; | |||
use common\models\Etablissement; | |||
use yii\base\Model; | |||
use Yii; | |||
use common\models\UserEtablissement ; | |||
/** | |||
* Signup form | |||
@@ -23,6 +24,8 @@ class SignupForm extends Model | |||
public $nom_magasin; | |||
public $code_postal; | |||
public $ville; | |||
public $id_etablissement ; | |||
public $option_client_boulanger ; | |||
/** | |||
* @inheritdoc | |||
@@ -35,26 +38,39 @@ class SignupForm extends Model | |||
['email', 'email'], | |||
['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', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | |||
['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', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||
return $model->is_boulanger ; | |||
return $model->option_client_boulanger == 'boulanger' ; | |||
},'whenClient' => "function (attribute, value) { | |||
return $('#signupform-is_boulanger').prop('checked') ; | |||
return $('#option-boulanger').prop('checked') ; | |||
}"], | |||
['siret', 'string'], | |||
['siret', 'required','message'=>'Champs obligatoire', 'when' => function($model) { | |||
return $model->is_boulanger ; | |||
return $model->option_client_boulanger == 'boulanger' ; | |||
},'whenClient' => "function (attribute, value) { | |||
return $('#signupform-is_boulanger').prop('checked') ; | |||
return $('#option-boulanger').prop('checked') ; | |||
}"], | |||
['siret', function($attribute, $params) { | |||
@@ -111,8 +127,9 @@ class SignupForm extends Model | |||
$user->telephone = $this->telephone ; | |||
$user->confiance = 1 ; | |||
if($this->is_boulanger) | |||
if($this->option_client_boulanger == 'boulanger') | |||
{ | |||
// etablissement | |||
$etablissement = new Etablissement ; | |||
$etablissement->nom = $this->nom_magasin ; | |||
$etablissement->siret = $this->siret; | |||
@@ -120,6 +137,7 @@ class SignupForm extends Model | |||
$etablissement->ville = $this->ville; | |||
$etablissement->save() ; | |||
// user | |||
$user->id_etablissement = $etablissement->id ; | |||
$user->status = User::STATUS_BOULANGER ; | |||
} | |||
@@ -128,25 +146,50 @@ class SignupForm extends Model | |||
$user->generateAuthKey(); | |||
if ($user->save()) { | |||
// 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. | |||
Si vous avez des questions, n'hésitez pas à me contacter. | |||
À bientôt, | |||
Matthieu" ; | |||
Guillaume" ; | |||
Yii::$app->mailer->compose() | |||
->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) | |||
->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 null; | |||
@@ -165,7 +208,8 @@ Matthieu" ; | |||
'nom_magasin' => 'Nom de la boulangerie', | |||
'siret' => 'Numéro SIRET', | |||
'code_postal' => 'Code postal', | |||
'ville' => 'Commune' | |||
'ville' => 'Commune', | |||
'id_etablissement' => 'Ma boulangerie', | |||
]; | |||
} | |||
} |
@@ -20,14 +20,28 @@ $this->params['breadcrumbs'][] = $this->title; | |||
<?= $form->field($model, 'nom') ?> | |||
<?= $form->field($model, 'prenom') ?> | |||
<?= $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"> | |||
<?= $form->field($model, 'nom_magasin') ?> | |||
<?= $form->field($model, 'siret') ?> | |||
<?= $form->field($model, 'code_postal') ?> | |||
<?= $form->field($model, 'ville') ?> | |||
</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']) ?> | |||
</div> | |||
<?php ActiveForm::end(); ?> |
@@ -451,9 +451,22 @@ ul li { | |||
/* signup */ | |||
/* 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 { | |||
display: none; | |||
} | |||
/* line 468, ../sass/screen.scss */ | |||
#form-signup #boutons-inscrire { | |||
margin-top: 30px; | |||
} | |||
/* line 2, ../sass/_systeme_commandes.scss */ | |||
h1.title-systeme-commande { |
@@ -26,7 +26,7 @@ function boulange_signup() | |||
if($('#form-signup').size()) | |||
{ | |||
boulange_signup_champs_boulanger() ; | |||
$('#signupform-is_boulanger').change(function() { | |||
$('#option-client, #option-boulanger').change(function() { | |||
boulange_signup_champs_boulanger() ; | |||
}) ; | |||
} | |||
@@ -34,12 +34,14 @@ function boulange_signup() | |||
function boulange_signup_champs_boulanger() | |||
{ | |||
if($('#signupform-is_boulanger').prop('checked')) | |||
if($('#option-boulanger').prop('checked')) | |||
{ | |||
$('#champs-boulanger').fadeIn() ; | |||
$('#champs-client').hide() ; | |||
} | |||
else { | |||
$('#champs-boulanger').hide() ; | |||
$('#champs-client').fadeIn() ; | |||
} | |||
} | |||
@@ -450,9 +450,24 @@ ul { | |||
/* signup */ | |||
#form-signup { | |||
#client-boulanger { | |||
margin-bottom: 30px ; | |||
} | |||
#signupform-id_etablissement { | |||
option:disabled { | |||
font-weight: bold ; | |||
color: black ; | |||
} | |||
} | |||
#champs-boulanger { | |||
display: none ; | |||
} | |||
#boutons-inscrire { | |||
margin-top: 30px; | |||
} | |||
} | |||
@import "_systeme_commandes.scss" ; |