|
|
|
@ -19,6 +19,9 @@ use yii\filters\VerbFilter;
|
|
|
|
|
use yii\helpers\Json; |
|
|
|
|
use yii\web\Controller; |
|
|
|
|
use yii\web\NotFoundHttpException; |
|
|
|
|
use DomainException; |
|
|
|
|
use yii\web\Response; |
|
|
|
|
use RuntimeException; |
|
|
|
|
use Yii; |
|
|
|
|
|
|
|
|
|
class MenuController extends Controller |
|
|
|
@ -70,7 +73,9 @@ class MenuController extends Controller
|
|
|
|
|
$menus = []; // menu list |
|
|
|
|
$menu_records = Menu::find()->all(); |
|
|
|
|
foreach ($menu_records as $menu_record) { |
|
|
|
|
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name; |
|
|
|
|
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name |
|
|
|
|
? $menu_record->translation->name |
|
|
|
|
: $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$form = new MenuSelectForm(); |
|
|
|
@ -105,7 +110,7 @@ class MenuController extends Controller
|
|
|
|
|
$menu = $this->menu_service->create($form); |
|
|
|
|
|
|
|
|
|
return $this->redirect(['index', 'id' => $menu->id]); |
|
|
|
|
} catch (\DomainException $e) { |
|
|
|
|
} catch (DomainException $e) { |
|
|
|
|
Yii::$app->errorHandler->logException($e); |
|
|
|
|
Yii::$app->session->setFlash('error', $e->getMessage()); |
|
|
|
|
} |
|
|
|
@ -126,7 +131,7 @@ class MenuController extends Controller
|
|
|
|
|
$this->menu_service->edit($menu->id, $form); |
|
|
|
|
|
|
|
|
|
return $this->redirect(['index', 'id' => $menu->id]); |
|
|
|
|
} catch (\DomainException $e) { |
|
|
|
|
} catch (DomainException $e) { |
|
|
|
|
Yii::$app->errorHandler->logException($e); |
|
|
|
|
Yii::$app->session->setFlash('error', $e->getMessage()); |
|
|
|
|
} |
|
|
|
@ -142,7 +147,7 @@ class MenuController extends Controller
|
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
$this->menu_service->remove($id); |
|
|
|
|
} catch (\DomainException $e) { |
|
|
|
|
} catch (DomainException $e) { |
|
|
|
|
Yii::$app->errorHandler->logException($e); |
|
|
|
|
Yii::$app->session->setFlash('error', $e->getMessage()); |
|
|
|
|
} |
|
|
|
@ -159,7 +164,7 @@ class MenuController extends Controller
|
|
|
|
|
$this->menu_item_service->edit($item->id, $form); |
|
|
|
|
|
|
|
|
|
return $this->redirect(['index', 'id' => $item->menu_id]); |
|
|
|
|
} catch (\DomainException $e) { |
|
|
|
|
} catch (DomainException $e) { |
|
|
|
|
Yii::$app->errorHandler->logException($e); |
|
|
|
|
Yii::$app->session->setFlash('error', $e->getMessage()); |
|
|
|
|
} |
|
|
|
@ -170,7 +175,7 @@ class MenuController extends Controller
|
|
|
|
|
|
|
|
|
|
public function actionDeleteMenuItem() |
|
|
|
|
{ |
|
|
|
|
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
|
|
|
if (Yii::$app->request->isAjax) { |
|
|
|
|
try { |
|
|
|
|
$id = Yii::$app->request->post('id'); |
|
|
|
@ -180,7 +185,7 @@ class MenuController extends Controller
|
|
|
|
|
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted')); |
|
|
|
|
|
|
|
|
|
return ['result' => 'success']; |
|
|
|
|
} catch (\RuntimeException $e) { |
|
|
|
|
} catch (RuntimeException $e) { |
|
|
|
|
return ['result' => 'error', 'message' => $e->getMessage()]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -191,7 +196,7 @@ class MenuController extends Controller
|
|
|
|
|
public function actionSaveMenuItems() |
|
|
|
|
{ |
|
|
|
|
$json = Yii::$app->request->post('json'); |
|
|
|
|
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
|
|
|
if (Yii::$app->request->isAjax) { |
|
|
|
|
try { |
|
|
|
|
$order = []; |
|
|
|
@ -203,7 +208,7 @@ class MenuController extends Controller
|
|
|
|
|
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved')); |
|
|
|
|
|
|
|
|
|
return ['result' => 'success']; |
|
|
|
|
} catch (\RuntimeException $e) { |
|
|
|
|
} catch (RuntimeException $e) { |
|
|
|
|
return ['result' => 'error', 'message' => $e->getMessage()]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -231,7 +236,7 @@ class MenuController extends Controller
|
|
|
|
|
if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
|
|
|
try { |
|
|
|
|
$this->menu_item_service->create($form); |
|
|
|
|
} catch (\DomainException $e) { |
|
|
|
|
} catch (DomainException $e) { |
|
|
|
|
Yii::$app->errorHandler->logException($e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|