|
- <?php
-
- namespace backend\modules\motorcade\controllers;
-
- use common\models\BaseRole;
- use common\models\User;
- use Yii;
- use common\models\BaseUserAuth;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
-
- /**
- * AuthController implements the CRUD actions for BaseUserAuth model.
- */
- class AuthController extends Controller
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
-
- /**
- * Lists all BaseUserAuth models.
- * @return mixed
- */
- public function actionIndex()
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => BaseUserAuth::zFind(BaseUserAuth::SYS_FO)->joinWith('mainCorp'),
- ]);
-
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- /**
- * Displays a single BaseUserAuth model.
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
-
- /**
- * Creates a new BaseUserAuth model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new BaseUserAuth();
-
- $roles = BaseRole::find()->where(['and', ['CANCEL_FLAG'=> 0], [ '>=', 'id', '123'], ])->asArray()->all();
- if ($model->load(Yii::$app->request->post())) {
- /* @var $list array */
- $list = $model->role_list;
- $model->role_list = implode(',', $list);
- $model->sys = $model::SYS_FO;
- if($model->save()){
- User::updateAll(['MENU_PERMISSION'=> $model->role_list], ['USER_ROLE2'=> $model->id]);
- }
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- $model->role_list = explode(',', $model->role_list);
- return $this->render('create', [
- 'model' => $model,
- 'roles' => $roles,
- ]);
- }
- }
-
- /**
- * Updates an existing BaseUserAuth model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
-
- $roles = BaseRole::find()->where(['and', ['CANCEL_FLAG'=> 0], [ '>=', 'id', '123'], ])->asArray()->all();
- // if(Yii::$app->request->isPost){
- // /* @var $model->role_list array */
- // $model->role_list = implode(',', $model->role_list);
- // }
- if ($model->load(Yii::$app->request->post())) {
- /* @var $list array */
- $list = $model->role_list;
- $model->role_list = implode(',', $list);
- $model->sys = $model::SYS_FO;
- if($model->save()){
- User::updateAll(['MENU_PERMISSION'=> $model->role_list], ['USER_ROLE2'=> $model->id]);
- }
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- $model->role_list = explode(',', $model->role_list);
- return $this->render('update', [
- 'model' => $model,
- 'roles' => $roles,
- ]);
- }
- }
- /**
- * Deletes an existing BaseUserAuth model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
-
- return $this->redirect(['index']);
- }
-
- /**
- * Finds the BaseUserAuth model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return BaseUserAuth the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = BaseUserAuth::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|