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