|
- <?php
-
-
-
- namespace backend\controllers;
-
- use domain\User\User\UserSearch;
- use Yii;
- use yii\filters\AccessControl;
-
- 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 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();
- }
- }
- }
|