Browse Source

Gestion de la liaisn utilisateur / point de vente dans les formulaires de création / modification d'un User

dev
Guillaume Bourgeois 5 years ago
parent
commit
08291eaddb
8 changed files with 86 additions and 6 deletions
  1. +53
    -5
      backend/controllers/UserController.php
  2. +1
    -0
      backend/views/user/_form.php
  3. +1
    -0
      backend/views/user/create.php
  4. +1
    -0
      backend/views/user/update.php
  5. +11
    -0
      backend/web/css/screen.css
  6. +1
    -0
      backend/web/sass/screen.scss
  7. +15
    -0
      backend/web/sass/user/_form.scss
  8. +3
    -1
      common/models/User.php

+ 53
- 5
backend/controllers/UserController.php View File

use common\models\Distribution ; use common\models\Distribution ;
use backend\models\MailForm ; use backend\models\MailForm ;
use common\models\UserProducer ; use common\models\UserProducer ;
use common\models\UserPointSale ;


/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.
]); ]);
} }
public function initForm($model)
{
$userPointSaleArray = UserPointSale::searchAll([
'id_user' => $model->id
]) ;
if($userPointSaleArray && count($userPointSaleArray) > 0) {
foreach($userPointSaleArray as $userPointSaleArray) {
$model->points_sale[] = $userPointSaleArray->id_point_sale ;
}
}
$pointsSaleArray = PointSale::searchAll() ;
return [
'pointsSaleArray' => $pointsSaleArray
] ;
}
/** /**
* Creates a new User model. * Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
$useProducer->save(); $useProducer->save();


$model->sendMailWelcome($password) ; $model->sendMailWelcome($password) ;
$this->processLinkPointSale($model) ;


return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', [
return $this->render('create', array_merge($this->initForm($model),[
'model' => $model, 'model' => $model,
]);
]));
} }
} }


$model->username = $model->email; $model->username = $model->email;
$model->sendMailWelcome($password) ; $model->sendMailWelcome($password) ;
} }
$this->processLinkPointSale($model) ;
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', [
'model' => $model,
]);
return $this->render('update', array_merge($this->initForm($model),[
'model' => $model,
]));
} }
} else { } else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs établissements, soit parce qu'il n'est pas lié au votre."); throw new UserException("Vous ne pouvez pas modifier cet utilisateur, soit parce qu'il appartient à plusieurs établissements, soit parce qu'il n'est pas lié au votre.");
} }
} }
/**
* Lie un utilisateur aux points de vente sélectionnés.
*
* @param User $modelUser
*/
public function processLinkPointSale($modelUser)
{
UserPointSale::deleteAll([
'id_user' => $modelUser->id
]) ;
if(is_array($modelUser->points_sale) && count($modelUser->points_sale) > 0) {
foreach($modelUser->points_sale as $pointSaleId) {
echo $modelUser->id.' / '.$pointSaleId.' <br />' ;
$userPointSale = UserPointSale::searchOne([
'id_user' => $modelUser->id,
'id_point_sale' => $pointSaleId
]) ;
if(!$userPointSale) {
$userPointSale = new UserPointSale ;
$userPointSale->id_user = $modelUser->id ;
$userPointSale->id_point_sale = $pointSaleId ;
$userPointSale->save() ;
}
}
}
}
/** /**
* Désactive l'utilisateur de l'établissement. * Désactive l'utilisateur de l'établissement.
* *

+ 1
- 0
backend/views/user/_form.php View File

<?= $form->field($model, 'phone')->textInput() ?> <?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?> <?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'address')->textarea() ?> <?= $form->field($model, 'address')->textarea() ?>
<?= $form->field($model, 'points_sale')->checkboxlist(ArrayHelper::map($pointsSaleArray, 'id',function($pointSale) { return Html::encode($pointSale->name);})); ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

+ 1
- 0
backend/views/user/create.php View File

<?php else: ?> <?php else: ?>
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?> ]) ?>
<?php endif; ?> <?php endif; ?>
</div> </div>

+ 1
- 0
backend/views/user/update.php View File

<div class="user-update"> <div class="user-update">
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?> ]) ?>
</div> </div>

+ 11
- 0
backend/web/css/screen.css View File

float: right; float: right;
} }


/* line 5, ../sass/user/_form.scss */
.user-create #user-points_sale label,
.user-update #user-points_sale label {
font-weight: normal;
margin-right: 10px;
cursor: pointer;
background-color: white;
padding: 5px 10px;
border: solid 1px #e0e0e0;
}

/* line 4, ../sass/producer/_update.scss */ /* line 4, ../sass/producer/_update.scss */
.producer-update #nav-params { .producer-update #nav-params {
margin-bottom: 30px; margin-bottom: 30px;

+ 1
- 0
backend/web/sass/screen.scss View File

@import "distribution/_index.scss" ; @import "distribution/_index.scss" ;
@import "user/_emails.scss" ; @import "user/_emails.scss" ;
@import "user/_credit.scss" ; @import "user/_credit.scss" ;
@import "user/_form.scss" ;
@import "producer/_update.scss" ; @import "producer/_update.scss" ;
@import "point_sale/_index.scss" ; @import "point_sale/_index.scss" ;

+ 15
- 0
backend/web/sass/user/_form.scss View File


.user-create,
.user-update {
#user-points_sale {
label {
font-weight: normal ;
margin-right: 10px ;
cursor: pointer ;
background-color: white ;
padding: 5px 10px ;
border: solid 1px #e0e0e0 ;
}
}
}

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

var $password_old; var $password_old;
var $password_new; var $password_new;
var $password_new_confirm; var $password_new_confirm;
var $points_sale = [] ;


/** /**
* @inheritdoc * @inheritdoc
['password_old', 'verifyPasswordOld'], ['password_old', 'verifyPasswordOld'],
['password_new', 'verifyPasswordNew'], ['password_new', 'verifyPasswordNew'],
['password_new_confirm', 'verifyPasswordNewConfirm'], ['password_new_confirm', 'verifyPasswordNewConfirm'],
[['date_last_connection', 'password_old', 'password_new', 'password_new_confirm', 'password_hash'], 'safe'],
[['date_last_connection', 'password_old', 'password_new', 'password_new_confirm', 'password_hash','points_sale'], 'safe'],
]; ];
} }
'password_old' => 'Ancien mot de passe', 'password_old' => 'Ancien mot de passe',
'password_new' => 'Nouveau mot de passe', 'password_new' => 'Nouveau mot de passe',
'password_new_confirm' => 'Confirmation du nouveau mot de passe', 'password_new_confirm' => 'Confirmation du nouveau mot de passe',
'points_sale' => 'Points de vente'
]; ];
} }

Loading…
Cancel
Save