Adaptation des fonctionnalités dépendantes suite à l'ajout du champs "actif" dans la table "user_etablissement".prodstable
{ | { | ||||
// 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) | ||||
{ | { |
->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() ; | ||||
</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" /> |
<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> |
->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() ; |
->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']) ; | ||||
} | } | ||||
} | } | ||||
$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.') ; | ||||
} | } | ||||
} | } |
$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() ; | ||||
} | } | ||||