Преглед изворни кода

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

refactoring
Guillaume Bourgeois пре 5 година
родитељ
комит
08291eaddb
8 измењених фајлова са 86 додато и 6 уклоњено
  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 Прегледај датотеку

@@ -43,6 +43,7 @@ use common\models\Producer ;
use common\models\Distribution ;
use backend\models\MailForm ;
use common\models\UserProducer ;
use common\models\UserPointSale ;

/**
* UserController implements the CRUD actions for User model.
@@ -110,6 +111,24 @@ class UserController extends BackendController
]);
}
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.
* If creation is successful, the browser will be redirected to the 'view' page.
@@ -141,12 +160,13 @@ class UserController extends BackendController
$useProducer->save();

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

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

@@ -174,18 +194,46 @@ class UserController extends BackendController
$model->username = $model->email;
$model->sendMailWelcome($password) ;
}
$this->processLinkPointSale($model) ;
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
return $this->render('update', array_merge($this->initForm($model),[
'model' => $model,
]));
}
} 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.");
}
}
/**
* 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.
*

+ 1
- 0
backend/views/user/_form.php Прегледај датотеку

@@ -53,6 +53,7 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?>
<?= $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">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

+ 1
- 0
backend/views/user/create.php Прегледај датотеку

@@ -50,6 +50,7 @@ $this->addBreadcrumb('Ajouter') ;
<?php else: ?>
<?= $this->render('_form', [
'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?>
<?php endif; ?>
</div>

+ 1
- 0
backend/views/user/update.php Прегледај датотеку

@@ -48,5 +48,6 @@ $this->addBreadcrumb('Modifier') ;
<div class="user-update">
<?= $this->render('_form', [
'model' => $model,
'pointsSaleArray' => $pointsSaleArray
]) ?>
</div>

+ 11
- 0
backend/web/css/screen.css Прегледај датотеку

@@ -1967,6 +1967,17 @@ termes.
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 */
.producer-update #nav-params {
margin-bottom: 30px;

+ 1
- 0
backend/web/sass/screen.scss Прегледај датотеку

@@ -1334,5 +1334,6 @@ a.btn, button.btn {
@import "distribution/_index.scss" ;
@import "user/_emails.scss" ;
@import "user/_credit.scss" ;
@import "user/_form.scss" ;
@import "producer/_update.scss" ;
@import "point_sale/_index.scss" ;

+ 15
- 0
backend/web/sass/user/_form.scss Прегледај датотеку

@@ -0,0 +1,15 @@

.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 Прегледај датотеку

@@ -70,6 +70,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
var $password_old;
var $password_new;
var $password_new_confirm;
var $points_sale = [] ;

/**
* @inheritdoc
@@ -105,7 +106,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
['password_old', 'verifyPasswordOld'],
['password_new', 'verifyPasswordNew'],
['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'],
];
}
@@ -129,6 +130,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
'password_old' => 'Ancien mot de passe',
'password_new' => 'Nouveau mot de passe',
'password_new_confirm' => 'Confirmation du nouveau mot de passe',
'points_sale' => 'Points de vente'
];
}

Loading…
Откажи
Сачувај