Переглянути джерело

Gestion des commentaires UserPointSale dans l'update/create de User

dev
Guillaume Bourgeois 5 роки тому
джерело
коміт
a8ae9d9561
4 змінених файлів з 64 додано та 23 видалено
  1. +40
    -22
      backend/controllers/UserController.php
  2. +12
    -1
      backend/views/user/_form.php
  3. +7
    -0
      backend/web/css/screen.css
  4. +5
    -0
      backend/web/sass/user/_form.scss

+ 40
- 22
backend/controllers/UserController.php Переглянути файл

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

/**
* UserController implements the CRUD actions for User model.
@@ -113,17 +114,30 @@ 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 ;
// init points de vente sélectionnés
if($model->id) {
$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() ;
// points de vente
$pointsSaleArray = PointSale::find()
->where([
'id_producer' => Producer::getId(),
])
->joinWith(['userPointSale' => function($query) use($model) {
if($model->id) {
$query->andOnCondition('user_point_sale.id_user = '.$model->id) ;
}
}])
->all();
return [
'pointsSaleArray' => $pointsSaleArray
] ;
@@ -161,13 +175,16 @@ class UserController extends BackendController

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

return $this->redirect(['index']);
} else {
return $this->render('create', array_merge($this->initForm($model),[
'model' => $model,
]));
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.');
$model = new User();
}
return $this->render('create', array_merge($this->initForm($model),[
'model' => $model,
]));
}

/**
@@ -195,16 +212,16 @@ class UserController extends BackendController
$model->sendMailWelcome($password) ;
}
$this->processLinkPointSale($model) ;
return $this->redirect(['index']);
} else {
return $this->render('update', array_merge($this->initForm($model),[
'model' => $model,
]));
Yii::$app->getSession()->setFlash('success', 'Utilisateur modifié.');
}
} 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.");
}
return $this->render('update', array_merge($this->initForm($model),[
'model' => $model,
]));
}
/**
@@ -214,12 +231,12 @@ class UserController extends BackendController
*/
public function processLinkPointSale($modelUser)
{
$posts = Yii::$app->request->post() ;
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
@@ -228,6 +245,7 @@ class UserController extends BackendController
$userPointSale = new UserPointSale ;
$userPointSale->id_user = $modelUser->id ;
$userPointSale->id_point_sale = $pointSaleId ;
$userPointSale->comment = isset($posts['User']['comment_point_sale_'.$pointSaleId]) ? $posts['User']['comment_point_sale_'.$pointSaleId] : '' ;
$userPointSale->save() ;
}
}

+ 12
- 1
backend/views/user/_form.php Переглянути файл

@@ -53,7 +53,18 @@ 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);})); ?>
<?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id',function($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '' ;
$html = Html::encode($pointSale->name);
if($pointSale->restricted_access) {
$html .= '<input type="text" placeholder="Commentaire" class="form-control" name="User[comment_point_sale_'.$pointSale->id.']" value="'.(($model->id) ? Html::encode($commentUserPointSale) : '').'" />' ;
}
return $html ;
}), [
'encode' => false
]);
?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

+ 7
- 0
backend/web/css/screen.css Переглянути файл

@@ -1977,6 +1977,13 @@ termes.
padding: 5px 10px;
border: solid 1px #e0e0e0;
}
/* line 13, ../sass/user/_form.scss */
.user-create #user-points_sale label .form-control,
.user-update #user-points_sale label .form-control {
display: inline;
width: 200px;
margin-left: 15px;
}

/* line 4, ../sass/producer/_update.scss */
.producer-update #nav-params {

+ 5
- 0
backend/web/sass/user/_form.scss Переглянути файл

@@ -10,6 +10,11 @@
padding: 5px 10px ;
border: solid 1px #e0e0e0 ;
.form-control {
display: inline ;
width: 200px;
margin-left: 15px ;
}
}
}
}

Завантаження…
Відмінити
Зберегти