|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\helpers\GlobalParam;
- use domain\User\UserGroup\UserGroupSearch;
- use domain\User\UserUserGroup\UserUserGroup;
- use yii\filters\AccessControl;
- use yii\helpers\Html;
- use yii\web\NotFoundHttpException;
-
-
- class UserGroupController 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()
- {
- $searchModel = new UserGroupSearch();
- $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
-
-
- public function actionCreate()
- {
- $userGroupModule = $this->getUserGroupModule();
-
- $model = $userGroupModule->instanciateUserGroup();
- $model->id_producer = GlobalParam::getCurrentProducerId();
-
- if ($model->load(\Yii::$app->request->post()) && $model->save()) {
- $this->setFlash('success', "Groupe d'utilisateur ajouté.");
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionUpdate(int $id)
- {
- $model = $this->findModel($id);
-
- if ($model->load(\Yii::$app->request->post()) && $model->save()) {
- $this->setFlash('success', "Groupe d'utilisateur modifié.");
- return $this->redirect(['index']);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionDelete(int $id)
- {
- $userGroup = $this->findModel($id);
- $userGroup->delete();
- UserUserGroup::deleteAll(['id_user_group' => $id]);
- $this->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.');
-
- return $this->redirect(['index']);
- }
-
-
-
- protected function findModel(int $id)
- {
- $userGroupModule = $this->getUserGroupModule();
- if (($model = $userGroupModule->findOneUserGroupById($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|