Browse Source

Adapter le formulaire d'inscription à l'entité Etablissement

prodstable
keun 8 years ago
parent
commit
b7ae7814a8
4 changed files with 26 additions and 25 deletions
  1. +2
    -2
      backend/controllers/UserController.php
  2. +3
    -3
      common/models/User.php
  3. +19
    -20
      frontend/models/SignupForm.php
  4. +2
    -0
      frontend/views/site/signup.php

+ 2
- 2
backend/controllers/UserController.php View File

'query' => 'query' =>
(new \yii\db\Query()) (new \yii\db\Query())
->select('*') ->select('*')
->from('user, user_boulangerie')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user') ->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id) ->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
]); ]);
$users = (new \yii\db\Query()) $users = (new \yii\db\Query())
->select('*') ->select('*')
->from('user, user_boulangerie')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user') ->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id) ->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
->all() ; ->all() ;

+ 3
- 3
common/models/User.php View File

return [ return [
['confiance','default','value'=>0], ['confiance','default','value'=>0],
[['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'], [['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'],
[['nom','prenom','telephone','adresse', 'description'], 'string'],
[['nom','prenom','telephone','adresse'], 'string'],
[['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'], [['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'],
['email','email','message'=> 'Cette adresse email n\'est pas valide'], ['email','email','message'=> 'Cette adresse email n\'est pas valide'],
['email','verifyEmail'], ['email','verifyEmail'],
['status', 'default', 'value' => self::STATUS_ACTIVE], ['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN]],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN,self::STATUS_BOULANGER ]],
]; ];
} }


public function getNomMagasin() public function getNomMagasin()
{ {
$etablissement = Etablissement::find($this->id_etablissement)->one() ;
$etablissement = Etablissement::findOne($this->id_etablissement) ;
return $etablissement->nom ; return $etablissement->nom ;
} }

+ 19
- 20
frontend/models/SignupForm.php View File

namespace frontend\models; namespace frontend\models;


use common\models\User; use common\models\User;
use common\models\Etablissement;
use yii\base\Model; use yii\base\Model;
use Yii; use Yii;


public $prenom; public $prenom;
public $telephone; public $telephone;
public $is_boulanger; public $is_boulanger;
public $siret; public $siret;
public $nom_magasin; public $nom_magasin;

public $code_postal;
public $ville;
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
/*['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet identifiant est déjà utilisé'],
['username', 'string', 'min' => 2, 'max' => 255],*/

['email', 'filter', 'filter' => 'trim'], ['email', 'filter', 'filter' => 'trim'],
['email', 'required','message'=>'Champs obligatoire'], ['email', 'required','message'=>'Champs obligatoire'],
['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','required','message'=>'Champs obligatoire'],
['nom', 'string', 'min' => 2, 'max' => 255],
['prenom','required','message'=>'Champs obligatoire'],
['prenom', 'string', 'min' => 2, 'max' => 255],
['telephone','required','message'=>'Champs obligatoire'],
['telephone', 'string', 'min' => 2, 'max' => 255, 'message'=>'Bada'],
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'],'required','message'=>'Champs obligatoire'],
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'], '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'],
{ {
if ($this->validate()) { if ($this->validate()) {
$user = new User(); $user = new User();
//$user->username = $this->username;
$user->username = $this->email; $user->username = $this->email;
$user->email = $this->email; $user->email = $this->email;
$user->nom = $this->nom ; $user->nom = $this->nom ;
if($this->is_boulanger) if($this->is_boulanger)
{ {
$user->is_boulanger = 1 ;
$user->nom_magasin = $this->nom_magasin ;
$user->siret = $this->siret ;
$etablissement = new Etablissement ;
$etablissement->nom = $this->nom_magasin ;
$etablissement->siret = $this->siret;
$etablissement->code_postal = $this->code_postal;
$etablissement->ville = $this->ville;
$etablissement->save() ;
$user->id_etablissement = $etablissement->id ;
$user->status = User::STATUS_BOULANGER ;
} }
$user->setPassword($this->password); $user->setPassword($this->password);
$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,


'telephone' => 'Téléphone', 'telephone' => 'Téléphone',
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation de pain dans ma boulangerie", 'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation de pain dans ma boulangerie",
'nom_magasin' => 'Nom de la boulangerie', 'nom_magasin' => 'Nom de la boulangerie',
'siret' => 'Numéro SIRET'
'siret' => 'Numéro SIRET',
'code_postal' => 'Code postal',
'ville' => 'Commune'
]; ];
} }
} }

+ 2
- 0
frontend/views/site/signup.php View File

<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, 'ville') ?>
</div> </div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton("S'inscrire", ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?> <?= Html::submitButton("S'inscrire", ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>

Loading…
Cancel
Save