|
|
|
|
|
|
|
|
* Liste les utilisateurs. |
|
|
* Liste les utilisateurs. |
|
|
*/ |
|
|
*/ |
|
|
public function actionIndex( |
|
|
public function actionIndex( |
|
|
int $idPointSale = 0, |
|
|
|
|
|
|
|
|
int $idPointSale = 0, |
|
|
bool $sectionSubscribers = false, |
|
|
bool $sectionSubscribers = false, |
|
|
bool $sectionInactiveUsers = false) |
|
|
bool $sectionInactiveUsers = false) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
'UserSearch' => array_merge( |
|
|
'UserSearch' => array_merge( |
|
|
[ |
|
|
[ |
|
|
'id_point_sale' => $idPointSale, |
|
|
'id_point_sale' => $idPointSale, |
|
|
'inactive' => (int) $sectionInactiveUsers, |
|
|
|
|
|
'subscribers' => (int) $sectionSubscribers |
|
|
|
|
|
|
|
|
'inactive' => (int)$sectionInactiveUsers, |
|
|
|
|
|
'subscribers' => (int)$sectionSubscribers |
|
|
], |
|
|
], |
|
|
isset(\Yii::$app->request->queryParams['UserSearch']) ? |
|
|
isset(\Yii::$app->request->queryParams['UserSearch']) ? |
|
|
Yii::$app->request->queryParams['UserSearch'] : |
|
|
Yii::$app->request->queryParams['UserSearch'] : |
|
|
|
|
|
|
|
|
$model->address, |
|
|
$model->address, |
|
|
$model->newsletter, |
|
|
$model->newsletter, |
|
|
Password::generate(), |
|
|
Password::generate(), |
|
|
(bool) $model->send_mail_welcome |
|
|
|
|
|
|
|
|
(bool)$model->send_mail_welcome |
|
|
); |
|
|
); |
|
|
$userCreate->points_sale = $model->points_sale; |
|
|
$userCreate->points_sale = $model->points_sale; |
|
|
$userCreate->user_groups = $model->user_groups; |
|
|
$userCreate->user_groups = $model->user_groups; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$model = $this->findModel($id); |
|
|
$model = $this->findModel($id); |
|
|
$previousMail = $model->email; |
|
|
$previousMail = $model->email; |
|
|
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); |
|
|
|
|
|
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); |
|
|
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); |
|
|
if ($userBelongToProducer) { |
|
|
if ($userBelongToProducer) { |
|
|
$model->newsletter = $userBelongToProducer->newsletter; |
|
|
$model->newsletter = $userBelongToProducer->newsletter; |
|
|
|
|
|
|
|
|
$this->processLinkUserGroup($model); |
|
|
$this->processLinkUserGroup($model); |
|
|
//$this->processProductPricePercent($model); |
|
|
//$this->processProductPricePercent($model); |
|
|
|
|
|
|
|
|
if($model->newsletter) { |
|
|
|
|
|
|
|
|
if ($model->newsletter) { |
|
|
$userModule->getNewsletterManager()->subscribeUserNewsletter($model); |
|
|
$userModule->getNewsletterManager()->subscribeUserNewsletter($model); |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
$userModule->getNewsletterManager()->unsubscribeUserNewsletter($model); |
|
|
$userModule->getNewsletterManager()->unsubscribeUserNewsletter($model); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->setFlash('success', 'Utilisateur <strong>'.Html::encode($userModule->getUsername($model)).'</strong> modifié.'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setFlash('success', 'Utilisateur <strong>' . Html::encode($userModule->getUsername($model)) . '</strong> modifié.'); |
|
|
return $this->redirect(['index']); |
|
|
return $this->redirect(['index']); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Nouveau mot de passe |
|
|
|
|
|
$newPassword = Yii::$app->request->post('submit_new_password'); |
|
|
|
|
|
if ($newPassword) { |
|
|
|
|
|
$password = Password::generate(); |
|
|
|
|
|
$userModule->setPassword($model, $password); |
|
|
|
|
|
$model->save(); |
|
|
|
|
|
|
|
|
|
|
|
$producer = $this->getProducerCurrent(); |
|
|
|
|
|
|
|
|
|
|
|
\Yii::$app->mailerService->sendFromProducer( |
|
|
|
|
|
'Nouveau mot de passe', |
|
|
|
|
|
'newPasswordUserAdmin', |
|
|
|
|
|
[ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'producer' => $producer, |
|
|
|
|
|
'password' => $password, |
|
|
|
|
|
], |
|
|
|
|
|
$model->email, |
|
|
|
|
|
$producer |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>'.Html::encode($userModule->getUsername($model)).'</strong>.'); |
|
|
|
|
|
|
|
|
// Email de bienvenue |
|
|
|
|
|
$mailWelcome = Yii::$app->request->post('submit_mail_welcome'); |
|
|
|
|
|
if ($mailWelcome) { |
|
|
|
|
|
$this->getUserModule()->getManager()->welcome($model); |
|
|
|
|
|
$this->setFlash('success', 'Email de bienvenue envoyé à <strong>' . Html::encode($userModule->getSolver()->getUsername($model)) . '</strong>.'); |
|
|
|
|
|
return $this->redirect(['update', 'id' => $model->id]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
|
|
|
|
|
|
// Mot de passe oublié |
|
|
|
|
|
$newPassword = Yii::$app->request->post('submit_new_password'); |
|
|
|
|
|
if ($newPassword) { |
|
|
|
|
|
$this->getUserModule()->getManager()->newPassword($model); |
|
|
|
|
|
$this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>' . Html::encode($userModule->getSolver()->getUsername($model)) . '</strong>.'); |
|
|
|
|
|
return $this->redirect(['update', 'id' => $model->id]); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->render('update', array_merge($this->initForm($model), [ |
|
|
return $this->render('update', array_merge($this->initForm($model), [ |
|
|
|
|
|
|
|
|
$userProducer = $userProducerModule->findOneUserProducer($user); |
|
|
$userProducer = $userProducerModule->findOneUserProducer($user); |
|
|
|
|
|
|
|
|
if ($userProducer) { |
|
|
if ($userProducer) { |
|
|
if($userProducerModule->hasOutstandingCredit($userProducer)) { |
|
|
|
|
|
|
|
|
if ($userProducerModule->hasOutstandingCredit($userProducer)) { |
|
|
$this->setFlash('error', "Vous ne pouvez pas supprimer cet utilisateur car il a toujours du crédit en cours."); |
|
|
$this->setFlash('error', "Vous ne pouvez pas supprimer cet utilisateur car il a toujours du crédit en cours."); |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
$userProducerModule->unlinkUserProducer($userProducer); |
|
|
$userProducerModule->unlinkUserProducer($userProducer); |
|
|
$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); |
|
|
$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$creditForm->comment |
|
|
$creditForm->comment |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if($creditForm->send_mail) { |
|
|
|
|
|
|
|
|
if ($creditForm->send_mail) { |
|
|
$paymentModule->getNotifier() |
|
|
$paymentModule->getNotifier() |
|
|
->notifyUserCreditMovement( |
|
|
->notifyUserCreditMovement( |
|
|
$user, |
|
|
$user, |
|
|
$creditForm->type, |
|
|
$creditForm->type, |
|
|
$creditForm->amount |
|
|
$creditForm->amount |
|
|
); |
|
|
); |
|
|
if(!$user->email) { |
|
|
|
|
|
|
|
|
if (!$user->email) { |
|
|
$this->addFlash('error', "L'utilisateur n'a pas pu être prévenu car son adresse email n'est pas définie."); |
|
|
$this->addFlash('error', "L'utilisateur n'a pas pu être prévenu car son adresse email n'est pas définie."); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$usersPointSaleHasOrder = 0) |
|
|
$usersPointSaleHasOrder = 0) |
|
|
{ |
|
|
{ |
|
|
$userModule = $this->getUserModule(); |
|
|
$userModule = $this->getUserModule(); |
|
|
$distributionModule = $this-> getDistributionModule(); |
|
|
|
|
|
|
|
|
$distributionModule = $this->getDistributionModule(); |
|
|
|
|
|
|
|
|
if ($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { |
|
|
if ($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { |
|
|
$usersPointSaleLink = 1; |
|
|
$usersPointSaleLink = 1; |
|
|
|
|
|
|
|
|
foreach ($users as $key => $user) { |
|
|
foreach ($users as $key => $user) { |
|
|
if (isset($user['email']) && strlen($user['email']) > 0) { |
|
|
if (isset($user['email']) && strlen($user['email']) > 0) { |
|
|
$usersArray[] = $user['email']; |
|
|
$usersArray[] = $user['email']; |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
unset($users[$key]); |
|
|
unset($users[$key]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionSwitchIdentity(int $id) |
|
|
public function actionSwitchIdentity(int $id) |
|
|
{ |
|
|
{ |
|
|
$userModule = $this->getUserModule(); |
|
|
$userModule = $this->getUserModule(); |
|
|
if($this->isUserCurrentAdmin()) { |
|
|
|
|
|
|
|
|
if ($this->isUserCurrentAdmin()) { |
|
|
$initialId = Yii::$app->user->getId(); |
|
|
$initialId = Yii::$app->user->getId(); |
|
|
if($initialId != $id) { |
|
|
|
|
|
|
|
|
if ($initialId != $id) { |
|
|
$user = $userModule->findOneUserById($id); |
|
|
$user = $userModule->findOneUserById($id); |
|
|
$duration = 0; |
|
|
$duration = 0; |
|
|
Yii::$app->user->switchIdentity($user, $duration); |
|
|
Yii::$app->user->switchIdentity($user, $duration); |
|
|
Yii::$app->session->set('user.idbeforeswitch',$initialId); |
|
|
|
|
|
|
|
|
Yii::$app->session->set('user.idbeforeswitch', $initialId); |
|
|
return $this->redirect(['index']); |
|
|
return $this->redirect(['index']); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
throw new NotFoundHttpException('Page introuvable'); |
|
|
throw new NotFoundHttpException('Page introuvable'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |