Browse Source

Crédit pain : comportement user_etablissement

Adaptation des fonctionnalités dépendantes suite à l'ajout du champs 
"actif" dans la table "user_etablissement".
prodstable
keun 8 years ago
parent
commit
7b457ac38b
8 changed files with 43 additions and 11 deletions
  1. +2
    -2
      backend/controllers/CommandeController.php
  2. +4
    -0
      backend/controllers/UserController.php
  3. +1
    -1
      backend/views/commande/index.php
  4. +1
    -1
      backend/views/commandeauto/_form.php
  5. +1
    -0
      common/models/User.php
  6. +3
    -1
      frontend/controllers/CommandeController.php
  7. +27
    -6
      frontend/models/AddEtablissementForm.php
  8. +4
    -0
      frontend/models/SignupForm.php

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

{ {


// changement état // changement état
$production = Production::find()->where(['date' => $date])->one();
$production = Production::find()->where(['date' => $date, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])->one();
$production->actif = $actif; $production->actif = $actif;
$production->save(); $production->save();
// add commandes automatiques // add commandes automatiques
if($actif) if($actif)
{ {

+ 4
- 0
backend/controllers/UserController.php View File

->select('*') ->select('*')
->from('user, user_etablissement') ->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user') ->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.actif = 1')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) ->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)
]); ]);
$user_etablissement = new UserEtablissement() ; $user_etablissement = new UserEtablissement() ;
$user_etablissement->id_user = $model->id ; $user_etablissement->id_user = $model->id ;
$user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement ; $user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement ;
$user_etablissement->credit = 0 ;
$user_etablissement->actif = 1 ;
$user_etablissement->save() ; $user_etablissement->save() ;
// send mail // send mail
->select('*') ->select('*')
->from('user, user_etablissement') ->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user') ->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.actif = 1')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) ->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)
->all() ; ->all() ;

+ 1
- 1
backend/views/commande/index.php View File

</span> </span>
<span class="the-title"></span> <span class="the-title"></span>
<span class="choix-user"> <span class="choix-user">
<?= Html::activeDropDownList(new User, 'id', ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->all(), 'id', function($model, $defaultValue) {
<?= Html::activeDropDownList(new User, 'id', ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->andWhere('user_etablissement.actif = 1')->all(), 'id', function($model, $defaultValue) {
return $model['nom'].' '.$model['prenom']; return $model['nom'].' '.$model['prenom'];
}), ['prompt' => '--','class' => 'form-control user-id']) ?> }), ['prompt' => '--','class' => 'form-control user-id']) ?>
OU <input type="text" class="form-control username" placeholder="Choisissez un nom" /> OU <input type="text" class="form-control username" placeholder="Choisissez un nom" />

+ 1
- 1
backend/views/commandeauto/_form.php View File

<div class="commandeauto-form"> <div class="commandeauto-form">
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> <?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?>
<div class="col-md-5" id="bloc-select-user"> <div class="col-md-5" id="bloc-select-user">
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->orderBy('nom ASC, prenom ASC')->all(), 'id', function($model, $defaultValue) {
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->andWhere('user_etablissement.actif = 1')->orderBy('nom ASC, prenom ASC')->all(), 'id', function($model, $defaultValue) {
return $model['nom'].' '.$model['prenom']; return $model['nom'].' '.$model['prenom'];
}), ['prompt' => '--','class' => 'form-control user-id', ]) ?> }), ['prompt' => '--','class' => 'form-control user-id', ]) ?>
</div> </div>

+ 1
- 0
common/models/User.php View File

->from(['user_etablissement', 'etablissement']) ->from(['user_etablissement', 'etablissement'])
->where('user_etablissement.id_etablissement = etablissement.id') ->where('user_etablissement.id_etablissement = etablissement.id')
->andWhere(['user_etablissement.id_user' => $this->id]) ->andWhere(['user_etablissement.id_user' => $this->id])
->andWhere(['user_etablissement.actif' => 1])
->all(); ->all();
$arr_etabs = array() ; $arr_etabs = array() ;

+ 3
- 1
frontend/controllers/CommandeController.php View File

->where(['id_etablissement'=>$id, 'id_user' => Yii::$app->user->identity->id]) ->where(['id_etablissement'=>$id, 'id_user' => Yii::$app->user->identity->id])
->one() ; ->one() ;
$user_etablissement->delete() ;
$user_etablissement->actif = 0 ;
$user_etablissement->save() ;
$this->redirect(['commande/index']) ; $this->redirect(['commande/index']) ;
} }



+ 27
- 6
frontend/models/AddEtablissementForm.php View File

} }
$user_etablissement_exist = UserEtablissement::find() $user_etablissement_exist = UserEtablissement::find()
->where(['id_user'=>Yii::$app->user->identity->id, 'id_etablissement' =>$this->id_etablissement])
->where([
'id_user' => Yii::$app->user->identity->id,
'id_etablissement' => $this->id_etablissement,
'actif' => 1
])
->one() ; ->one() ;
if($user_etablissement_exist) if($user_etablissement_exist)
{ {
$etablissement = Etablissement::findOne($this->id_etablissement) ; $etablissement = Etablissement::findOne($this->id_etablissement) ;
$user_etablissement = new UserEtablissement() ;
$user_etablissement->id_user = Yii::$app->user->identity->id ;
$user_etablissement->id_etablissement = $this->id_etablissement ;
$user_etablissement->save() ;

$user_etablissement_exist = UserEtablissement::find()
->where([
'id_user' => Yii::$app->user->identity->id,
'id_etablissement' => $this->id_etablissement,
'actif' => 0
])
->one() ;
if($user_etablissement_exist)
{
$user_etablissement_exist->actif = 1 ;
$user_etablissement_exist->save() ;
}
else {
$user_etablissement = new UserEtablissement() ;
$user_etablissement->id_user = Yii::$app->user->identity->id ;
$user_etablissement->id_etablissement = $this->id_etablissement ;
$user_etablissement->credit = 0 ;
$user_etablissement->actif = 1 ;
$user_etablissement->save() ;
}
Yii::$app->session->setFlash('success', 'La boulangerie <strong>'.Html::encode($etablissement->nom).'</strong> a bien été ajoutée à votre tableau de bord.') ; Yii::$app->session->setFlash('success', 'La boulangerie <strong>'.Html::encode($etablissement->nom).'</strong> a bien été ajoutée à votre tableau de bord.') ;
} }
} }

+ 4
- 0
frontend/models/SignupForm.php View File

$etab_user = new UserEtablissement ; $etab_user = new UserEtablissement ;
$etab_user->id_etablissement = $this->id_etablissement ; $etab_user->id_etablissement = $this->id_etablissement ;
$etab_user->id_user = $user->id ; $etab_user->id_user = $user->id ;
$etab_user->credit = 0 ;
$etab_user->actif = 1 ;
$etab_user->save() ; $etab_user->save() ;
} }
} }
$etab_user = new UserEtablissement ; $etab_user = new UserEtablissement ;
$etab_user->id_etablissement = $etablissement->id ; $etab_user->id_etablissement = $etablissement->id ;
$etab_user->id_user = $user->id ; $etab_user->id_user = $user->id ;
$etab_user->credit = 0 ;
$etab_user->actif = 1 ;
$etab_user->save() ; $etab_user->save() ;
} }

Loading…
Cancel
Save