| Current Path : /var/www/html/school/backend/controllers/ |
| Current File : /var/www/html/school/backend/controllers/MenuController.php |
<?php
//namespace app\controllers;
namespace backend\controllers;
use Yii;
use backend\models\Menu;
use backend\models\MenuSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\components\AccessRule;
/**
* MenuController implements the CRUD actions for Menu model.
*/
class MenuController extends Controller {
/**
* @inheritdoc
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index','index-frontend','delete-frontend' ,'update-frontend' ,'create-frontend' ,'create' , 'update', 'view','delete'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
// 'delete' => ['POST'],
],
],
];
}
/**
* Lists all Menu models.
* @return mixed
*/
public function actionIndex() {
//exit;
$searchModel = new MenuSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='10'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'moduleArr' => $moduleArr,
'menucat' => '10',
]);
}
public function actionIndexfrontend() {
//exit;
$searchModel = new MenuSearch();
$dataProvider = $searchModel->searchFrontEnd(Yii::$app->request->queryParams);
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='11'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'moduleArr' => $moduleArr,
'menucat' => '11',
]);
}
/**
* Displays a single Menu model.
* @param integer $id
* @return mixed
*/
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Menu model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate() {
$model = new Menu();
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='10'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
if ($model->load(Yii::$app->request->post())) {
$model->menucat = 10;
$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 menu has been successfully added.'));
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
'moduleArr' => $moduleArr,
]);
}
}
public function actionCreatefrontend() {
$model = new Menu();
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='11'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
if ($model->load(Yii::$app->request->post())) {
$model->menucat = '11';
if ($model->save()) {
$menuBm = new \backend\models\MenuLang();
$menuBm->menu_id = $model->id;
$menuBm->menu_txt = $_POST['Menu']['menu_txtbm'];
$menuBm->menu_lang = '2';
if ($menuBm->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 menu has been successfully added.'));
return $this->redirect(['indexfrontend', 'id' => $model->id]);
}
}
} else {
return $this->render('createfrontend', [
'model' => $model,
'moduleArr' => $moduleArr,
]);
}
}
/**
* Updates an existing Menu 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);
// $mainmenu = MainMenu::find()->where(['id' => $id])->one();
// $menu = Menu::find()->where(['id' => $id])->one();
// $menuaccess = Menu::find()->where(['menu_parent_id' => $menu->id])->all();
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='10'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
// $moduleArr2 = [];
// $main = MainMenu::find()->where("cat = 'MAIN'")->all();
//// $main->modulecd = $model->modulecd;
// foreach ($main as $param2) {
// $moduleArr2[$param2->id] = $param2->descr;
// }
// if ($model->validate()) {
// $menuaccess->descr = $model->descr;
// }
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', 'The menu has been successfully updated.'));
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
'moduleArr' => $moduleArr,
]);
}
}
public function actionUpdatefrontend($id) {
$model = $this->findModel($id);
$menuBm = \backend\models\MenuLang::find()->where(['menu_id' => $id])->one();
$moduleArr = [];
$module = Menu::find()->where("module_ind = '1' AND menucat='11'")->all();
foreach ($module as $param) {
$moduleArr[$param->id] = $param->menu_txt;
}
if ($model->load(Yii::$app->request->post())) {
$model->menucat = '11';
if ($model->save()) {
$menuBm->menu_id = $model->id;
$menuBm->menu_txt = $_POST['Menu']['menu_txtbm'];
$menuBm->menu_lang = '2';
if ($menuBm->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 menu has been successfully added.'));
return $this->redirect(['indexfrontend', 'id' => $model->id]);
}
}
} else {
return $this->render('updatefrontend', [
'model' => $model,
'menuBm' => $menuBm,
'moduleArr' => $moduleArr,
]);
}
}
/**
* 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']);
}
public function actionDeletefrontend($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(['indexfrontend']);
}
/**
* Finds the Menu model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Menu the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = Menu::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}