소스 검색

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

prodstable
keun 8 년 전
부모
커밋
b7ae7814a8
4개의 변경된 파일26개의 추가작업 그리고 25개의 파일을 삭제
  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 파일 보기

@@ -52,7 +52,7 @@ class UserController extends Controller
'query' =>
(new \yii\db\Query())
->select('*')
->from('user, user_boulangerie')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
]);
@@ -149,7 +149,7 @@ PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compt
$users = (new \yii\db\Query())
->select('*')
->from('user, user_boulangerie')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
->all() ;

+ 3
- 3
common/models/User.php 파일 보기

@@ -56,12 +56,12 @@ class User extends ActiveRecord implements IdentityInterface
return [
['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'],
[['nom','prenom','telephone','adresse', 'description'], 'string'],
[['nom','prenom','telephone','adresse'], 'string'],
[['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'],
['email','email','message'=> 'Cette adresse email n\'est pas valide'],
['email','verifyEmail'],
['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 ]],
];
}

@@ -234,7 +234,7 @@ class User extends ActiveRecord implements IdentityInterface
public function getNomMagasin()
{
$etablissement = Etablissement::find($this->id_etablissement)->one() ;
$etablissement = Etablissement::findOne($this->id_etablissement) ;
return $etablissement->nom ;
}

+ 19
- 20
frontend/models/SignupForm.php 파일 보기

@@ -2,6 +2,7 @@
namespace frontend\models;

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

@@ -17,33 +18,25 @@ class SignupForm extends Model
public $prenom;
public $telephone;
public $is_boulanger;
public $siret;
public $nom_magasin;

public $code_postal;
public $ville;
/**
* @inheritdoc
*/
public function rules()
{
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', 'required','message'=>'Champs obligatoire'],
['email', 'email'],
['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', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'],
@@ -111,7 +104,6 @@ class SignupForm extends Model
{
if ($this->validate()) {
$user = new User();
//$user->username = $this->username;
$user->username = $this->email;
$user->email = $this->email;
$user->nom = $this->nom ;
@@ -121,15 +113,20 @@ class SignupForm extends Model
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->generateAuthKey();
if ($user->save()) {
// envoi d'un mail de confirmation
$message = "Bonjour,

@@ -166,7 +163,9 @@ Matthieu" ;
'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",
'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 파일 보기

@@ -27,6 +27,8 @@ $this->params['breadcrumbs'][] = $this->title;
<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">
<?= Html::submitButton("S'inscrire", ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>

Loading…
취소
저장