Commit 7765bf97b8dc7025502c3f9dd566952f9317dc9f

Authored by Dmitryi
1 parent 583ea05f

menu no perevod

backend/controllers/MenuController.php
@@ -4,10 +4,11 @@ namespace backend\controllers; @@ -4,10 +4,11 @@ namespace backend\controllers;
4 4
5 use Yii; 5 use Yii;
6 use common\models\Menu; 6 use common\models\Menu;
7 -use backend\models\SearchMenu; 7 +use backend\models\MenuSearch;
8 use yii\web\Controller; 8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException; 9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 10 use yii\filters\VerbFilter;
  11 +use common\models\TerminLang;
11 12
12 /** 13 /**
13 * MenuController implements the CRUD actions for Menu model. 14 * MenuController implements the CRUD actions for Menu model.
@@ -32,7 +33,7 @@ class MenuController extends Controller @@ -32,7 +33,7 @@ class MenuController extends Controller
32 */ 33 */
33 public function actionIndex() 34 public function actionIndex()
34 { 35 {
35 - $searchModel = new SearchMenu(); 36 + $searchModel = new MenuSearch();
36 $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 37 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
37 38
38 return $this->render('index', [ 39 return $this->render('index', [
@@ -61,14 +62,33 @@ class MenuController extends Controller @@ -61,14 +62,33 @@ class MenuController extends Controller
61 public function actionCreate() 62 public function actionCreate()
62 { 63 {
63 $model = new Menu(); 64 $model = new Menu();
64 - $x = Menu::find()->all();  
65 65
66 - if ($model->load(Yii::$app->request->post()) && $model->save()) { 66 + $menu = yii::$app->db->createCommand('
  67 + SELECT *
  68 + FROM `menu`
  69 + LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id
  70 + ')->queryAll();
  71 +
  72 +
  73 + $termin = TerminLang::find()->all();
  74 +
  75 + if ($model->load(Yii::$app->request->post())) {
  76 +
  77 + if($model->menu_pid == null)
  78 + {
  79 + $model->menu_pid = 0;
  80 + }
  81 +
  82 +
  83 + $model->save();
  84 +
  85 +
67 return $this->redirect(['view', 'id' => $model->menu_id]); 86 return $this->redirect(['view', 'id' => $model->menu_id]);
68 } else { 87 } else {
69 return $this->render('create', [ 88 return $this->render('create', [
70 'model' => $model, 89 'model' => $model,
71 - 'x' => $x, 90 + 'termin' => $termin,
  91 + 'menu' => $menu,
72 ]); 92 ]);
73 } 93 }
74 } 94 }
@@ -82,12 +102,22 @@ class MenuController extends Controller @@ -82,12 +102,22 @@ class MenuController extends Controller
82 public function actionUpdate($id) 102 public function actionUpdate($id)
83 { 103 {
84 $model = $this->findModel($id); 104 $model = $this->findModel($id);
  105 + $menu = yii::$app->db->createCommand('
  106 + SELECT *
  107 + FROM `menu`
  108 + LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id
  109 + ')->queryAll() + ['termin_id' => 0, 'termin_title' => 'ROOT'];
  110 +
  111 +
  112 + $termin = TerminLang::find()->all();
85 113
86 if ($model->load(Yii::$app->request->post()) && $model->save()) { 114 if ($model->load(Yii::$app->request->post()) && $model->save()) {
87 return $this->redirect(['view', 'id' => $model->menu_id]); 115 return $this->redirect(['view', 'id' => $model->menu_id]);
88 } else { 116 } else {
89 return $this->render('update', [ 117 return $this->render('update', [
90 'model' => $model, 118 'model' => $model,
  119 + 'termin' => $termin,
  120 + 'menu' => $menu,
91 ]); 121 ]);
92 } 122 }
93 } 123 }
backend/views/menu/_form.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 use yii\helpers\Html; 3 use yii\helpers\Html;
4 use yii\widgets\ActiveForm; 4 use yii\widgets\ActiveForm;
5 use yii\helpers\ArrayHelper; 5 use yii\helpers\ArrayHelper;
  6 +use kartik\select2\Select2;
6 7
7 /* @var $this yii\web\View */ 8 /* @var $this yii\web\View */
8 /* @var $model common\models\Menu */ 9 /* @var $model common\models\Menu */
@@ -13,16 +14,36 @@ use yii\helpers\ArrayHelper; @@ -13,16 +14,36 @@ use yii\helpers\ArrayHelper;
13 14
14 <?php $form = ActiveForm::begin(); ?> 15 <?php $form = ActiveForm::begin(); ?>
15 16
16 - <?= $form->field($model, 'menu_pid')->dropDownList(ArrayHelper::map($x, 'menu_id', 'menu_id')) ?> 17 +
17 18
18 - <?= $form->field($model, 'termin_id')->textInput() ?> 19 + <?= $form->field($model, 'termin_id')->widget(Select2::classname(), [
  20 + //'data' => $data,
  21 + 'language' => 'ru',
  22 + 'options' => ['placeholder' => 'под меню ...'],
  23 + 'pluginOptions' => [
  24 +
  25 + ],
  26 + 'data' => ArrayHelper::map($termin, 'termin_id', 'termin_title'), // data as array
  27 + ]) ?>
19 28
20 - <?= $form->field($model, 'show')->textInput() ?> 29 + <?= $form->field($model, 'menu_pid')->widget(Select2::classname(), [
  30 + //'data' => $data,
  31 + 'language' => 'ru',
  32 + 'options' => ['placeholder' => 'Меню родитель ...'],
  33 + 'pluginOptions' => [
  34 +
  35 + ],
  36 + 'data' => ArrayHelper::map($menu, 'termin_id', 'termin_title'), // data as array
  37 + ]) ?>
21 38
22 - <?= $form->field($model, 'sortorder')->textInput() ?> 39 +
  40 +
  41 + <?= $form->field($model, 'show')->dropDownList(['1' => Yii::t('action', 'show'), '0' => Yii::t('action', 'hide')]) ?>
  42 +
  43 + <?= $form->field($model, 'sortorder')->dropDownList(['1' => '1', '0' => '2']) ?>
23 44
24 <div class="form-group"> 45 <div class="form-group">
25 - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 46 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
26 </div> 47 </div>
27 48
28 <?php ActiveForm::end(); ?> 49 <?php ActiveForm::end(); ?>
backend/views/menu/_search.php
@@ -4,7 +4,7 @@ use yii\helpers\Html; @@ -4,7 +4,7 @@ use yii\helpers\Html;
4 use yii\widgets\ActiveForm; 4 use yii\widgets\ActiveForm;
5 5
6 /* @var $this yii\web\View */ 6 /* @var $this yii\web\View */
7 -/* @var $model backend\models\SearchMenu */ 7 +/* @var $model backend\models\MenuSearch */
8 /* @var $form yii\widgets\ActiveForm */ 8 /* @var $form yii\widgets\ActiveForm */
9 ?> 9 ?>
10 10
@@ -30,8 +30,8 @@ use yii\widgets\ActiveForm; @@ -30,8 +30,8 @@ use yii\widgets\ActiveForm;
30 <?php // echo $form->field($model, 'sortorder') ?> 30 <?php // echo $form->field($model, 'sortorder') ?>
31 31
32 <div class="form-group"> 32 <div class="form-group">
33 - <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>  
34 - <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> 33 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  34 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
35 </div> 35 </div>
36 36
37 <?php ActiveForm::end(); ?> 37 <?php ActiveForm::end(); ?>
backend/views/menu/create.php
@@ -6,8 +6,8 @@ use yii\helpers\Html; @@ -6,8 +6,8 @@ use yii\helpers\Html;
6 /* @var $this yii\web\View */ 6 /* @var $this yii\web\View */
7 /* @var $model common\models\Menu */ 7 /* @var $model common\models\Menu */
8 8
9 -$this->title = 'Create Menu';  
10 -$this->params['breadcrumbs'][] = ['label' => 'Menus', 'url' => ['index']]; 9 +$this->title = Yii::t('app', 'Create Menu');
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Menus'), 'url' => ['index']];
11 $this->params['breadcrumbs'][] = $this->title; 11 $this->params['breadcrumbs'][] = $this->title;
12 ?> 12 ?>
13 <div class="menu-create"> 13 <div class="menu-create">
@@ -16,7 +16,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -16,7 +16,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 16
17 <?= $this->render('_form', [ 17 <?= $this->render('_form', [
18 'model' => $model, 18 'model' => $model,
19 - 'x' => $x, 19 + 'termin' => $termin,
  20 + 'menu' => $menu,
20 ]) ?> 21 ]) ?>
21 22
22 </div> 23 </div>
backend/views/menu/index.php
@@ -4,10 +4,10 @@ use yii\helpers\Html; @@ -4,10 +4,10 @@ use yii\helpers\Html;
4 use yii\grid\GridView; 4 use yii\grid\GridView;
5 5
6 /* @var $this yii\web\View */ 6 /* @var $this yii\web\View */
7 -/* @var $searchModel backend\models\SearchMenu */ 7 +/* @var $searchModel backend\models\MenuSearch */
8 /* @var $dataProvider yii\data\ActiveDataProvider */ 8 /* @var $dataProvider yii\data\ActiveDataProvider */
9 9
10 -$this->title = 'Menus'; 10 +$this->title = Yii::t('app', 'Menus');
11 $this->params['breadcrumbs'][] = $this->title; 11 $this->params['breadcrumbs'][] = $this->title;
12 ?> 12 ?>
13 <div class="menu-index"> 13 <div class="menu-index">
@@ -16,7 +16,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -16,7 +16,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 <?php // echo $this->render('_search', ['model' => $searchModel]); ?> 16 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17 17
18 <p> 18 <p>
19 - <?= Html::a('Create Menu', ['create'], ['class' => 'btn btn-success']) ?> 19 + <?= Html::a(Yii::t('app', 'Create Menu'), ['create'], ['class' => 'btn btn-success']) ?>
20 </p> 20 </p>
21 21
22 <?= GridView::widget([ 22 <?= GridView::widget([
@@ -27,8 +27,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -27,8 +27,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
27 27
28 'menu_id', 28 'menu_id',
29 'menu_pid', 29 'menu_pid',
30 - 'menu_lft',  
31 - 'menu_rgt', 30 + [
  31 + 'attribute' => 'menu_pid',
  32 + 'value' => function ($model) {
  33 + return empty($model->termin_id) ? '-' : $model->termin_lang->termin_title;
  34 + },
  35 + ],
  36 + // 'menu_lft',
  37 + // 'menu_rgt',
32 'termin_id', 38 'termin_id',
33 // 'show', 39 // 'show',
34 // 'sortorder', 40 // 'sortorder',
backend/views/menu/update.php
@@ -5,10 +5,12 @@ use yii\helpers\Html; @@ -5,10 +5,12 @@ use yii\helpers\Html;
5 /* @var $this yii\web\View */ 5 /* @var $this yii\web\View */
6 /* @var $model common\models\Menu */ 6 /* @var $model common\models\Menu */
7 7
8 -$this->title = 'Update Menu: ' . ' ' . $model->menu_id;  
9 -$this->params['breadcrumbs'][] = ['label' => 'Menus', 'url' => ['index']]; 8 +$this->title = Yii::t('app', 'Update {modelClass}: ', [
  9 + 'modelClass' => 'Menu',
  10 +]) . ' ' . $model->menu_id;
  11 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Menus'), 'url' => ['index']];
10 $this->params['breadcrumbs'][] = ['label' => $model->menu_id, 'url' => ['view', 'id' => $model->menu_id]]; 12 $this->params['breadcrumbs'][] = ['label' => $model->menu_id, 'url' => ['view', 'id' => $model->menu_id]];
11 -$this->params['breadcrumbs'][] = 'Update'; 13 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
12 ?> 14 ?>
13 <div class="menu-update"> 15 <div class="menu-update">
14 16
@@ -16,6 +18,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;; @@ -16,6 +18,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;;
16 18
17 <?= $this->render('_form', [ 19 <?= $this->render('_form', [
18 'model' => $model, 20 'model' => $model,
  21 + 'termin' => $termin,
  22 + 'menu' => $menu,
19 ]) ?> 23 ]) ?>
20 24
21 </div> 25 </div>
backend/views/menu/view.php
@@ -7,7 +7,7 @@ use yii\widgets\DetailView; @@ -7,7 +7,7 @@ use yii\widgets\DetailView;
7 /* @var $model common\models\Menu */ 7 /* @var $model common\models\Menu */
8 8
9 $this->title = $model->menu_id; 9 $this->title = $model->menu_id;
10 -$this->params['breadcrumbs'][] = ['label' => 'Menus', 'url' => ['index']]; 10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Menus'), 'url' => ['index']];
11 $this->params['breadcrumbs'][] = $this->title; 11 $this->params['breadcrumbs'][] = $this->title;
12 ?> 12 ?>
13 <div class="menu-view"> 13 <div class="menu-view">
@@ -15,11 +15,11 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -15,11 +15,11 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
15 <h1><?= Html::encode($this->title) ?></h1> 15 <h1><?= Html::encode($this->title) ?></h1>
16 16
17 <p> 17 <p>
18 - <?= Html::a('Update', ['update', 'id' => $model->menu_id], ['class' => 'btn btn-primary']) ?>  
19 - <?= Html::a('Delete', ['delete', 'id' => $model->menu_id], [ 18 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->menu_id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->menu_id], [
20 'class' => 'btn btn-danger', 20 'class' => 'btn btn-danger',
21 'data' => [ 21 'data' => [
22 - 'confirm' => 'Are you sure you want to delete this item?', 22 + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
23 'method' => 'post', 23 'method' => 'post',
24 ], 24 ],
25 ]) ?> 25 ]) ?>
common/models/Menu.php
@@ -31,7 +31,7 @@ class Menu extends \yii\db\ActiveRecord @@ -31,7 +31,7 @@ class Menu extends \yii\db\ActiveRecord
31 public function rules() 31 public function rules()
32 { 32 {
33 return [ 33 return [
34 - [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'required'], 34 + [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'safe'],
35 [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'integer'] 35 [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'integer']
36 ]; 36 ];
37 } 37 }
@@ -42,13 +42,14 @@ class Menu extends \yii\db\ActiveRecord @@ -42,13 +42,14 @@ class Menu extends \yii\db\ActiveRecord
42 public function attributeLabels() 42 public function attributeLabels()
43 { 43 {
44 return [ 44 return [
45 - 'menu_id' => 'Menu ID',  
46 - 'menu_pid' => 'Menu Pid',  
47 - 'menu_lft' => 'Menu Lft',  
48 - 'menu_rgt' => 'Menu Rgt',  
49 - 'termin_id' => 'Termin ID',  
50 - 'show' => 'Show',  
51 - 'sortorder' => 'Sortorder', 45 + 'menu_id' => Yii::t('app', 'Menu ID'),
  46 + 'menu_pid' => Yii::t('app', 'Menu Pid'),
  47 + 'menu_lft' => Yii::t('app', 'Menu Lft'),
  48 + 'menu_rgt' => Yii::t('app', 'Menu Rgt'),
  49 + 'termin_id' => Yii::t('app', 'Termin ID'),
  50 + 'show' => Yii::t('app', 'Show'),
  51 + 'sortorder' => Yii::t('app', 'Sortorder'),
52 ]; 52 ];
53 } 53 }
  54 +
54 } 55 }
common/models/TerminLang.php
@@ -44,4 +44,9 @@ class TerminLang extends \yii\db\ActiveRecord @@ -44,4 +44,9 @@ class TerminLang extends \yii\db\ActiveRecord
44 'lang_id' => 'ID языка', 44 'lang_id' => 'ID языка',
45 ]; 45 ];
46 } 46 }
  47 +
  48 + public function getMenu()
  49 + {
  50 + return $this->hasMany(Menu::className(), ['termin_id' => 'termin_id']);
  51 + }
47 } 52 }