diff --git a/backend/config/bootstrap.php b/backend/config/bootstrap.php
index b3d9bbc..c81e9b4 100644
--- a/backend/config/bootstrap.php
+++ b/backend/config/bootstrap.php
@@ -1 +1,2 @@
[
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['post'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Language models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new LanguageSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Creates a new Language model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ if(!empty(Yii::$app->request->get('id'))) {
+ $model = $this->findModel(Yii::$app->request->get('id'));
+ $model->active = 1;
+ $model->save();
+ return $this->redirect(['index']);
+ } else {
+ $searchModel = new LanguageSearch();
+ $dataProvider = $searchModel->searchNew(Yii::$app->request->queryParams);
+
+ return $this->render('create', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+ }
+
+ /**
+ * Deletes an existing Language model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionDelete($id)
+ {
+ $model = $this->findModel($id);
+ $model->active = 0;
+ $model->save();
+
+ return $this->redirect(['index']);
+ }
+
+ public function actionDefault($id)
+ {
+ $model = $this->findModel($id);
+ $models = Language::find()->where(['is_default' => 1])->all();
+ foreach($models as $onemodel) {
+ $onemodel->is_default = 0;
+ $onemodel->save();
+ }
+ $model->is_default = 1;
+ $model->save();
+ return $this->redirect(['index']);
+ }
+ /**
+ * Finds the Language model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return Language the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = Language::findOne($id)) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+}
diff --git a/backend/controllers/OptionController.php b/backend/controllers/OptionController.php
new file mode 100644
index 0000000..1817d35
--- /dev/null
+++ b/backend/controllers/OptionController.php
@@ -0,0 +1,132 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['post'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Option models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new OptionSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single Option model.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new Option model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $form[0] = Option::create(\Yii::$app->request->post(), 'User', 10, [['name' => 'phone', 'template' => 'text', 'translate' => true], ['name' => 'adres', 'template' => 'text', 'translate' => false]]);
+ if($form[0]['success'] == false) {
+ return $this->render('create', ['forms' => $form]);
+ } else {
+ return $this->redirect(['index']);
+ }
+ }
+
+ /**
+ * Updates an existing Option model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionUpdate($id)
+ {
+ $form[0] = Option::change($id, \Yii::$app->request->post(), 'User', 10);
+ if($form[0]['success'] == false) {
+ return $this->render('update', ['forms' => $form]);
+ } else {
+ return $this->redirect(['view', 'id' => $id]);
+ }
+ }
+
+ /**
+ * Deletes an existing Option model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionDelete($id)
+ {
+ $model = $this->findModel($id);
+ $children = $model->hasMany(Option::className(), ['parent_id' => 'option_id'])->all();
+ $langs = array();
+ if(!empty($children)) {
+ foreach($children as $child) {
+ $langs = OptionLang::findAll(['id' => $child->option_id]);
+ foreach($langs as $lang) {
+ $lang->delete();
+ }
+ $child->delete();
+ }
+ }
+ $langs = OptionLang::findAll(['id' => $id]);
+ foreach($langs as $lang) {
+ $lang->delete();
+ }
+ $model->delete();
+
+ return $this->redirect(['index']);
+ }
+
+ /**
+ * Finds the Option model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return Option the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = Option::findOne($id)) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+}
diff --git a/backend/models/Language.php b/backend/models/Language.php
new file mode 100644
index 0000000..9b8e3ae
--- /dev/null
+++ b/backend/models/Language.php
@@ -0,0 +1,52 @@
+ 4],
+ [['language_name'], 'string', 'max' => 255]
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'language_id' => Yii::t('app', 'Language ID'),
+ 'lang_code' => Yii::t('app', 'Lang Code'),
+ 'is_default' => Yii::t('app', 'Is Default'),
+ 'language_name' => Yii::t('app', 'Language Name'),
+ 'active' => Yii::t('app', 'Active'),
+ ];
+ }
+}
diff --git a/backend/models/LanguageSearch.php b/backend/models/LanguageSearch.php
new file mode 100644
index 0000000..c4eed3f
--- /dev/null
+++ b/backend/models/LanguageSearch.php
@@ -0,0 +1,100 @@
+ $query,
+ ]);
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ $query->andFilterWhere([
+ 'language_id' => $this->language_id,
+ 'is_default' => $this->is_default,
+ 'active' => $this->active,
+ ]);
+
+ $query->andFilterWhere(['like', 'lang_code', $this->lang_code])
+ ->andFilterWhere(['like', 'language_name', $this->language_name])
+ ->andWhere(['active' => '1']);
+
+ return $dataProvider;
+ }
+
+ public function searchNew($params)
+ {
+ $query = Language::find();
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => $query,
+ ]);
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ $query->andFilterWhere([
+ 'language_id' => $this->language_id,
+ 'is_default' => $this->is_default,
+ 'active' => $this->active,
+ ]);
+
+ $query->andFilterWhere(['like', 'lang_code', $this->lang_code])
+ ->andFilterWhere(['like', 'language_name', $this->language_name])
+ ->andWhere(['active' => '0']);
+
+ return $dataProvider;
+ }
+}
diff --git a/backend/views/language/_search.php b/backend/views/language/_search.php
new file mode 100644
index 0000000..bd18a09
--- /dev/null
+++ b/backend/views/language/_search.php
@@ -0,0 +1,35 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'language_id') ?>
+
+ = $form->field($model, 'lang_code') ?>
+
+ = $form->field($model, 'is_default')->checkbox() ?>
+
+ = $form->field($model, 'language_name') ?>
+
+ = $form->field($model, 'active')->checkbox() ?>
+
+
+ = Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
+ = Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
+
+
+
+
+
diff --git a/backend/views/language/create.php b/backend/views/language/create.php
new file mode 100644
index 0000000..1014af0
--- /dev/null
+++ b/backend/views/language/create.php
@@ -0,0 +1,41 @@
+title = Yii::t('app', 'Languages');
+$this->params['breadcrumbs'][] = $this->title;
+echo $this->render('layout');
+?>
+
+
+ render('_search', ['model' => $searchModel]); ?>
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'layout' => "{items}",
+ 'columns' => [
+ 'language_name',
+ 'lang_code',
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => '{create}',
+ 'buttons' => [
+ 'create' => function ($url, $model, $key) {
+ return Html::a('', $url, ['class' => 'glyphicon glyphicon-plus', 'title' => Yii::t('app', 'Create Language')]);
+ },
+ ],
+ ]
+ ]
+ ]); ?>
+
+
+ = Html::a(Yii::t('app', 'Cancel'), ['index'], ['class' => 'btn btn-success']) ?>
+
+
+
diff --git a/backend/views/language/index.php b/backend/views/language/index.php
new file mode 100644
index 0000000..fa7fa10
--- /dev/null
+++ b/backend/views/language/index.php
@@ -0,0 +1,42 @@
+title = Yii::t('app', 'Languages');
+$this->params['breadcrumbs'][] = $this->title;
+echo $this->render('layout');
+?>
+
+
+ render('_search', ['model' => $searchModel]); ?>
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'layout' => "{items}",
+ 'columns' => [
+ 'language_name',
+ 'lang_code',
+ 'is_default:boolean',
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => '{default} {delete}',
+ 'buttons' => [
+ 'default' => function ($url, $model, $key) {
+ return Html::a('', $model->is_default?'#':$url, ['class' => $model->is_default?'glyphicon glyphicon-star':'glyphicon glyphicon-star-empty', 'title' => Yii::t('app', 'Make default')]);
+ },
+ ],
+ ]
+ ]
+ ]); ?>
+
+
+ = Html::a(Yii::t('app', 'Create Language'), ['create'], ['class' => 'btn btn-success']) ?>
+
+
+
diff --git a/backend/views/language/layout.php b/backend/views/language/layout.php
new file mode 100644
index 0000000..d917061
--- /dev/null
+++ b/backend/views/language/layout.php
@@ -0,0 +1,40 @@
+registerCssFile('/backend/web/css/language.css');
+$this->registerJsFile('/backend/web/js/language.js', ['depends' => ['yii\web\JqueryAsset'], 'position' => $this::POS_END]);
+$this->title = Yii::t('app', 'Settings');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
= Html::encode($this->title) ?>
+
+
diff --git a/backend/views/language/update.php b/backend/views/language/update.php
new file mode 100644
index 0000000..fbfe669
--- /dev/null
+++ b/backend/views/language/update.php
@@ -0,0 +1,23 @@
+title = Yii::t('app', 'Update {modelClass}: ', [
+ 'modelClass' => 'Language',
+]) . ' ' . $model->language_id;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Languages'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->language_id, 'url' => ['view', 'id' => $model->language_id]];
+$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/language/view.php b/backend/views/language/view.php
new file mode 100644
index 0000000..356f305
--- /dev/null
+++ b/backend/views/language/view.php
@@ -0,0 +1,39 @@
+title = $model->language_id;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Languages'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->language_id], ['class' => 'btn btn-primary']) ?>
+ = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->language_id], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'language_id',
+ 'lang_code',
+ 'is_default:boolean',
+ 'language_name',
+ 'active:boolean',
+ ],
+ ]) ?>
+
+
diff --git a/backend/views/option/_form.php b/backend/views/option/_form.php
new file mode 100644
index 0000000..32331a3
--- /dev/null
+++ b/backend/views/option/_form.php
@@ -0,0 +1,128 @@
+
+
+
diff --git a/backend/views/option/_form_edit.php b/backend/views/option/_form_edit.php
new file mode 100644
index 0000000..4a3dd57
--- /dev/null
+++ b/backend/views/option/_form_edit.php
@@ -0,0 +1,41 @@
+
+
+
diff --git a/backend/views/option/_search.php b/backend/views/option/_search.php
new file mode 100644
index 0000000..5fe0200
--- /dev/null
+++ b/backend/views/option/_search.php
@@ -0,0 +1,37 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'option_id') ?>
+
+ = $form->field($model, 'model') ?>
+
+ = $form->field($model, 'model_id') ?>
+
+ = $form->field($model, 'name') ?>
+
+ = $form->field($model, 'template') ?>
+
+ field($model, 'parent_id') ?>
+
+
+ = Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
+ = Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
+
+
+
+
+
diff --git a/backend/views/option/create.php b/backend/views/option/create.php
new file mode 100644
index 0000000..7c128cc
--- /dev/null
+++ b/backend/views/option/create.php
@@ -0,0 +1,19 @@
+title = Yii::t('app', 'Create Option');
+$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Options'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
= Html::encode($this->title) ?>
+ render('_form', $oneform);
+ }?>
+
+
diff --git a/backend/views/option/index.php b/backend/views/option/index.php
new file mode 100644
index 0000000..9deb2f6
--- /dev/null
+++ b/backend/views/option/index.php
@@ -0,0 +1,71 @@
+title = Yii::t('app', 'Options');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
+
= Html::encode($this->title) ?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
+ = Html::a(Yii::t('app', 'Create Option'), ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ 'option_id',
+ 'model',
+ 'model_id',
+ 'name',
+ 'template',
+ // 'parent_id',
+
+ ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
+
+
+
+
+
+
= Html::encode($this->title) ?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
+ = Html::a(Yii::t('app', 'Create Option'), ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ 'option_id',
+ 'model',
+ 'model_id',
+ 'name',
+ 'template',
+ // 'parent_id',
+
+ ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
+
+
+
\ No newline at end of file
diff --git a/backend/views/option/update.php b/backend/views/option/update.php
new file mode 100644
index 0000000..1bb652d
--- /dev/null
+++ b/backend/views/option/update.php
@@ -0,0 +1,21 @@
+title = Yii::t('app', 'Update {modelClass}: ', [
+ 'modelClass' => 'Option',
+]) . ' ' . $forms[0]['models'][\Yii::$app->request->get('id')]->name;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Options'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $forms[0]['models'][\Yii::$app->request->get('id')]->name, 'url' => ['view', 'id' => $forms[0]['models'][\Yii::$app->request->get('id')]->option_id]];
+$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
+?>
+
+
= Html::encode($this->title) ?>
+ render('_form_edit', $oneform);
+ }?>
+
+
diff --git a/backend/views/option/view.php b/backend/views/option/view.php
new file mode 100644
index 0000000..ba4d20b
--- /dev/null
+++ b/backend/views/option/view.php
@@ -0,0 +1,40 @@
+title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Options'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->option_id], ['class' => 'btn btn-primary']) ?>
+ = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->option_id], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'option_id',
+ 'model',
+ 'model_id',
+ 'name',
+ 'template',
+ 'parent_id',
+ ],
+ ]) ?>
+
+
diff --git a/backend/web/css/language.css b/backend/web/css/language.css
new file mode 100644
index 0000000..b2234a0
--- /dev/null
+++ b/backend/web/css/language.css
@@ -0,0 +1,89 @@
+section.content-header {
+ display: none;
+}
+section.content {
+ height: 100%;
+ padding: 0;
+}
+.content-wrapper {
+ background: #444444 !important;
+ position: absolute;
+ top: 50px;
+ height: calc(100% - 50px);
+ left:0;
+ width: calc(100% - 230px);
+}
+footer.main-footer {
+ position: absolute;
+ width: 100%;
+ bottom: 0;
+ left: 0;
+}
+footer.main-footer div.pull-right.hidden-xs {
+ margin-right: 230px;
+}
+.lang-column-1 {
+ float: left;
+ width: 50%;
+ height: 100%;
+ overflow: auto;
+}
+.lang-column-1 h1 {
+ text-align: center;
+ color: #ecf0f5;
+}
+.lang-column-2 {
+ background: #ecf0f5;
+ padding: 50px 10px 0 10px;
+ width: 50%;
+ height: 100%;
+ display:inline-block;
+}
+.settings_menu {
+ color: #ecf0f5;
+ white-space: normal !important;
+}
+.settings_menu a {
+ color: #ecf0f5;
+}
+.settings_menu a:focus {
+ color: #ecf0f5;
+}
+.settings_menu_inner {
+ list-style: none;
+ padding-left: 20px;
+ background: #2c3b41;
+}
+.settings_menu_inner li {
+ color: #8aa4af;
+ padding: 5px 0;
+}
+.settings_menu_inner li .grid-view {
+ background: #ecf0f5;
+ margin-right: 10px;
+ padding: 5px;
+ color: #8aa4af !important;
+}
+.settings_menu_inner li .grid-view a:hover, .settings_menu_inner li .grid-view a:focus {
+ color: #3C8DBC;
+}
+.settings_menu_inner li:hover {
+ color: #ecf0f5;
+ padding: 5px 0;
+}
+.settings_menu_inner li:focus {
+ color: #ecf0f5;
+ padding: 5px 0;
+}
+.settings_menu_inner li a {
+ color: #8aa4af;
+}
+.settings_menu_inner li a:hover {
+ color: #ecf0f5;
+}
+.settings_menu_inner li a:focus {
+ color: #ecf0f5;
+}
+.settings_menu_inner li a.glyphicon {
+ padding-left: 15px;
+}
\ No newline at end of file
diff --git a/backend/web/js/language.js b/backend/web/js/language.js
new file mode 100644
index 0000000..131b298
--- /dev/null
+++ b/backend/web/js/language.js
@@ -0,0 +1,6 @@
+$(function() {
+ $(document).on('click', '.settings_menu>li>a', function() {
+ console.log('event');
+ $(this).parent().toggleClass('active');
+ });
+});
\ No newline at end of file
diff --git a/common/config/main.php b/common/config/main.php
index ef701e2..d484172 100644
--- a/common/config/main.php
+++ b/common/config/main.php
@@ -27,9 +27,9 @@ return [
],
'i18n' => [
'translations' => [
- '*' => [
+ 'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
- 'basePath' => $_SERVER['DOCUMENT_ROOT'].'/common/translation',
+ 'basePath' => '@common/translation',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
@@ -41,4 +41,5 @@ return [
'class' => 'yii\rbac\DbManager',
],
],
+ 'language' => 'ru-RU'
];
diff --git a/common/translation/ru/app.php b/common/translation/ru/app.php
new file mode 100644
index 0000000..733671c
--- /dev/null
+++ b/common/translation/ru/app.php
@@ -0,0 +1,11 @@
+ 'Добавить',
+ 'Settings' => 'Настройки',
+ 'languages' => 'Языки',
+ 'Languages' => 'Языки',
+ 'Language list' => 'Список языков',
+ 'roles' => 'Роли',
+ 'Create Language' => 'Добавить язык',
+ 'Cancel' => 'Отмена'
+];
\ No newline at end of file
diff --git a/frontend/controllers/OptionController.php b/frontend/controllers/OptionController.php
index ee6fcd7..d2e93d8 100644
--- a/frontend/controllers/OptionController.php
+++ b/frontend/controllers/OptionController.php
@@ -61,7 +61,7 @@ class OptionController extends Controller
*/
public function actionCreate()
{
- $form[0] = Option::create(\Yii::$app->request->post(), 'User', 10, [['name' => 'phone', 'template' => 'text'], ['name' => 'adres', 'template' => 'text']]);
+ $form[0] = Option::create(\Yii::$app->request->post(), 'User', 10, [['name' => 'phone', 'template' => 'text', 'translate' => true], ['name' => 'adres', 'template' => 'text', 'translate' => false]]);
if($form[0]['success'] == false) {
return $this->render('create', ['forms' => $form]);
} else {
diff --git a/frontend/models/Option.php b/frontend/models/Option.php
index ed4383f..dd316df 100644
--- a/frontend/models/Option.php
+++ b/frontend/models/Option.php
@@ -73,21 +73,33 @@ class Option extends \yii\db\ActiveRecord
if(!empty($post)) {
foreach($post['Option'] as $key => $option) {
if(in_array($key, array('model', 'model_id'))) { continue; }
+ if(empty($option['value'][$models[$key]->name]) && !empty($option['lang'])) {
+ foreach($option['lang'] as $lang_id => $lang) {
+ if(!empty($lang)) {
+ $option['value'][$models[$key]->name] = $lang;
+ break;
+ }
+ }
+ }
$modellang[$key][0]->value = $option['value'][$models[$key]->name];
- if(!$modellang[$key][0]->save()) {
+ if(empty($modellang[$key][0]->value) || !$modellang[$key][0]->save()) {
$ok = 0;
+ $models[$key]->addError('value', 'Value must be set');
+ $modellang[$key][0]->addError('value', 'Value must be set');
}
- foreach($option['lang'] as $lang_id => $lang) {
- if(empty($modellang[$key][$lang_id])) {
- $modellang[$key][$lang_id] = new OptionLang();
- $modellang[$key][$lang_id]->id = $models[$key]->option_id;
- $modellang[$key][$lang_id]->lang_id = $lang_id;
- $modellang[$key][$lang_id]->value = $lang;
- } else {
- $modellang[$key][$lang_id]->value = $lang;
- }
- if(!$modellang[$key][$lang_id]->save()) {
- $ok = 0;
+ if(!empty($option['lang'])) {
+ foreach($option['lang'] as $lang_id => $lang) {
+ if(empty($modellang[$key][$lang_id])) {
+ $modellang[$key][$lang_id] = new OptionLang();
+ $modellang[$key][$lang_id]->id = $models[$key]->option_id;
+ $modellang[$key][$lang_id]->lang_id = $lang_id;
+ $modellang[$key][$lang_id]->value = $lang;
+ } else {
+ $modellang[$key][$lang_id]->value = $lang;
+ }
+ if(!$modellang[$key][$lang_id]->save()) {
+ $ok = 0;
+ }
}
}
}
@@ -125,12 +137,21 @@ class Option extends \yii\db\ActiveRecord
$models[$index][$key] = new Option();
$models[$index][$key]->model = $post['Option']['model'];
$models[$index][$key]->model_id = $post['Option']['model_id'];
- $models[$index][$key]->template = $option['template'];
+ $models[$index][$key]->template = $option[$key]['template'];
+ $models[$index][$key]->translate = $option[$key]['translate']?1:0;
$models[$index][$key]->name = $key;
if(!$first) {
$models[$index][$key]->parent_id = $parentid;
}
$modelslang[$index][$key][0] = new OptionLang();
+ if(!empty($option['lang'][$key])) {
+ foreach($option['lang'][$key] as $code => $lang) {
+ if(!empty($lang)) {
+ $value = $lang;
+ break;
+ }
+ }
+ }
if(!empty($value) && $models[$index][$key]->save()) {
if($first) {
$parentid = $models[$index][$key]->option_id;
diff --git a/frontend/views/option/_form.php b/frontend/views/option/_form.php
index caacf87..32331a3 100644
--- a/frontend/views/option/_form.php
+++ b/frontend/views/option/_form.php
@@ -16,20 +16,37 @@ use yii\widgets\ActiveForm;
- $field) {
?>
+
-
-
+
+
+
+
getLangs() as $lang) {
+ if($field['translate']) {
+ ?>
+
+
+
-
+
=$modellang[$index][$key][0]->getFirstError('value')?>
getLangs() as $lang) {
- ?>
-
-
+
+
+
+
@@ -83,6 +111,18 @@ use yii\widgets\ActiveForm;
$(clone).appendTo('#=$form->getId()?>');
$('#=$form->getId()?> button[type=submit]').parent().appendTo('#=$form->getId()?>');
});
+ $(document).on('click', '.add_lang', function() {
+ var field_block = $(this).parent().parent();
+ if($(this).hasClass('active')) {
+ $(field_block).find('.main_input').attr('required', '').show();
+ $(field_block).find('.lang_inputs').hide();
+ $(this).removeClass('active');
+ } else {
+ $(field_block).find('.main_input').removeAttr('required').hide();
+ $(field_block).find('.lang_inputs').show();
+ $(this).addClass('active');
+ }
+ });
});
diff --git a/frontend/views/option/_form_edit.php b/frontend/views/option/_form_edit.php
index b6f950f..4a3dd57 100644
--- a/frontend/views/option/_form_edit.php
+++ b/frontend/views/option/_form_edit.php
@@ -20,14 +20,17 @@ use yii\widgets\ActiveForm;
hasErrors()) { ?>getFirstError('value');?>
getLangs() as $lang_id => $lang) {
- ?>
-
- translate) {
+ foreach($row->getLangs() as $lang_id => $lang) {
+ ?>
+
+
--
libgit2 0.21.4