|
- <?php
-
-
-
- namespace backend\controllers;
-
- use domain\User\User\UserSearch;
- use Yii;
- use yii\filters\AccessControl;
- use yii\web\NotFoundHttpException;
-
- class UserAdminController extends BackendController
- {
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return $this->getUserModule()
- ->getAuthorizationChecker()
- ->isGrantedAsAdministrator($this->getUserCurrent());
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $searchModel = new UserSearch();
- $dataProvider = $searchModel->search([
- 'UserSearch' => isset(\Yii::$app->request->queryParams['UserSearch']) ?
- Yii::$app->request->queryParams['UserSearch'] : []
- ]);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider
- ]);
- }
-
- public function actionEmailDeliverability()
- {
- $searchModel = new UserSearch();
- $searchModel->problem_receiving_emails = true;
- $dataProvider = $searchModel->search([
- 'UserSearch' => isset(\Yii::$app->request->queryParams['UserSearch']) ?
- Yii::$app->request->queryParams['UserSearch'] : []
- ]);
-
- return $this->render('email_deliverability', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider
- ]);
- }
-
- public function actionReportProblemReceivingEmails(int $id)
- {
- $user = $this->findModel($id);
-
- if($this->getUserModule()->getManager()->reportProblemReceivingEmails($user)) {
- $this->setFlash('success', "L'utilisateur <strong>".$this->getUserModule()->getSolver()->getUsername($user)."</strong> a bien été signalé comme ayant des problèmes dans la réception de vos emails. L'administrateur débloquera la situation dès que possible et préviendra l'utilisateur.");
- }
- else {
- $this->setFlash('error', "Une erreur est survenue.");
- }
-
- return $this->redirect('index');
- }
-
- public function actionRedirectView(int $idUserProducer)
- {
- $userCurrent = $this->getUserCurrent();
- $userProducer = $this->getUserProducerModule()->getRepository()->findOneUserProducerById($idUserProducer);
- if($userProducer) {
- $user = $userProducer->user;
- $producer = $userProducer->producer;
- $this->getUserModule()->getBuilder()->switchProducer($userCurrent, $producer);
- return $this->redirect(['user/view', 'id' => $user->id]);
- }
- else {
- $this->addFlash('error', "L'utilisateur n'a pas été trouvé.");
- return $this->redirectReferer();
- }
- }
-
- protected function findModel($id)
- {
- if (($user = $this->getUserModule()->findOneUserById($id)) !== null) {
- return $user;
- } else {
- throw new NotFoundHttpException("Utilisateur introuvable");
- }
- }
- }
|