|
|
@@ -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() ; |
|
|
|
} |
|
|
|
} |