Browse Source

[Backend] Utilisateur : retour à la liste après modification #1145

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
70c02d2181
2 changed files with 12 additions and 11 deletions
  1. +8
    -11
      backend/controllers/UserController.php
  2. +4
    -0
      backend/views/user/_form.php

+ 8
- 11
backend/controllers/UserController.php View File

use common\logic\User\User\Model\UserSearch; use common\logic\User\User\Model\UserSearch;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserUserGroup\Model\UserUserGroup; use common\logic\User\UserUserGroup\Model\UserUserGroup;
use Faker\Provider\HtmlLorem;
use yii\base\UserException; use yii\base\UserException;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use \Yii; use \Yii;
use yii\helpers\Html;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;


/** /**
$userProducerManager = $this->getUserProducerManager(); $userProducerManager = $this->getUserProducerManager();
$userGroupManager = $this->getUserGroupManager(); $userGroupManager = $this->getUserGroupManager();


$producerCurrent = $this->getProducerCurrent();

if ($model->id) { if ($model->id) {
$userPointSaleArray = $userPointSaleManager->findUserPointSalesByUser($model); $userPointSaleArray = $userPointSaleManager->findUserPointSalesByUser($model);
if ($userPointSaleArray && count($userPointSaleArray) > 0) { if ($userPointSaleArray && count($userPointSaleArray) > 0) {
{ {
$userManager = $this->getUserManager(); $userManager = $this->getUserManager();
$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$pointSaleManager = $this->getPointSaleManager();


$producerCurrent = $this->getProducerCurrent(); $producerCurrent = $this->getProducerCurrent();
$model = $userManager->instanciateUser(); $model = $userManager->instanciateUser();


} }


/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
*/
public function actionUpdate($id) public function actionUpdate($id)
{ {
$userManager = $this->getUserManager(); $userManager = $this->getUserManager();
$this->processLinkUserGroup($model); $this->processLinkUserGroup($model);
$this->processProductPricePercent($model); $this->processProductPricePercent($model);


$this->setFlash('success', 'Utilisateur modifié.');
$this->setFlash('success', 'Utilisateur <strong>'.Html::encode($userManager->getUsername($model)).'</strong> modifié.');

return $this->redirect(['index']);
} }
} else { } else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); throw new UserException("Vous ne pouvez pas modifier cet utilisateur.");
] ]
]); ]);


$this->setFlash('success', 'Nouveau mot de passe envoyé.');
$this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>'.Html::encode($userManager->getUsername($model)).'</strong>.');

return $this->redirect(['index']);
} }


return $this->render('update', array_merge($this->initForm($model), [ return $this->render('update', array_merge($this->initForm($model), [
$userProducerManager = $this->getUserProducerManager(); $userProducerManager = $this->getUserProducerManager();


$user = $userManager->findOneUserById($id); $user = $userManager->findOneUserById($id);
$producer = $this->getProducerCurrent();
$userProducer = $userProducerManager->findOneUserProducer($user); $userProducer = $userProducerManager->findOneUserProducer($user);


if ($userProducer) { if ($userProducer) {
$userProducerManager = $this->getUserProducerManager(); $userProducerManager = $this->getUserProducerManager();


$user = $userManager->findOneUserById($idUser); $user = $userManager->findOneUserById($idUser);
$producerCurrent = $this->getproducerCurrent();
$userProducer = $userProducerManager->findOneUserProducer($user); $userProducer = $userProducerManager->findOneUserProducer($user);


if ($userProducer) { if ($userProducer) {

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

<?= $form->field($model, 'evoliz_code')->textInput() ?> <?= $form->field($model, 'evoliz_code')->textInput() ?>
<?php endif; ?> <?php endif; ?>


<?php if($pointsSaleArray && count($pointsSaleArray) > 0): ?>
<?= $form->field($model, 'points_sale')->checkboxlist( <?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id', function ($pointSale) use ($model) { ArrayHelper::map($pointsSaleArray, 'id', function ($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : ''; $commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '';
'encode' => false 'encode' => false
]); ]);
?> ?>
<?php endif; ?>


<?php if($userGroupsArray && count($userGroupsArray) > 0): ?>
<?= $form->field($model, 'user_groups')->checkboxlist( <?= $form->field($model, 'user_groups')->checkboxlist(
ArrayHelper::map($userGroupsArray, 'id', function ($userGroup) use ($model) { ArrayHelper::map($userGroupsArray, 'id', function ($userGroup) use ($model) {
return Html::encode($userGroup->name); return Html::encode($userGroup->name);
'encode' => false 'encode' => false
]); ]);
?> ?>
<?php endif; ?>


<?php /* $form->field($model, 'product_price_percent') <?php /* $form->field($model, 'product_price_percent')
->dropDownList( ProductPrice::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit pour cet utilisateur.');*/ ?> ->dropDownList( ProductPrice::percentValues(), [])->hint('Pourcentage appliqué aux prix de chaque produit pour cet utilisateur.');*/ ?>

Loading…
Cancel
Save