|
- <?php
-
-
-
- namespace backend\controllers;
-
- use backend\models\AccessUserProducerForm;
- use domain\User\User\UserSearch;
- use yii\filters\AccessControl;
-
-
- class AccessController extends BackendController
- {
-
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return $this->getUserModule()
- ->getAuthorizationChecker()
- ->isGrantedAsProducer($this->getUserCurrent());
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $userModule = $this->getUserModule();
- $producer = $this->getProducerCurrent();
- $userSearch = new UserSearch();
- $usersArray = $userSearch->search([], $producer)->query->all();
-
- $modelAccessUserProducerForm = new AccessUserProducerForm;
- if ($modelAccessUserProducerForm->load(\Yii::$app->request->post()) && $modelAccessUserProducerForm->validate()) {
- $user = $userModule->findOneUserById($modelAccessUserProducerForm->id_user);
- if($user && $userModule->grantAccess($user)) {
- $this->setFlash('success', 'Droits ajoutés à l\'utilisateur');
- }
- else {
- $this->addFlash('error', "Une erreur est survenue.");
- }
- }
-
- return $this->render('index', [
- 'usersArray' => $usersArray,
- 'usersAccessArray' => $userModule->findUsersByProducer($producer),
- 'producer' => $producer,
- 'modelAccessUserProducerForm' => $modelAccessUserProducerForm,
- ]);
- }
-
- public function actionDelete($idUser)
- {
- $userModule = $this->getUserModule();
- $user = $userModule->findOneUserById($idUser);
-
- if ($user && $userModule->deleteAccess($user)) {
- $this->addFlash('success', 'Droits de l\'utilisateur supprimé.');
- }
- else {
- $this->addFlash('error', "Une erreur est survenue.");
- }
-
- return $this->redirect(['index']);
- }
- }
|