| Current Path : /var/www/html/sprm/backend/controllers/ |
| Current File : /var/www/html/sprm/backend/controllers/RoleUserController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\Ref;
use backend\models\RefSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\components\AccessRule;
/**
* RefController implements the CRUD actions for Ref model.
*/
class RoleUserController extends Controller {
/**
* @inheritdoc
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index', 'create', 'update','update2','update3','update4', 'view', 'delete','deletegroup'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
// 'delete' => ['POST'],
],
],
];
}
public function actionIndex() {
$searchModel = new RefSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Ref model.
* @param integer $id
* @return mixed
*/
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
public function actionCreate() {
$model = new Ref();
if ($model->load(Yii::$app->request->post())) {
$model->cat = 'ROLE';
if ($model->save()) {
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $model->id;
$log->save();
Yii::$app->session->setFlash('success', Yii::t('app', 'Peranan baru berjaya ditambah.'));
return $this->redirect(['index', 'id' => $model->id]);
}
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Ref model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate2($id, $cityid, $parentid, $cat) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$model->cat = $cityid;
$model->param1 = $cat;
if ($model->save()) {
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $model->id;
$log->save();
Yii::$app->session->setFlash('success', Yii::t('app', 'PThe parameter has been successfully updated.'));
return $this->redirect(['list-data', 'id' => $cityid, 'parentid' => $parentid, 'cat' => $cat]);
}
} else {
return $this->render('update2', [
'model' => $model,
'id' => $id,
'cityid' => $cityid,
'parentid' => $parentid,
'cat' => $cat
]);
}
}
public function actionUpdate3($id, $id2, $cityid, $parentid, $cat, $child = '') {
$mRef = Ref::findOne($id2);
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
if ($cat == 'dae') {
$model->cat = 'mkm';
} else {
$model->cat = 'dun';
}
$model->param1 = $id2;
if ($model->save()) {
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $model->id;
$log->save();
Yii::$app->session->setFlash('success', Yii::t('app', 'The parameter has been successfully updated.'));
return $this->redirect(['index2', 'id' => $id2, 'cityid' => $cityid, 'parentid' => $parentid, 'cat' => $cat, 'child' => $child]);
}
} else {
return $this->render('update3', [
'model' => $model,
'mRef' => $mRef,
'id' => $id,
'id2' => $id2,
'cityid' => $cityid,
'parentid' => $parentid,
'cat' => $cat,
'child' => $child,
]);
}
}
public function actionUpdate4($id, $id2, $parentid) {
$mRef = Ref::findOne($id2);
$model = Ref::findOne($id);
if ($model->load(Yii::$app->request->post())) {
$model->cat = 'SUBETHNIC';
$model->param1 = $id2;
if ($model->save()) {
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $model->id;
$log->save();
Yii::$app->session->setFlash('success', Yii::t('app', 'The new parameter has been successfully added.'));
return $this->redirect(['index3', 'id' => $id2, 'parentid' => $parentid]);
}
} else {
return $this->render('update4', [
'model' => $model,
'mRef' => $mRef,
'id' => $id,
'id2' => $id2,
'parentid' => $parentid,
]);
}
}
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $model->id;
$log->save();
Yii::$app->session->setFlash('success', Yii::t('app', 'Peranan telah berjaya dikemaskini.'));
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Ref model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDeleteGroup($id) {
$model = $this->findModel($id);
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $id;
$childs = Ref::find()->where('cat="' . $model->code . '"')->all();
if (!empty($childs)) {
foreach ($childs as $child) {
$childs2 = Ref::find()->where('cat="' . $child->id . '"')->all();
if (!empty($childs2)) {
foreach ($childs2 as $child2) {
$childs3 = Ref::find()->where('cat="' . $child2->id . '"')->all();
if (!empty($childs3)) {
foreach ($childs3 as $child3) {
$childs4 = Ref::find()->where('cat="' . $child2->id . '"')->all();
if (!empty($childs4)) {
foreach ($childs4 as $child4) {
$child4->delete();
}
}
$child3->delete();
}
}
$child2->delete();
}
}
$child->delete();
}
}
$model->delete();
Yii::$app->session->setFlash('success', Yii::t('app', 'The parameter has been successful deleted.'));
return $this->redirect(['group-list']);
}
/**
* Deletes an existing Menu 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();
$log = new \backend\models\Log();
$log->module = Yii::$app->controller->id;
$log->details = Yii::$app->controller->action->id . ":" . $id;
$log->save();
return $this->redirect(['index']);
}
/**
* Finds the Ref model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Ref the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = Ref::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}