|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\helpers\GlobalParam;
- use common\models\Producer ;
- use common\models\User ;
- use common\models\UserSearch ;
- use backend\models\AccessUserProducerForm ;
-
-
- class AccessController 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()
- {
- $userSearch = new UserSearch ;
- $usersArray = $userSearch->search()->query->all() ;
-
- $modelAccessUserProducerForm = new AccessUserProducerForm ;
- if($modelAccessUserProducerForm->load(Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) {
- Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur');
- }
-
- $usersAccessArray = User::find()
- ->where([
- 'id_producer' => GlobalParam::getCurrentProducerId(),
- 'status' => User::STATUS_PRODUCER
- ])
- ->all() ;
-
- $producer = Producer::searchOne() ;
-
- return $this->render('index', [
- 'usersArray' => $usersArray,
- 'usersAccessArray' => $usersAccessArray,
- 'producer' => $producer,
- 'modelAccessUserProducerForm' => $modelAccessUserProducerForm,
- ]);
- }
-
-
-
- public function actionDelete($idUser)
- {
- $user = User::searchOne([
- 'id' => $idUser
- ]) ;
-
- if($user) {
- $user->id_producer = 0 ;
- $user->status = User::STATUS_ACTIVE ;
- $user->save() ;
- Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.');
- }
-
- return $this->redirect(['index']) ;
- }
-
- }
|