|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\helpers\GlobalParam;
- use common\models\UserGroup;
- use common\models\UserUserGroup;
- use Yii;
- use yii\filters\AccessControl;
- use common\models\PointSale;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use common\models\User;
- use common\models\UserPointSale;
- use common\models\Order;
- use common\models\Producer;
- use common\models\Distribution;
- use yii\helpers\Html;
-
-
- class UserGroupController extends BackendController
- {
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::hasAccessBackend();
- }
- ],
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $searchModel = new UserGroupSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
-
-
- public function actionCreate()
- {
- $model = new UserGroup();
-
- $model->id_producer = GlobalParam::getCurrentProducerId() ;
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Yii::$app->getSession()->setFlash('success', "Groupe d'utilisateur ajouté.");
- return $this->redirect(['index']);
- }
- else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Yii::$app->getSession()->setFlash('success', "Groupe d'utilisateur modifié.");
- return $this->redirect(['index']);
- }
- else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionDelete($id)
- {
- $userGroup = $this->findModel($id);
-
- $userGroup->delete();
- UserUserGroup::deleteAll(['id_user_group' => $id]);
- Yii::$app->getSession()->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.');
-
- return $this->redirect(['index']);
- }
-
-
-
- protected function findModel($id)
- {
- if (($model = UserGroup::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|