Commit ae7541fb84efaa96b71d196f9eae8259d46a2fcc

Authored by andryeyev
2 parents 1a43a715 fe5be656

Merge branch 'master' into Andryeyev

Showing 170 changed files with 2995 additions and 787 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 170 files are displayed.

backend/controllers/AdminMenuController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\controllers;
  4 +
  5 +use Yii;
  6 +use backend\models\AdminMenu;
  7 +use backend\models\AdminMenuSearch;
  8 +use yii\web\Controller;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * AdminMenuController implements the CRUD actions for AdminMenu model.
  14 + */
  15 +class AdminMenuController extends Controller
  16 +{
  17 + public $layout = 'settings';
  18 +
  19 + public function behaviors()
  20 + {
  21 + return [
  22 + 'verbs' => [
  23 + 'class' => VerbFilter::className(),
  24 + 'actions' => [
  25 + 'delete' => ['post'],
  26 + ],
  27 + ],
  28 + ];
  29 + }
  30 +
  31 + /**
  32 + * Lists all AdminMenu models.
  33 + * @return mixed
  34 + */
  35 + public function actionIndex()
  36 + {
  37 + $searchModel = new AdminMenuSearch();
  38 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  39 +
  40 + return $this->render('index', [
  41 + 'searchModel' => $searchModel,
  42 + 'dataProvider' => $dataProvider,
  43 + ]);
  44 + }
  45 +
  46 + /**
  47 + * Displays a single AdminMenu model.
  48 + * @param integer $id
  49 + * @return mixed
  50 + */
  51 + public function actionView($id)
  52 + {
  53 + return $this->render('view', [
  54 + 'model' => $this->findModel($id),
  55 + ]);
  56 + }
  57 +
  58 + /**
  59 + * Creates a new AdminMenu model.
  60 + * If creation is successful, the browser will be redirected to the 'view' page.
  61 + * @return mixed
  62 + */
  63 + public function actionCreate()
  64 + {
  65 + $model = new AdminMenu();
  66 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  67 + return $this->redirect(['view', 'id' => $model->admin_menu_id]);
  68 + } else {
  69 + return $this->render('create', [
  70 + 'model' => $model,
  71 + ]);
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * Updates an existing AdminMenu model.
  77 + * If update is successful, the browser will be redirected to the 'view' page.
  78 + * @param integer $id
  79 + * @return mixed
  80 + */
  81 + public function actionUpdate($id)
  82 + {
  83 + $model = $this->findModel($id);
  84 +
  85 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  86 + return $this->redirect(['view', 'id' => $model->adminmenu_id]);
  87 + } else {
  88 + return $this->render('update', [
  89 + 'model' => $model,
  90 + ]);
  91 + }
  92 + }
  93 +
  94 + /**
  95 + * Deletes an existing AdminMenu model.
  96 + * If deletion is successful, the browser will be redirected to the 'index' page.
  97 + * @param integer $id
  98 + * @return mixed
  99 + */
  100 + public function actionDelete($id)
  101 + {
  102 + $this->findModel($id)->delete();
  103 +
  104 + return $this->redirect(['index']);
  105 + }
  106 +
  107 + /**
  108 + * Finds the AdminMenu model based on its primary key value.
  109 + * If the model is not found, a 404 HTTP exception will be thrown.
  110 + * @param integer $id
  111 + * @return AdminMenu the loaded model
  112 + * @throws NotFoundHttpException if the model cannot be found
  113 + */
  114 + protected function findModel($id)
  115 + {
  116 + if (($model = AdminMenu::findOne($id)) !== null) {
  117 + return $model;
  118 + } else {
  119 + throw new NotFoundHttpException('The requested page does not exist.');
  120 + }
  121 + }
  122 +
  123 +}
backend/controllers/LanguageController.php
@@ -54,7 +54,7 @@ class LanguageController extends Controller @@ -54,7 +54,7 @@ class LanguageController extends Controller
54 { 54 {
55 if(!empty(Yii::$app->request->get('id'))) { 55 if(!empty(Yii::$app->request->get('id'))) {
56 $model = $this->findModel(Yii::$app->request->get('id')); 56 $model = $this->findModel(Yii::$app->request->get('id'));
57 - $model->active = 1; 57 + $model->status = 1;
58 $model->save(); 58 $model->save();
59 return $this->redirect(['index']); 59 return $this->redirect(['index']);
60 } else { 60 } else {
@@ -77,7 +77,7 @@ class LanguageController extends Controller @@ -77,7 +77,7 @@ class LanguageController extends Controller
77 public function actionDelete($id) 77 public function actionDelete($id)
78 { 78 {
79 $model = $this->findModel($id); 79 $model = $this->findModel($id);
80 - $model->active = 0; 80 + $model->status = 0;
81 $model->save(); 81 $model->save();
82 82
83 return $this->redirect(['index']); 83 return $this->redirect(['index']);
@@ -152,18 +152,18 @@ class LanguageController extends Controller @@ -152,18 +152,18 @@ class LanguageController extends Controller
152 public function actionDeleteAdress($id) 152 public function actionDeleteAdress($id)
153 { 153 {
154 $model = $this->findModelAdress($id); 154 $model = $this->findModelAdress($id);
155 - $children = $model->hasMany(Option::className(), ['parent_id' => 'option_id'])->all(); 155 + $children = $model->hasMany(Option::className(), ['option_pid' => 'option_id'])->all();
156 $langs = array(); 156 $langs = array();
157 if(!empty($children)) { 157 if(!empty($children)) {
158 foreach($children as $child) { 158 foreach($children as $child) {
159 - $langs = OptionLang::findAll(['id' => $child->option_id]); 159 + $langs = OptionLang::findAll(['option_language_id' => $child->option_id]);
160 foreach($langs as $lang) { 160 foreach($langs as $lang) {
161 $lang->delete(); 161 $lang->delete();
162 } 162 }
163 $child->delete(); 163 $child->delete();
164 } 164 }
165 } 165 }
166 - $langs = OptionLang::findAll(['id' => $id]); 166 + $langs = OptionLang::findAll(['option_language_id' => $id]);
167 foreach($langs as $lang) { 167 foreach($langs as $lang) {
168 $lang->delete(); 168 $lang->delete();
169 } 169 }
backend/controllers/MenuController.php
@@ -118,4 +118,5 @@ class MenuController extends Controller @@ -118,4 +118,5 @@ class MenuController extends Controller
118 throw new NotFoundHttpException('The requested page does not exist.'); 118 throw new NotFoundHttpException('The requested page does not exist.');
119 } 119 }
120 } 120 }
  121 +
121 } 122 }
backend/controllers/MenuLocationController.php
@@ -4,7 +4,7 @@ namespace backend\controllers; @@ -4,7 +4,7 @@ namespace backend\controllers;
4 4
5 use Yii; 5 use Yii;
6 use backend\models\MenuLocation; 6 use backend\models\MenuLocation;
7 -use backend\models\MenuSearchLocation; 7 +use backend\models\MenuLocationSearch;
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;
@@ -32,7 +32,7 @@ class MenuLocationController extends Controller @@ -32,7 +32,7 @@ class MenuLocationController extends Controller
32 */ 32 */
33 public function actionIndex() 33 public function actionIndex()
34 { 34 {
35 - $searchModel = new MenuSearchLocation(); 35 + $searchModel = new MenuLocationSearch();
36 $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 36 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
37 37
38 return $this->render('index', [ 38 return $this->render('index', [
backend/controllers/SettingsController.php 0 → 100644
  1 +<?php
  2 +namespace backend\controllers;
  3 +
  4 +use Yii;
  5 +use yii\filters\AccessControl;
  6 +use yii\web\Controller;
  7 +use common\models\LoginForm;
  8 +use yii\filters\VerbFilter;
  9 +use backend\models\Profile;
  10 +use common\models\User;
  11 +use frontend\models\Option;
  12 +use yii\data\ActiveDataProvider;
  13 +use yii\validators\BooleanValidator;
  14 +use yii\validators\StringValidator;
  15 +/**
  16 + * Site controller
  17 + */
  18 +class SettingsController extends Controller
  19 +{
  20 + public $layout = 'settings';
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public function actions()
  25 + {
  26 + return [
  27 + 'error' => [
  28 + 'class' => 'yii\web\ErrorAction',
  29 + ],
  30 + ];
  31 + }
  32 +
  33 + public function actionIndex()
  34 + {
  35 + return $this->render('index');
  36 + }
  37 +
  38 +}
backend/controllers/SiteController.php
@@ -57,7 +57,19 @@ class SiteController extends Controller @@ -57,7 +57,19 @@ class SiteController extends Controller
57 57
58 public function actionIndex() 58 public function actionIndex()
59 { 59 {
60 - return $this->render('index'); 60 +/*
  61 + if (Yii::$app->user->can('site/index'))
  62 + {
  63 +
  64 + }
  65 + else
  66 + {
  67 + Yii::$app->getSession()->setFlash('error', 'Доступ закрыт..');
  68 +
  69 + return $this->redirect('/');
  70 + }
  71 +*/
  72 + return $this->render('index');
61 } 73 }
62 74
63 public function actionLogin() 75 public function actionLogin()
backend/controllers/TerminController.php
@@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException; @@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 10 use yii\filters\VerbFilter;
11 use backend\models\TerminLang; 11 use backend\models\TerminLang;
12 use backend\models\TerminStructure; 12 use backend\models\TerminStructure;
  13 +use yii\filters\AccessControl;
13 14
14 /** 15 /**
15 * TerminController implements the CRUD actions for Termin model. 16 * TerminController implements the CRUD actions for Termin model.
backend/models/AdminMenu.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "admin_menu".
  9 + *
  10 + * @property integer $admin_menu_id
  11 + * @property integer $admin_menu_pid
  12 + * @property integer $status
  13 + * @property integer $hide_min
  14 + * @property integer $sort
  15 + * @property string $name
  16 + * @property string $path
  17 + * @property string $param
  18 + *
  19 + * @property AdminMenu $parent
  20 + * @property AdminMenu[] $adminMenus
  21 + * @property AdminMenuAccessGroup[] $adminMenuAccessGroups
  22 + * @property AdminMenuAccessUser[] $adminMenuAccessUsers
  23 + */
  24 +class AdminMenu extends \yii\db\ActiveRecord
  25 +{
  26 +
  27 + public $parentt;
  28 + /**
  29 + * @inheritdoc
  30 + */
  31 + public static function tableName()
  32 + {
  33 + return 'admin_menu';
  34 + }
  35 +
  36 + /**
  37 + * @inheritdoc
  38 + */
  39 + public function rules()
  40 + {
  41 + return [
  42 + [['admin_menu_pid', 'status', 'hide_min', 'sort'], 'integer'],
  43 + [['name'], 'required'],
  44 + [['name', 'path', 'param','parentt'], 'string']
  45 + ];
  46 + }
  47 +
  48 + /**
  49 + * @inheritdoc
  50 + */
  51 + public function attributeLabels()
  52 + {
  53 + return [
  54 + 'admin_menu_id' => Yii::t('app', 'Admin menu ID'),
  55 + 'admin_menu_pid' => Yii::t('app', 'Admin menu parent ID'),
  56 + 'status' => Yii::t('app', 'Status'),
  57 + 'hide_min' => Yii::t('app', 'Hide Min'),
  58 + 'sort' => Yii::t('app', 'Sort'),
  59 + 'name' => Yii::t('app', 'Name'),
  60 + 'path' => Yii::t('app', 'Path'),
  61 + 'param' => Yii::t('app', 'Params'),
  62 + 'parentt' => Yii::t('app', 'Parent item')
  63 + ];
  64 + }
  65 +
  66 + /**
  67 + * @return \yii\db\ActiveQuery
  68 + */
  69 + public function getParent()
  70 + {
  71 + return $this->hasOne(AdminMenu::className(), ['admin_menu_id' => 'admin_menu_pid']);
  72 + }
  73 +
  74 + /**
  75 + * @return \yii\db\ActiveQuery
  76 + */
  77 + public function getAdminMenus()
  78 + {
  79 + return $this->hasMany(AdminMenu::className(), ['admin_menu_pid' => 'admin_menu_id']);
  80 + }
  81 +
  82 + /**
  83 + * @return \yii\db\ActiveQuery
  84 + */
  85 + public function getAdminMenuAccessGroups()
  86 + {
  87 + return $this->hasMany(AdminMenuAccessGroup::className(), ['admin_menu_id' => 'admin_menu_id']);
  88 + }
  89 +
  90 + /**
  91 + * @return \yii\db\ActiveQuery
  92 + */
  93 + public function getAdminMenuAccessUsers()
  94 + {
  95 + return $this->hasMany(AdminMenuAccessUser::className(), ['admin_menu_id' => 'admin_menu_id']);
  96 + }
  97 +
  98 + public static function buildMenu($withValues = false)
  99 + {
  100 + $result = [];
  101 + $roots = self::find()->where(['admin_menu_pid' => NULL])->with(['adminMenus'])->all();
  102 + foreach($roots as $root) {
  103 + if($root->adminMenus) {
  104 + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->admin_menu_id, 'options' => ['class' => 'header']];
  105 + foreach($root->adminMenus as $submenu) {
  106 + if($submenu->adminMenus) {
  107 + $items = [];
  108 + foreach($submenu->adminMenus as $item) {
  109 + $items[] = ['label' => Yii::t('app', $item->name), 'id' => $item->admin_menu_id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$item->path], \common\models\Tools::parseUrlParams($item->param))];
  110 + }
  111 + $result[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->admin_menu_id, 'icon' => 'fa fa-circle-o', 'url' => '#', 'items' => $items];
  112 + unset($items);
  113 + } else {
  114 + $result[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->admin_menu_id, 'icon' => 'fa fa-circle-o', 'url' => array_merge([$submenu->path], \common\models\Tools::parseUrlParams($submenu->param))];
  115 + }
  116 + }
  117 + }
  118 + }
  119 + return $result;
  120 + }
  121 +
  122 + public static function buildMenuSelect()
  123 + {
  124 + $result = [];
  125 + $roots = self::find()->where(['admin_menu_pid' => NULL])->with(['adminMenus'])->all();
  126 + foreach($roots as $root) {
  127 + if($root->adminMenus) {
  128 + $items = [];
  129 + foreach($root->adminMenus as $submenu) {
  130 + $items[] = ['label' => Yii::t('app', $submenu->name), 'id' => $submenu->admin_menu_id];
  131 + }
  132 + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->admin_menu_id, 'items' => $items];
  133 + unset($items);
  134 + } else {
  135 + $result[] = ['label' => Yii::t('app', $root->name), 'id' => $root->admin_menu_id];
  136 + }
  137 + }
  138 + return $result;
  139 + }
  140 +
  141 + public function beforeSave($insert)
  142 + {
  143 + if (parent::beforeSave($insert)) {
  144 + if(!$this->admin_menu_pid) {
  145 + $this->admin_menu_pid = NULL;
  146 + }
  147 + return true;
  148 + } else {
  149 + return false;
  150 + }
  151 + }
  152 +}
backend/models/AdminMenuAccessGroup.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "admin_menu_access_group".
  9 + *
  10 + * @property integer $admin_menu_access_group_id
  11 + * @property integer $admin_menu_id
  12 + * @property string $group
  13 + *
  14 + * @property AdminMenu $menu
  15 + * @property AuthRule $group0
  16 + */
  17 +class AdminMenuAccessGroup extends \yii\db\ActiveRecord
  18 +{
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public static function tableName()
  23 + {
  24 + return 'admin_menu_access_group';
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + [['admin_menu_id'], 'integer'],
  34 + [['group'], 'string']
  35 + ];
  36 + }
  37 +
  38 + /**
  39 + * @inheritdoc
  40 + */
  41 + public function attributeLabels()
  42 + {
  43 + return [
  44 + 'admin_menu_access_group_id' => Yii::t('app', 'Admin Access Group ID'),
  45 + 'admin_menu_id' => Yii::t('app', 'Admin Menu ID'),
  46 + 'group' => Yii::t('app', 'Group'),
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @return \yii\db\ActiveQuery
  52 + */
  53 + public function getMenu()
  54 + {
  55 + return $this->hasOne(AdminMenu::className(), ['admin_menu_id' => 'admin_menu_id']);
  56 + }
  57 +
  58 + /**
  59 + * @return \yii\db\ActiveQuery
  60 + */
  61 + public function getGroup0()
  62 + {
  63 + return $this->hasOne(AuthRule::className(), ['name' => 'group']);
  64 + }
  65 +}
backend/models/AdminMenuAccessUser.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use common\models\User;
  6 +use Yii;
  7 +
  8 +/**
  9 + * This is the model class for table "admin_menu_access_user".
  10 + *
  11 + * @property integer $admin_menu_id
  12 + * @property integer $user_id
  13 + * @property integer $admin_menu_access_user_id
  14 + *
  15 + * @property AdminMenu $menu
  16 + * @property User $user
  17 + */
  18 +class AdminMenuAccessUser extends \yii\db\ActiveRecord
  19 +{
  20 + /**
  21 + * @inheritdoc
  22 + */
  23 + public static function tableName()
  24 + {
  25 + return 'admin_menu_access_user';
  26 + }
  27 +
  28 + /**
  29 + * @inheritdoc
  30 + */
  31 + public function rules()
  32 + {
  33 + return [
  34 + [['admin_menu_id', 'user_id'], 'integer']
  35 + ];
  36 + }
  37 +
  38 + /**
  39 + * @inheritdoc
  40 + */
  41 + public function attributeLabels()
  42 + {
  43 + return [
  44 + 'admin_menu_id' => Yii::t('app', 'Admin Menu ID'),
  45 + 'user_id' => Yii::t('app', 'User ID'),
  46 + 'admin_menu_access_user_id' => Yii::t('app', 'Admin Menu Access User ID'),
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @return \yii\db\ActiveQuery
  52 + */
  53 + public function getMenu()
  54 + {
  55 + return $this->hasOne(AdminMenu::className(), ['admin_menu_id' => 'admin_menu_id']);
  56 + }
  57 +
  58 + /**
  59 + * @return \yii\db\ActiveQuery
  60 + */
  61 + public function getUser()
  62 + {
  63 + return $this->hasOne(User::className(), ['id' => 'user_id']);
  64 + }
  65 +}
backend/models/AdminMenuSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use backend\models\AdminMenu;
  9 +
  10 +/**
  11 + * AdminMenuSearch represents the model behind the search form about `backend\models\AdminMenu`.
  12 + */
  13 +class AdminMenuSearch extends AdminMenu
  14 +{
  15 +
  16 +
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function rules()
  21 + {
  22 + return [
  23 + [['admin_menu_id', 'admin_menu_pid', 'status', 'hide_min', 'sort'], 'integer'],
  24 + [['name', 'path', 'param','parentt'], 'safe'],
  25 + ];
  26 + }
  27 +
  28 + /**
  29 + * @inheritdoc
  30 + */
  31 + public function scenarios()
  32 + {
  33 + // bypass scenarios() implementation in the parent class
  34 + return Model::scenarios();
  35 + }
  36 +
  37 + /**
  38 + * Creates data provider instance with search query applied
  39 + *
  40 + * @param array $params
  41 + *
  42 + * @return ActiveDataProvider
  43 + */
  44 + public function search($params)
  45 + {
  46 + $query = AdminMenu::find();
  47 +
  48 + $dataProvider = new ActiveDataProvider([
  49 + 'query' => $query,
  50 + 'pagination' => [
  51 + 'pageSize' => 5
  52 + ],
  53 + 'sort' => [
  54 + 'attributes' => [
  55 + 'admin_menu_id',
  56 + 'name',
  57 + 'path',
  58 + 'param',
  59 + 'status',
  60 + 'hide_min',
  61 + 'parentt' => [
  62 + 'asc' => ['name' => SORT_ASC],
  63 + 'desc' => ['name' => SORT_DESC],
  64 + 'default' => SORT_DESC
  65 + ]
  66 + ]
  67 + ]
  68 + ]);
  69 +
  70 + $this->load($params);
  71 +
  72 + if (!$this->validate()) {
  73 + // uncomment the following line if you do not want to return any records when validation fails
  74 + // $query->where('0=1');
  75 + return $dataProvider;
  76 + }
  77 +
  78 + $query->andFilterWhere([
  79 + 'admin_menu_id' => $this->admin_menu_id,
  80 + 'admin_menu_pid' => $this->admin_menu_pid,
  81 + 'status' => $this->status,
  82 + 'hide_min' => $this->hide_min,
  83 + 'sort' => $this->sort
  84 + ]);
  85 +
  86 +
  87 + $query->andFilterWhere(['like', 'name', $this->name])
  88 + ->andFilterWhere(['like', 'path', $this->path])
  89 + ->andFilterWhere(['like', 'param', $this->param])
  90 + ->andFilterWhere(['in', 'admin_menu_pid', $this->find()->select(['admin_menu_id'])->andFilterWhere(['like', 'name', $this->parentt])->column()]);
  91 +
  92 + return $dataProvider;
  93 + }
  94 +}
backend/models/Import.php
@@ -42,7 +42,7 @@ class Import extends \yii\db\ActiveRecord @@ -42,7 +42,7 @@ class Import extends \yii\db\ActiveRecord
42 $termin_pid = 8; 42 $termin_pid = 8;
43 // $template_id шаблон каьегорий 43 // $template_id шаблон каьегорий
44 $template_id = 3; 44 $template_id = 3;
45 - $lang_id = 2; 45 + $language_id = 2;
46 $type = 'H'; 46 $type = 'H';
47 47
48 // массив для импортп товаров 48 // массив для импортп товаров
@@ -69,7 +69,7 @@ class Import extends \yii\db\ActiveRecord @@ -69,7 +69,7 @@ class Import extends \yii\db\ActiveRecord
69 // массив для поиска/добавления термина 69 // массив для поиска/добавления термина
70 $basic = [ 70 $basic = [
71 'type' => $type, 71 'type' => $type,
72 - 'lang_id' => $lang_id, 72 + 'language_id' => $language_id,
73 'template_id' => $template_id, 73 'template_id' => $template_id,
74 ]; 74 ];
75 75
backend/models/LanguageSearch.php
@@ -19,8 +19,8 @@ class LanguageSearch extends Language @@ -19,8 +19,8 @@ class LanguageSearch extends Language
19 { 19 {
20 return [ 20 return [
21 [['language_id'], 'integer'], 21 [['language_id'], 'integer'],
22 - [['lang_code', 'language_name'], 'safe'],  
23 - [['is_default', 'active'], 'boolean'], 22 + [['language_code', 'language_name'], 'safe'],
  23 + [['is_default', 'status'], 'boolean'],
24 ]; 24 ];
25 } 25 }
26 26
@@ -59,12 +59,12 @@ class LanguageSearch extends Language @@ -59,12 +59,12 @@ class LanguageSearch extends Language
59 $query->andFilterWhere([ 59 $query->andFilterWhere([
60 'language_id' => $this->language_id, 60 'language_id' => $this->language_id,
61 'is_default' => $this->is_default, 61 'is_default' => $this->is_default,
62 - 'active' => $this->active, 62 + 'status' => $this->status,
63 ]); 63 ]);
64 64
65 - $query->andFilterWhere(['like', 'lang_code', $this->lang_code]) 65 + $query->andFilterWhere(['like', 'language_code', $this->language_code])
66 ->andFilterWhere(['like', 'language_name', $this->language_name]) 66 ->andFilterWhere(['like', 'language_name', $this->language_name])
67 - ->andWhere(['active' => '1']) 67 + ->andWhere(['status' => '1'])
68 ->andWhere(['>', 'language_id', '0']); 68 ->andWhere(['>', 'language_id', '0']);
69 69
70 return $dataProvider; 70 return $dataProvider;
@@ -89,12 +89,12 @@ class LanguageSearch extends Language @@ -89,12 +89,12 @@ class LanguageSearch extends Language
89 $query->andFilterWhere([ 89 $query->andFilterWhere([
90 'language_id' => $this->language_id, 90 'language_id' => $this->language_id,
91 'is_default' => $this->is_default, 91 'is_default' => $this->is_default,
92 - 'active' => $this->active, 92 + 'status' => $this->status,
93 ]); 93 ]);
94 94
95 - $query->andFilterWhere(['like', 'lang_code', $this->lang_code]) 95 + $query->andFilterWhere(['like', 'language_code', $this->language_code])
96 ->andFilterWhere(['like', 'language_name', $this->language_name]) 96 ->andFilterWhere(['like', 'language_name', $this->language_name])
97 - ->andWhere(['active' => '0']); 97 + ->andWhere(['status' => '0']);
98 98
99 return $dataProvider; 99 return $dataProvider;
100 } 100 }
backend/models/Menu.php
@@ -80,7 +80,7 @@ class Menu extends \yii\db\ActiveRecord @@ -80,7 +80,7 @@ class Menu extends \yii\db\ActiveRecord
80 AND menu_location.menu_location_name = \''.$location_name.'\' 80 AND menu_location.menu_location_name = \''.$location_name.'\'
81 INNER JOIN termin ON termin.termin_id = menu.termin_id 81 INNER JOIN termin ON termin.termin_id = menu.termin_id
82 INNER JOIN termin_lang ON termin_lang.termin_id = menu.termin_id 82 INNER JOIN termin_lang ON termin_lang.termin_id = menu.termin_id
83 - AND termin_lang.lang_id = '.Yii::$app->params['lang_id'].' 83 + AND termin_lang.language_id = '.Yii::$app->params['language_id'].'
84 ORDER BY menu.level ASC, menu.sortorder ASC 84 ORDER BY menu.level ASC, menu.sortorder ASC
85 ')->queryAll(); 85 ')->queryAll();
86 /* 86 /*
@@ -90,8 +90,13 @@ class Menu extends \yii\db\ActiveRecord @@ -90,8 +90,13 @@ class Menu extends \yii\db\ActiveRecord
90 ->join( 90 ->join(
91 'INNER JOIN', 91 'INNER JOIN',
92 'termin_lang.termin_id = menu.termin_id', 92 'termin_lang.termin_id = menu.termin_id',
93 - ['lang_id' => yii::$app->params['lang_id']]) 93 + ['language_id' => yii::$app->params['language_id']])
94 ->all(); 94 ->all();
95 */ 95 */
96 } 96 }
  97 +
  98 + public function getTerminLang()
  99 + {
  100 + return $this->hasOne(TerminLang::className(), ['termin_id' => 'termin_id']);
  101 + }
97 } 102 }
backend/models/MenuLocation.php
@@ -59,6 +59,6 @@ class MenuLocation extends \yii\db\ActiveRecord @@ -59,6 +59,6 @@ class MenuLocation extends \yii\db\ActiveRecord
59 */ 59 */
60 public function getLangs() 60 public function getLangs()
61 { 61 {
62 - return $this->hasMany(Language::className(), ['language_id' => 'lang_id'])->viaTable('menu_location_lang', ['menu_location_id' => 'menu_location_id']); 62 + return $this->hasMany(Language::className(), ['language_id' => 'language_id'])->viaTable('menu_location_lang', ['menu_location_id' => 'menu_location_id']);
63 } 63 }
64 } 64 }
backend/models/MenuLocationLang.php
@@ -9,7 +9,7 @@ use Yii; @@ -9,7 +9,7 @@ use Yii;
9 * 9 *
10 * @property integer $menu_location_id 10 * @property integer $menu_location_id
11 * @property string $menu_location_title 11 * @property string $menu_location_title
12 - * @property integer $lang_id 12 + * @property integer $language_id
13 * 13 *
14 * @property Language $lang 14 * @property Language $lang
15 * @property MenuLocation $menuLocation 15 * @property MenuLocation $menuLocation
@@ -30,8 +30,8 @@ class MenuLocationLang extends \yii\db\ActiveRecord @@ -30,8 +30,8 @@ class MenuLocationLang extends \yii\db\ActiveRecord
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - [['menu_location_id', 'menu_location_title', 'lang_id'], 'required'],  
34 - [['menu_location_id', 'lang_id'], 'integer'], 33 + [['menu_location_id', 'menu_location_title', 'language_id'], 'required'],
  34 + [['menu_location_id', 'language_id'], 'integer'],
35 [['menu_location_title'], 'string', 'max' => 250] 35 [['menu_location_title'], 'string', 'max' => 250]
36 ]; 36 ];
37 } 37 }
@@ -44,7 +44,7 @@ class MenuLocationLang extends \yii\db\ActiveRecord @@ -44,7 +44,7 @@ class MenuLocationLang extends \yii\db\ActiveRecord
44 return [ 44 return [
45 'menu_location_id' => Yii::t('app', 'Menu Location ID'), 45 'menu_location_id' => Yii::t('app', 'Menu Location ID'),
46 'menu_location_title' => Yii::t('app', 'Menu Location Title'), 46 'menu_location_title' => Yii::t('app', 'Menu Location Title'),
47 - 'lang_id' => Yii::t('app', 'Lang ID'), 47 + 'language_id' => Yii::t('app', 'Lang ID'),
48 ]; 48 ];
49 } 49 }
50 50
@@ -53,7 +53,7 @@ class MenuLocationLang extends \yii\db\ActiveRecord @@ -53,7 +53,7 @@ class MenuLocationLang extends \yii\db\ActiveRecord
53 */ 53 */
54 public function getLang() 54 public function getLang()
55 { 55 {
56 - return $this->hasOne(Language::className(), ['language_id' => 'lang_id']); 56 + return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
57 } 57 }
58 58
59 /** 59 /**
backend/models/MenuSearch.php
@@ -49,7 +49,8 @@ class MenuSearch extends Menu @@ -49,7 +49,8 @@ class MenuSearch extends Menu
49 49
50 $this->load($params); 50 $this->load($params);
51 51
52 - if (!$this->validate()) { 52 + if (! $this->validate())
  53 + {
53 // uncomment the following line if you do not want to return any records when validation fails 54 // uncomment the following line if you do not want to return any records when validation fails
54 // $query->where('0=1'); 55 // $query->where('0=1');
55 return $dataProvider; 56 return $dataProvider;
@@ -67,7 +68,7 @@ class MenuSearch extends Menu @@ -67,7 +68,7 @@ class MenuSearch extends Menu
67 ]); 68 ]);
68 69
69 $query->andFilterWhere(['like', 'name', $this->name]) 70 $query->andFilterWhere(['like', 'name', $this->name])
70 - ->andFilterWhere(['like', 'url', $this->url]); 71 + ->andFilterWhere(['like', 'url', $this->url]);
71 72
72 return $dataProvider; 73 return $dataProvider;
73 } 74 }
backend/models/NewOptionsLang.php
@@ -9,7 +9,7 @@ use Yii; @@ -9,7 +9,7 @@ use Yii;
9 * 9 *
10 * @property integer $primary 10 * @property integer $primary
11 * @property integer $id 11 * @property integer $id
12 - * @property integer $lang_id 12 + * @property integer $language_id
13 * @property string $value 13 * @property string $value
14 */ 14 */
15 class NewOptionsLang extends \yii\db\ActiveRecord 15 class NewOptionsLang extends \yii\db\ActiveRecord
@@ -32,7 +32,7 @@ class NewOptionsLang extends \yii\db\ActiveRecord @@ -32,7 +32,7 @@ class NewOptionsLang extends \yii\db\ActiveRecord
32 { 32 {
33 return [ 33 return [
34 [['id', 'value'], 'required'], 34 [['id', 'value'], 'required'],
35 - [['id', 'lang_id'], 'integer'], 35 + [['id', 'language_id'], 'integer'],
36 [['value'], 'string'] 36 [['value'], 'string']
37 ]; 37 ];
38 } 38 }
@@ -45,7 +45,7 @@ class NewOptionsLang extends \yii\db\ActiveRecord @@ -45,7 +45,7 @@ class NewOptionsLang extends \yii\db\ActiveRecord
45 return [ 45 return [
46 'primary' => Yii::t('app', 'Primary'), 46 'primary' => Yii::t('app', 'Primary'),
47 'id' => Yii::t('app', 'ID'), 47 'id' => Yii::t('app', 'ID'),
48 - 'lang_id' => Yii::t('app', 'Lang ID'), 48 + 'language_id' => Yii::t('app', 'Lang ID'),
49 'value' => Yii::t('app', 'Value'), 49 'value' => Yii::t('app', 'Value'),
50 ]; 50 ];
51 } 51 }
backend/models/NewOptionsLangSearch.php
@@ -18,7 +18,7 @@ class NewOptionsLangSearch extends NewOptionsLang @@ -18,7 +18,7 @@ class NewOptionsLangSearch extends NewOptionsLang
18 public function rules() 18 public function rules()
19 { 19 {
20 return [ 20 return [
21 - [['primary', 'id', 'lang_id'], 'integer'], 21 + [['primary', 'id', 'language_id'], 'integer'],
22 [['value'], 'safe'], 22 [['value'], 'safe'],
23 ]; 23 ];
24 } 24 }
@@ -58,7 +58,7 @@ class NewOptionsLangSearch extends NewOptionsLang @@ -58,7 +58,7 @@ class NewOptionsLangSearch extends NewOptionsLang
58 $query->andFilterWhere([ 58 $query->andFilterWhere([
59 'primary' => $this->primary, 59 'primary' => $this->primary,
60 'id' => $this->id, 60 'id' => $this->id,
61 - 'lang_id' => $this->lang_id, 61 + 'language_id' => $this->language_id,
62 ]); 62 ]);
63 63
64 $query->andFilterWhere(['like', 'value', $this->value]); 64 $query->andFilterWhere(['like', 'value', $this->value]);
backend/models/Termin.php
@@ -57,7 +57,7 @@ class Termin extends \yii\db\ActiveRecord @@ -57,7 +57,7 @@ class Termin extends \yii\db\ActiveRecord
57 57
58 /** 58 /**
59 * Выполняет поиск по параметрам 59 * Выполняет поиск по параметрам
60 - * @param array $param принимает [termin_id, lang_id, return_one, return_field, show_all] 60 + * @param array $param принимает [termin_id, language_id, return_one, return_field, show_all]
61 * @return array one | array all | string значение масива 61 * @return array one | array all | string значение масива
62 */ 62 */
63 public function finInfo (array $params = []) 63 public function finInfo (array $params = [])
@@ -65,7 +65,7 @@ class Termin extends \yii\db\ActiveRecord @@ -65,7 +65,7 @@ class Termin extends \yii\db\ActiveRecord
65 Tools::ifNotExist ($params, array ( 65 Tools::ifNotExist ($params, array (
66 'termin_id' => false, 66 'termin_id' => false,
67 'termin_pid' => false, 67 'termin_pid' => false,
68 - 'lang_id' => Yii::$app->params['lang_id'], 68 + 'language_id' => Yii::$app->params['language_id'],
69 'return_one' => false, 69 'return_one' => false,
70 'return_field' => false, 70 'return_field' => false,
71 'show_all' => false, 71 'show_all' => false,
@@ -92,9 +92,9 @@ class Termin extends \yii\db\ActiveRecord @@ -92,9 +92,9 @@ class Termin extends \yii\db\ActiveRecord
92 'termin.termin_id = termin_lang.termin_id' 92 'termin.termin_id = termin_lang.termin_id'
93 ); 93 );
94 94
95 - if ($params['lang_id']) 95 + if ($params['language_id'])
96 { 96 {
97 - $WHERE['termin_lang.lang_id'] = $params['lang_id']; 97 + $WHERE['termin_lang.language_id'] = $params['language_id'];
98 } 98 }
99 99
100 // структура 100 // структура
@@ -169,7 +169,7 @@ class Termin extends \yii\db\ActiveRecord @@ -169,7 +169,7 @@ class Termin extends \yii\db\ActiveRecord
169 */ 169 */
170 public function getLangs() 170 public function getLangs()
171 { 171 {
172 - return $this->hasMany(Language::className(), ['language_id' => 'lang_id']) 172 + return $this->hasMany(Language::className(), ['language_id' => 'language_id'])
173 ->viaTable('termin_lang', ['termin_id' => 'termin_id']); 173 ->viaTable('termin_lang', ['termin_id' => 'termin_id']);
174 } 174 }
175 175
backend/models/TerminLang.php
@@ -8,7 +8,7 @@ use Yii; @@ -8,7 +8,7 @@ use Yii;
8 * This is the model class for table "termin_lang". 8 * This is the model class for table "termin_lang".
9 * 9 *
10 * @property integer $termin_id 10 * @property integer $termin_id
11 - * @property integer $lang_id 11 + * @property integer $language_id
12 * @property string $termin_title 12 * @property string $termin_title
13 * @property string $termin_alias 13 * @property string $termin_alias
14 * 14 *
@@ -31,8 +31,8 @@ class TerminLang extends \yii\db\ActiveRecord @@ -31,8 +31,8 @@ class TerminLang extends \yii\db\ActiveRecord
31 public function rules() 31 public function rules()
32 { 32 {
33 return [ 33 return [
34 - [['lang_id'], 'required'],  
35 - [['lang_id'], 'integer'], 34 + [['language_id'], 'required'],
  35 + [['language_id'], 'integer'],
36 [['termin_title', 'termin_alias'], 'string', 'max' => 250] 36 [['termin_title', 'termin_alias'], 'string', 'max' => 250]
37 ]; 37 ];
38 } 38 }
@@ -44,7 +44,7 @@ class TerminLang extends \yii\db\ActiveRecord @@ -44,7 +44,7 @@ class TerminLang extends \yii\db\ActiveRecord
44 { 44 {
45 return [ 45 return [
46 'termin_id' => Yii::t('app', 'Termin ID'), 46 'termin_id' => Yii::t('app', 'Termin ID'),
47 - 'lang_id' => Yii::t('app', 'Lang ID'), 47 + 'language_id' => Yii::t('app', 'Lang ID'),
48 'termin_title' => Yii::t('app', 'Termin Title'), 48 'termin_title' => Yii::t('app', 'Termin Title'),
49 'termin_alias' => Yii::t('app', 'Termin Alias'), 49 'termin_alias' => Yii::t('app', 'Termin Alias'),
50 ]; 50 ];
@@ -55,7 +55,7 @@ class TerminLang extends \yii\db\ActiveRecord @@ -55,7 +55,7 @@ class TerminLang extends \yii\db\ActiveRecord
55 */ 55 */
56 public function getLang() 56 public function getLang()
57 { 57 {
58 - return $this->hasOne(Language::className(), ['language_id' => 'lang_id']); 58 + return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
59 } 59 }
60 60
61 /** 61 /**
backend/models/TerminSearch.php
@@ -19,7 +19,7 @@ class TerminSearch extends Termin @@ -19,7 +19,7 @@ class TerminSearch extends Termin
19 { 19 {
20 return [ 20 return [
21 [['termin_id', 'is_book'], 'integer'], 21 [['termin_id', 'is_book'], 'integer'],
22 - [['termin_name'], 'safe'], 22 + [['termin_name', 'termin_title', 'termin_parent_title'], 'safe'],
23 ]; 23 ];
24 } 24 }
25 25
@@ -42,6 +42,7 @@ class TerminSearch extends Termin @@ -42,6 +42,7 @@ class TerminSearch extends Termin
42 public function search($params) 42 public function search($params)
43 { 43 {
44 $query = Termin::find(); 44 $query = Termin::find();
  45 + $query->select('*');
45 46
46 $dataProvider = new ActiveDataProvider([ 47 $dataProvider = new ActiveDataProvider([
47 'query' => $query, 48 'query' => $query,
@@ -53,7 +54,9 @@ class TerminSearch extends Termin @@ -53,7 +54,9 @@ class TerminSearch extends Termin
53 // uncomment the following line if you do not want to return any records when validation fails 54 // uncomment the following line if you do not want to return any records when validation fails
54 // $query->where('0=1'); 55 // $query->where('0=1');
55 return $dataProvider; 56 return $dataProvider;
56 - } 57 + }
  58 +
  59 + $query->joinWith(['terminLangs', 'terminStructures']);
57 60
58 $query->andFilterWhere([ 61 $query->andFilterWhere([
59 'termin_id' => $this->termin_id, 62 'termin_id' => $this->termin_id,
@@ -61,6 +64,8 @@ class TerminSearch extends Termin @@ -61,6 +64,8 @@ class TerminSearch extends Termin
61 ]); 64 ]);
62 65
63 $query->andFilterWhere(['like', 'termin_name', $this->termin_name]); 66 $query->andFilterWhere(['like', 'termin_name', $this->termin_name]);
  67 + $query->andFilterWhere(['like', TerminLang::tableName().'.termin_title', $this->termin_title]);
  68 + //$query->andFilterWhere(['like', 'termin_title', $this->termin_title]);
64 69
65 return $dataProvider; 70 return $dataProvider;
66 } 71 }
backend/models/TerminStructure.php
@@ -51,7 +51,7 @@ class TerminStructure extends \yii\db\ActiveRecord @@ -51,7 +51,7 @@ class TerminStructure extends \yii\db\ActiveRecord
51 { 51 {
52 return $this->hasOne(Termin::className(), ['termin_id' => 'termin_id']); 52 return $this->hasOne(Termin::className(), ['termin_id' => 'termin_id']);
53 } 53 }
54 - 54 +
55 /** 55 /**
56 * @return \yii\db\ActiveQuery 56 * @return \yii\db\ActiveQuery
57 */ 57 */
backend/views/admin-menu/_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use backend\models\AdminMenu;
  4 +use common\models\Tools;
  5 +use yii\helpers\Html;
  6 +use yii\widgets\ActiveForm;
  7 +
  8 +/* @var $this yii\web\View */
  9 +/* @var $model backend\models\AdminMenu */
  10 +/* @var $form yii\widgets\ActiveForm */
  11 +?>
  12 +
  13 +<div class="admin-menu-form">
  14 +
  15 + <?php $form = ActiveForm::begin(); ?>
  16 +
  17 + <?= $form->field($model, 'name')->textInput() ?>
  18 +
  19 + <?= $form->field($model, 'status')->checkbox() ?>
  20 +
  21 + <?= $form->field($model, 'hide_min')->checkbox() ?>
  22 +
  23 + <?= $form->field($model, 'path')->textInput() ?>
  24 +
  25 + <?= $form->field($model, 'param')->textInput() ?>
  26 +
  27 + <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  28 + <div class="panel panel-default">
  29 + <div class="panel-heading" role="tab" id="headingOne">
  30 + <h4 class="panel-title">
  31 + <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
  32 + <?= Yii::t('app', 'Parent menu item') ?>
  33 + </a>
  34 + </h4>
  35 + </div>
  36 + <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
  37 + <ul class="list-group checkboxer">
  38 + <?php
  39 + $roots = AdminMenu::buildMenuSelect();
  40 + echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level0 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => 0, 'uncheck' => null, 'label' => Yii::t('app', 'root'), 'labelOptions' => ['class' => 'checkboxer_label']]);
  41 + foreach($roots as $root) {
  42 + echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level1 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => $root['id'], 'uncheck' => null, 'label' => Yii::t('app', $root['label']), 'labelOptions' => ['class' => 'checkboxer_label']]);
  43 + if($root['items']) {
  44 + foreach($root['items'] as $submenu) {
  45 + echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level2 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => $submenu['id'], 'uncheck' => null, 'label' => Yii::t('app', $submenu['label']), 'labelOptions' => ['class' => 'checkboxer_label']]);
  46 + }
  47 + }
  48 + }
  49 + ?>
  50 + </ul>
  51 + </div>
  52 + </div>
  53 + </div>
  54 +
  55 + <div class="form-group">
  56 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => ($model->isNewRecord ? 'btn btn-success' : 'btn btn-primary') . ' btn-flat']) ?>
  57 + </div>
  58 +
  59 + <?php ActiveForm::end(); ?>
  60 +
  61 +</div>
backend/views/admin-menu/_search.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\AdminMenuSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="admin-menu-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'id') ?>
  19 +
  20 + <?= $form->field($model, 'parent_id') ?>
  21 +
  22 + <?= $form->field($model, 'active') ?>
  23 +
  24 + <?= $form->field($model, 'hide_min') ?>
  25 +
  26 + <?= $form->field($model, 'sort') ?>
  27 +
  28 + <?php // echo $form->field($model, 'name') ?>
  29 +
  30 + <?php // echo $form->field($model, 'path') ?>
  31 +
  32 + <?php // echo $form->field($model, 'params') ?>
  33 +
  34 + <div class="form-group">
  35 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  36 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
  37 + </div>
  38 +
  39 + <?php ActiveForm::end(); ?>
  40 +
  41 +</div>
backend/views/admin-menu/create.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\AdminMenu */
  8 +
  9 +$this->title = Yii::t('app', 'Create Admin Menu');
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Admin Menus'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="admin-menu-create">
  14 + <div class="box box-primary">
  15 + <div class="box-body">
  16 + <?= $this->render('_form', [
  17 + 'model' => $model,
  18 + ]) ?>
  19 + </div>
  20 + </div>
  21 +
  22 +</div>
backend/views/admin-menu/index.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel backend\models\AdminMenuSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = Yii::t('app', 'Admin Menus');
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="admin-menu-index box box-primary">
  14 +
  15 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  16 +
  17 + <?= GridView::widget([
  18 + 'dataProvider' => $dataProvider,
  19 + 'filterModel' => $searchModel,
  20 + 'showFooter' => true,
  21 + 'layout' => "<div class='box-header with-border admin_grid_action'>
  22 + <div class='action_link'>"
  23 + .Html::a(Yii::t('app', 'Create Admin Menu'), ['create'], ['class' => 'btn btn-success btn-flat']).
  24 + "</div>
  25 + <div class='pull-right'>
  26 + {pager}
  27 + </div>
  28 + </div>
  29 + <div class='box-body no-padding table-responsive'>
  30 + {items}
  31 + </div>
  32 + <div class='box-footer admin_grid_action'>
  33 + <div class='action_link'>"
  34 + .Html::a(Yii::t('app', 'Create Admin Menu'), ['create'], ['class' => 'btn btn-success btn-flat']).
  35 + "</div>
  36 + <div class='pull-right'>
  37 + {pager}
  38 + </div>
  39 + </div>",
  40 + 'columns' => [
  41 + ['class' => 'yii\grid\ActionColumn'],
  42 + 'admin_menu_id',
  43 + 'name',
  44 + 'path',
  45 + 'param',
  46 + [
  47 + 'format' => 'raw',
  48 + 'filter' => [
  49 + '1'=>'Отображаются',
  50 + '0'=>'Скрытые',
  51 + ],
  52 + 'value' => function($data){
  53 + if($data->status){
  54 + $status_img = '<i style="color: #008000" class="glyphicon glyphicon-ok"></i>';
  55 + } else {
  56 + $status_img = '<i style="color: red" class="glyphicon glyphicon-remove"></i>';
  57 + }
  58 + return $status_img;
  59 + },
  60 + 'attribute'=>'status',
  61 + ],
  62 + [
  63 + 'attribute' => 'parentt',
  64 + 'content' =>
  65 + function($model, $key, $index, $column) {
  66 + if($model->parent->admin_menu_id) {
  67 + return $model->parent->name;
  68 + } else {
  69 + return '<i class="small">'.Yii::t('app', 'Корневой элемент').'</i>';
  70 + }
  71 + }
  72 + ],
  73 + [
  74 + 'format' => 'raw',
  75 + 'filter' => [
  76 + '1'=>'Отображаются',
  77 + '0'=>'Скрытые',
  78 + ],
  79 + 'value' => function($data){
  80 + if($data->hide_min){
  81 + $status_img = '<i style="color: #008000" class="glyphicon glyphicon-ok"></i>';
  82 + } else {
  83 + $status_img = '<i style="color: red" class="glyphicon glyphicon-remove"></i>';
  84 + }
  85 + return $status_img;
  86 + },
  87 + 'attribute'=>'hide_min',
  88 + ],
  89 + ],
  90 + ]); ?>
  91 +
  92 +</div>
backend/views/admin-menu/update.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model backend\models\AdminMenu */
  7 +
  8 +$this->title = Yii::t('app', 'Update') . ': ' . $model->name;
  9 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Admin Menus'), 'url' => ['index']];
  10 +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->admin_menu_id]];
  11 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
  12 +?>
  13 +<div class="admin-menu-update">
  14 +
  15 + <?= $this->render('_form', [
  16 + 'model' => $model,
  17 + ]) ?>
  18 +
  19 +</div>
backend/views/admin-menu/view.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model backend\models\AdminMenu */
  8 +
  9 +$this->title = Yii::t('app', 'Admin Menus').': '.$model->name;
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Admin Menus'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +
  14 +<div class="admin-menu-view box box-primary">
  15 +<?= DetailView::widget([
  16 + 'model' => $model,
  17 + 'attributes' => [
  18 + 'admin_menu_id',
  19 + 'admin_menu_pid',
  20 + 'status',
  21 + 'hide_min',
  22 + 'sort',
  23 + 'name',
  24 + 'path',
  25 + 'param',
  26 + ],
  27 + ]) ?>
  28 +
  29 + <div class="box-footer with-border">
  30 + <p>
  31 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->admin_menu_id], ['class' => 'btn btn-primary btn-flat']) ?>
  32 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->admin_menu_id], [
  33 + 'class' => 'btn btn-danger btn-flat',
  34 + 'data' => [
  35 + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
  36 + 'method' => 'post',
  37 + ],
  38 + ]) ?>
  39 + <?= Html::a(Yii::t('app', 'Back'), ['index'], ['class' => 'btn btn-default btn-flat']) ?>
  40 + </p>
  41 + </div>
  42 +
  43 +</div>
0 \ No newline at end of file 44 \ No newline at end of file
backend/views/blog/articles.php
@@ -21,7 +21,7 @@ echo GridView::widget([ @@ -21,7 +21,7 @@ echo GridView::widget([
21 'class' => Column::className(), 21 'class' => Column::className(),
22 'header' => Yii::t('app', 'Name'), 22 'header' => Yii::t('app', 'Name'),
23 'content' => function($model, $key, $index, $column) { 23 'content' => function($model, $key, $index, $column) {
24 - return $model->getArticleLangs()->where(['lang_id' => Language::getDefaultLang()->language_id])->one()->name; 24 + return $model->getArticleLangs()->where(['language_id' => Language::getDefaultLang()->language_id])->one()->name;
25 } 25 }
26 ], 26 ],
27 [ 27 [
backend/views/language/_form_adress_edit.php
@@ -21,7 +21,7 @@ use yii\widgets\ActiveForm; @@ -21,7 +21,7 @@ use yii\widgets\ActiveForm;
21 <?php if($row->hasErrors()) { ?><div class="help-block"><?php echo $modellang[$id][0]->getFirstError('value');?></div> <?php } ?> 21 <?php if($row->hasErrors()) { ?><div class="help-block"><?php echo $modellang[$id][0]->getFirstError('value');?></div> <?php } ?>
22 <?php 22 <?php
23 if($row->translate) { 23 if($row->translate) {
24 - foreach($row->getLangs() as $lang_id => $lang) { 24 + foreach($row->getLangs() as $language_id => $lang) {
25 ?> 25 ?>
26 <div class="form-group"> 26 <div class="form-group">
27 <div class="col-xs-1"><?=$lang['lang_code']?></div> 27 <div class="col-xs-1"><?=$lang['lang_code']?></div>
backend/views/language/index.php
@@ -28,7 +28,7 @@ echo $this-&gt;render(&#39;layout&#39;); @@ -28,7 +28,7 @@ echo $this-&gt;render(&#39;layout&#39;);
28 } 28 }
29 ], 29 ],
30 'language_name', 30 'language_name',
31 - 'lang_code', 31 + 'language_code',
32 'is_default:boolean', 32 'is_default:boolean',
33 [ 33 [
34 'class' => 'yii\grid\ActionColumn', 34 'class' => 'yii\grid\ActionColumn',
backend/views/language/view_adress.php
@@ -24,7 +24,7 @@ echo $this-&gt;render(&#39;layout&#39;); @@ -24,7 +24,7 @@ echo $this-&gt;render(&#39;layout&#39;);
24 [ 24 [
25 'class' => 'yii\grid\Column', 25 'class' => 'yii\grid\Column',
26 'content' => function($model, $key, $index, $column) { 26 'content' => function($model, $key, $index, $column) {
27 - return OptionLang::find()->select('value')->where(['lang_id' => 0, 'id' => $model->option_id])->scalar(); 27 + return OptionLang::find()->select('value')->where(['language_id' => 0, 'id' => $model->option_id])->scalar();
28 }, 28 },
29 'header' => Yii::t('app', 'adress_name') 29 'header' => Yii::t('app', 'adress_name')
30 ], 30 ],
backend/views/layouts/header.php
@@ -23,6 +23,19 @@ $username = Yii::$app-&gt;user-&gt;identity-&gt;firstname.&#39; &#39;.Yii::$app-&gt;user-&gt;identity-&gt; @@ -23,6 +23,19 @@ $username = Yii::$app-&gt;user-&gt;identity-&gt;firstname.&#39; &#39;.Yii::$app-&gt;user-&gt;identity-&gt;
23 23
24 <ul class="nav navbar-nav"> 24 <ul class="nav navbar-nav">
25 25
  26 + <!-- search form -->
  27 + <li class="header-search">
  28 + <form action="#" method="get" class="sidebar-form">
  29 + <div class="input-group">
  30 + <input type="text" name="q" class="form-control" placeholder="Search..."/>
  31 + <span class="input-group-btn">
  32 + <button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i>
  33 + </button>
  34 + </span>
  35 + </div>
  36 + </form>
  37 + </li>
  38 + <!-- /.search form -->
26 <!-- Messages: style can be found in dropdown.less--> 39 <!-- Messages: style can be found in dropdown.less-->
27 <li class="dropdown messages-menu"> 40 <li class="dropdown messages-menu">
28 <a href="#" class="dropdown-toggle" data-toggle="dropdown"> 41 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
backend/views/layouts/left.php
@@ -14,79 +14,15 @@ @@ -14,79 +14,15 @@
14 </div> 14 </div>
15 </div> 15 </div>
16 16
17 - <!-- search form -->  
18 - <form action="#" method="get" class="sidebar-form">  
19 - <div class="input-group">  
20 - <input type="text" name="q" class="form-control" placeholder="Search..."/>  
21 - <span class="input-group-btn">  
22 - <button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i>  
23 - </button>  
24 - </span>  
25 - </div>  
26 - </form>  
27 - <!-- /.search form -->  
28 -  
29 - <?= dmstr\widgets\Menu::widget(  
30 - [  
31 - 'options' => ['class' => 'sidebar-menu'],  
32 - 'items' => [  
33 - ['label' => 'Термины', 'icon' => 'fa fa-file-code-o', 'url' => ['/termin/']],  
34 - //['label' => Yii::t('app', 'Pages'), 'icon' => 'fa fa-file-code-o', 'url' => ['/page/']],  
35 - //['label' => 'Каталог', 'icon' => 'fa fa-file-code-o', 'url' => ['/catalog/']],  
36 - ['label' => 'Меню', 'icon' => 'fa fa-file-code-o', 'url' => ['/menu/']],  
37 - ['label' => 'Заявки', 'icon' => 'fa fa-file-code-o', 'url' => ['/site/requests/']],  
38 - ['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii']],  
39 - ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug']],  
40 - ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],  
41 - ['label' => 'Пользователи', 'icon' => 'fa fa-file-code-o', 'url' => ['/user/']],  
42 - [  
43 - 'label' => Yii::t('app', 'Blog'),  
44 - 'icon' => 'fa fa-share',  
45 - 'url' => '#',  
46 - 'items' => [  
47 - ['label' => Yii::t('app', 'Static pages'), 'icon' => 'fa fa-file-code-o', 'url' => ['blog/articles', 'category_id' => '63'],],  
48 - ['label' => Yii::t('app', 'Categories'), 'icon' => 'fa fa-dashboard', 'url' => ['blog/categories'],],  
49 - ['label' => Yii::t('app', 'Articles'), 'icon' => 'fa fa-dashboard', 'url' => ['blog/articles'],],  
50 - ],  
51 - ],  
52 - [  
53 - 'label' => 'Роли',  
54 - 'icon' => 'fa fa-share',  
55 - 'url' => '#',  
56 - 'items' => [  
57 - ['label' => 'Управление ролями', 'icon' => 'fa fa-file-code-o', 'url' => ['/permit/access/role'],],  
58 - ['label' => 'Управление правами доступа', 'icon' => 'fa fa-dashboard', 'url' => ['/permit/access/permission'],],  
59 - ],  
60 - ],  
61 - [  
62 - 'label' => 'Same tools',  
63 - 'icon' => 'fa fa-share',  
64 - 'url' => '#',  
65 - 'items' => [  
66 - ['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii'],],  
67 - ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug'],],  
68 - [  
69 - 'label' => 'Level One',  
70 - 'icon' => 'fa fa-circle-o',  
71 - 'url' => '#',  
72 - 'items' => [  
73 - ['label' => 'Level Two', 'icon' => 'fa fa-circle-o', 'url' => '#',],  
74 - [  
75 - 'label' => 'Level Two',  
76 - 'icon' => 'fa fa-circle-o',  
77 - 'url' => '#',  
78 - 'items' => [  
79 - ['label' => 'Level Three', 'icon' => 'fa fa-circle-o', 'url' => '#',],  
80 - ['label' => 'Level Three', 'icon' => 'fa fa-circle-o', 'url' => '#',],  
81 - ],  
82 - ],  
83 - ],  
84 - ],  
85 - ],  
86 - ],  
87 - ],  
88 - ]  
89 - ) ?> 17 + <?= dmstr\widgets\Menu::widget([
  18 + 'options' => ['class' => 'sidebar-menu'],
  19 + 'items' => array_merge(
  20 + \backend\models\AdminMenu::buildMenu(),
  21 + [
  22 + ['label' => Yii::t('app', 'Settings'), 'url' => ['/settings/index'], 'icon' => 'fa fa-gear']
  23 + ]
  24 + ),
  25 + ]) ?>
90 26
91 </section> 27 </section>
92 28
backend/views/layouts/settings.php 0 → 100644
  1 +<?php
  2 +
  3 +use dmstr\widgets\Menu;
  4 +use yii\widgets\Breadcrumbs;
  5 +use yii\helpers\Html;
  6 +
  7 +/* @var $content string */
  8 +$this->beginContent('@app/views/layouts/main.php');
  9 +?>
  10 + <div class="row">
  11 + <div class="col-md-3">
  12 + <div class="box box-solid">
  13 + <div class="box-header with-border">
  14 + <h3 class="box-title"><?=Yii::t('app', 'Settings categories')?></h3>
  15 + <div class="box-tools">
  16 + <button type="button" class="btn btn-box-tool" data-widget="collapse">
  17 + <i class="fa fa-minus"></i>
  18 + </button>
  19 + </div>
  20 + </div>
  21 + <div class="box-body no-padding">
  22 + <?php
  23 + echo Menu::widget([
  24 + 'options' => [
  25 + 'class' => 'nav nav-pills nav-stacked'
  26 + ],
  27 + 'items' => [
  28 + ['label' => Yii::t('app', 'Admin Menus'), 'url' => ['/admin-menu/index'], 'icon' => 'fa fa-navicon'],
  29 + ['label' => Yii::t('app', 'Next menu item'), 'url' => ['#'], 'icon' => 'fa fa-arrow-circle-o-right'],
  30 + ],
  31 + ]);
  32 + ?>
  33 + </div>
  34 + </div>
  35 + </div>
  36 + <div class="col-md-9">
  37 + <?= $content ?>
  38 + </div>
  39 + </div>
  40 +<?php $this->endContent() ?>
0 \ No newline at end of file 41 \ No newline at end of file
backend/views/menu/index.php
@@ -25,13 +25,15 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -25,13 +25,15 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
25 'filterModel' => $searchModel, 25 'filterModel' => $searchModel,
26 'columns' => [ 26 'columns' => [
27 ['class' => 'yii\grid\SerialColumn'], 27 ['class' => 'yii\grid\SerialColumn'],
28 - 28 +/*
29 [ 29 [
30 'attribute' => Yii::t('app', 'termin'), 30 'attribute' => Yii::t('app', 'termin'),
31 - 'value' => function ($model) {  
32 - return empty($model->termin_id) ? '-' : $model->termin_lang->termin_title; 31 + 'value' => function ($model)
  32 + {
  33 + return empty ($model->termin_id) ? '-' : $model->terminLang->termin_title;
33 }, 34 },
34 - ], 35 + ],
  36 + */
35 'menu_pid', 37 'menu_pid',
36 'level', 38 'level',
37 // 'sortorder', 39 // 'sortorder',
backend/views/new-options-lang/_form.php
@@ -14,7 +14,7 @@ use yii\widgets\ActiveForm; @@ -14,7 +14,7 @@ use yii\widgets\ActiveForm;
14 14
15 <?= $form->field($model, 'id')->textInput() ?> 15 <?= $form->field($model, 'id')->textInput() ?>
16 16
17 - <?= $form->field($model, 'lang_id')->textInput() ?> 17 + <?= $form->field($model, 'language_id')->textInput() ?>
18 18
19 <?= $form->field($model, 'value')->textarea(['rows' => 6]) ?> 19 <?= $form->field($model, 'value')->textarea(['rows' => 6]) ?>
20 20
backend/views/new-options-lang/_search.php
@@ -19,7 +19,7 @@ use yii\widgets\ActiveForm; @@ -19,7 +19,7 @@ use yii\widgets\ActiveForm;
19 19
20 <?= $form->field($model, 'id') ?> 20 <?= $form->field($model, 'id') ?>
21 21
22 - <?= $form->field($model, 'lang_id') ?> 22 + <?= $form->field($model, 'language_id') ?>
23 23
24 <?= $form->field($model, 'value') ?> 24 <?= $form->field($model, 'value') ?>
25 25
backend/views/new-options-lang/index.php
@@ -27,7 +27,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -27,7 +27,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
27 27
28 'primary', 28 'primary',
29 'id', 29 'id',
30 - 'lang_id', 30 + 'language_id',
31 'value:ntext', 31 'value:ntext',
32 32
33 ['class' => 'yii\grid\ActionColumn'], 33 ['class' => 'yii\grid\ActionColumn'],
backend/views/new-options-lang/view.php
@@ -30,7 +30,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -30,7 +30,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
30 'attributes' => [ 30 'attributes' => [
31 'primary', 31 'primary',
32 'id', 32 'id',
33 - 'lang_id', 33 + 'language_id',
34 'value:ntext', 34 'value:ntext',
35 ], 35 ],
36 ]) ?> 36 ]) ?>
backend/views/option/_form_edit.php
@@ -21,7 +21,7 @@ use yii\widgets\ActiveForm; @@ -21,7 +21,7 @@ use yii\widgets\ActiveForm;
21 <?php if($row->hasErrors()) { ?><div class="help-block"><?php echo $modellang[$id][0]->getFirstError('value');?></div> <?php } ?> 21 <?php if($row->hasErrors()) { ?><div class="help-block"><?php echo $modellang[$id][0]->getFirstError('value');?></div> <?php } ?>
22 <?php 22 <?php
23 if($row->translate) { 23 if($row->translate) {
24 - foreach($row->getLangs() as $lang_id => $lang) { 24 + foreach($row->getLangs() as $language_id => $lang) {
25 ?> 25 ?>
26 <div class="form-group"> 26 <div class="form-group">
27 <div class="col-xs-1"><?=$lang['lang_code']?></div> 27 <div class="col-xs-1"><?=$lang['lang_code']?></div>
backend/views/settings/index.php 0 → 100644
  1 +<?php
  2 +
  3 +/* @var $this yii\web\View */
  4 +
  5 +use backend\models\AdminMenu;
  6 +use dmstr\widgets\Menu;
  7 +use yii\helpers\Url;
  8 +
  9 +$this->title = Yii::t('app', 'Settings');
  10 +$this->params['breadcrumbs'][] = $this->title;
  11 +?>
backend/views/site/index.php
@@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
2 2
3 /* @var $this yii\web\View */ 3 /* @var $this yii\web\View */
4 4
  5 +use backend\models\AdminMenu;
  6 +use yii\helpers\Url;
  7 +
5 $this->title = 'My Yii Application'; 8 $this->title = 'My Yii Application';
6 ?> 9 ?>
7 <div class="site-index"> 10 <div class="site-index">
backend/views/termin/_article_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\bootstrap\ActiveField;
  4 +use mihaildev\ckeditor\CKEditor;
  5 +
  6 +$form = \yii\bootstrap\ActiveForm::begin();
  7 +?>
  8 +<div role="" class="tab-pane active ajax-loaded" id="<?=$widget_id?>-<?=$model->language_id?>">
  9 +
  10 + <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]lang_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?>
  11 +
  12 + <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]termin_title"]))->textInput() ?>
  13 +
  14 + <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]termin_alias"]))->textInput() ?>
  15 +
  16 +</div>
  17 +<?php
  18 +$form->end();
  19 +?>
backend/views/termin/_form.php
@@ -37,8 +37,8 @@ use yii\helpers\ArrayHelper; @@ -37,8 +37,8 @@ use yii\helpers\ArrayHelper;
37 37
38 <?= $form->field($model_lang, 'termin_alias')->textInput() ?> 38 <?= $form->field($model_lang, 'termin_alias')->textInput() ?>
39 39
40 - <?= Html::activeHiddenInput ($model_lang, 'lang_id', [  
41 - 'value' => ($model_lang->lang_id != 0 ? $model_lang->lang_id : Yii::$app->params['lang_id']), 40 + <?= Html::activeHiddenInput ($model_lang, 'language_id', [
  41 + 'value' => ($model_lang->language_id != 0 ? $model_lang->language_id : Yii::$app->params['language_id']),
42 ]) ?> 42 ]) ?>
43 43
44 <div class="form-group"> 44 <div class="form-group">
backend/views/termin/create.php
@@ -17,6 +17,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -17,6 +17,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
17 <?= $this->render('_form', [ 17 <?= $this->render('_form', [
18 'model' => $model, 18 'model' => $model,
19 'model_lang' => $model_lang, 19 'model_lang' => $model_lang,
  20 + 'model_pid' => $model_pid,
20 ]) ?> 21 ]) ?>
21 22
22 </div> 23 </div>
backend/views/termin/index.php
@@ -19,17 +19,20 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -19,17 +19,20 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
19 <?= Html::a(Yii::t('app', 'Create'), ['create'], ['class' => 'btn btn-success']) ?> 19 <?= Html::a(Yii::t('app', 'Create'), ['create'], ['class' => 'btn btn-success']) ?>
20 </p> 20 </p>
21 21
  22 +
22 <?= GridView::widget([ 23 <?= GridView::widget([
23 'dataProvider' => $dataProvider, 24 'dataProvider' => $dataProvider,
24 'filterModel' => $searchModel, 25 'filterModel' => $searchModel,
25 'columns' => [ 26 'columns' => [
26 ['class' => 'yii\grid\SerialColumn'], 27 ['class' => 'yii\grid\SerialColumn'],
27 [ 28 [
28 - 'attribute' => Yii::t('app', 'termin'),  
29 - 'value' => function ($model) {  
30 - return $model->terminLangs[0]->termin_title;  
31 - },  
32 - ], 29 + 'attribute' => 'termin_title',
  30 + 'value' => 'terminLangs.termin_title'
  31 + ],
  32 + [
  33 + 'attribute' => 'termin_parent_title',
  34 + 'value' => 'parent.terminLangs.termin_title'
  35 + ],
33 'termin_name', 36 'termin_name',
34 'is_book', 37 'is_book',
35 38
backend/web/css/site.css
@@ -89,3 +89,47 @@ a.desc:after { @@ -89,3 +89,47 @@ a.desc:after {
89 padding: 10px 20px; 89 padding: 10px 20px;
90 margin: 0 0 15px 0; 90 margin: 0 0 15px 0;
91 } 91 }
  92 +.header-search {
  93 + width: 200px;
  94 +}
  95 +.skin-blue .sidebar-form {
  96 + margin: 5px !important;
  97 +}
  98 +.checkboxer .list-group-item {
  99 + padding: 0;
  100 +}
  101 +.checkboxer .list-group-item:hover {
  102 + background: #ddd;
  103 +}
  104 +.checkboxer .list-group-item.active, .checkboxer .list-group-item.active:hover {
  105 + background: #00a65a;
  106 +}
  107 +.checkboxer .list-group-item.active label, .checkboxer .list-group-item.active:hover label {
  108 + color: white;
  109 +}
  110 +.checkboxer .list-group-item.level0 {
  111 + padding-left: 15px;
  112 +}
  113 +.checkboxer .list-group-item.level1 {
  114 + padding-left: 45px;
  115 +}
  116 +.checkboxer .list-group-item.level2 {
  117 + padding-left: 75px;
  118 +}
  119 +.checkboxer .checkboxer_label {
  120 + padding: 10px 0;
  121 + display: block;
  122 +}
  123 +.checkboxer .checkboxer_label input[type=radio] {
  124 + position: absolute;
  125 + clip: rect(0,0,0,0);
  126 +}
  127 +.action_link {
  128 + float: left;
  129 +}
  130 +.admin_grid_action {
  131 + padding: 0 20px;
  132 +}
  133 +.admin_grid_action .pagination {
  134 + margin: 0;
  135 +}
backend/web/js/option.js
@@ -12,6 +12,11 @@ function readURL(input) { @@ -12,6 +12,11 @@ function readURL(input) {
12 } 12 }
13 return urls; 13 return urls;
14 } 14 }
  15 +function checkboxerInit() {
  16 + $.each($('.checkboxer input[type=radio]:checked'), function(index, value) {
  17 + $(value).trigger('change');
  18 + });
  19 +}
15 $(function() { 20 $(function() {
16 var counter = 0; 21 var counter = 0;
17 $(document).on('click', '.add_row', function() { 22 $(document).on('click', '.add_row', function() {
@@ -36,57 +41,93 @@ $(function() { @@ -36,57 +41,93 @@ $(function() {
36 $(document).on('click', '.remove_lang', function() { 41 $(document).on('click', '.remove_lang', function() {
37 $(this).parents('.form-wrapper').remove(); 42 $(this).parents('.form-wrapper').remove();
38 }); 43 });
39 - if($('#lang-tabs li').length > 1) {  
40 - $('#lang-tabs li').append('<span class="glyphicon glyphicon-remove-circle remove-lang"></span>')  
41 - }  
42 - $(document).on('click', '#lang-dropdown li a[data-lang]', function() { 44 + $(document).on('change', '.image_inputs_field', function() {
  45 + readURL(this);
  46 + });
  47 + $('a.remove_image').on('click', function(e) {
  48 + var el = $(this);
  49 + e.preventDefault();
  50 + if(confirm(confirm_message)) {
  51 + $.ajax({
  52 + type: 'post',
  53 + url: $(this).attr('href'),
  54 + data: $(this).data('params')
  55 + }).done(function() {
  56 + $(el).parents('.additional_image_container').remove();
  57 + });
  58 + }
  59 + return false;
  60 + });
  61 + $.each($('.nav-tabs.f32'), function(key, value) {
  62 + if($(value).find('li').length > 1) {
  63 + $(value).find('li').append('<span class="glyphicon glyphicon-remove-circle remove-lang"></span>');
  64 + }
  65 + });
  66 + $(document).on('click', '.dropdown-menu.f32:not(.old) li a[data-lang]', function() {
  67 + var lang = $(this).data('lang');
  68 + var flag = $(this).find('span').first().clone();
  69 + var el = $(this);
  70 + var id = $(this).attr('href').substr(1);
  71 + var path = form[id].handler;
  72 + var view = form[id].view;
  73 + var model = form[id].model;
  74 + $.get(path, { language_id: lang, widget_id: id, ajaxView: view, model: model }, function(data) {
  75 + $('#'+id+'-tabs li').removeClass('active');
  76 + $('#'+id+'-tabs').append('<li role="lang_inputs" class="active" data-lang="'+lang+'"><a href="#'+id+'-'+lang+'" aria-controls="'+id+'-'+lang+'" role="tab" data-toggle="tab">'+$('<p>').append($(flag)).html()+'</a></li>');
  77 + $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
  78 + $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
  79 + $('body').append($(data).filter('script'));
  80 + $(el).parent().remove();
  81 + if(!$('#lang-'+id+' li').length) {
  82 + $('#'+id+'Lang').addClass('disabled');
  83 + }
  84 + if($('#'+id+'-tabs li').length > 1) {
  85 + $('#'+id+'-tabs li').append('<span class="glyphicon glyphicon-remove-circle remove-lang"></span>')
  86 + }
  87 + });
  88 + });
  89 + $(document).on('click', '.dropdown-menu.f32.old li a[data-lang]', function(e) {
  90 + e.preventDefault();
43 var lang = $(this).data('lang'); 91 var lang = $(this).data('lang');
44 var flag = $(this).find('span').first().clone(); 92 var flag = $(this).find('span').first().clone();
45 var el = $(this); 93 var el = $(this);
46 - $.get('/blog/ajax/category-form', { lang_id: lang }, function(data) {  
47 - $('#lang-tabs li').removeClass('active');  
48 - $('#lang-tabs').append('<li role="lang_inputs" class="active" data-lang="'+lang+'"><a href="#lang-'+lang+'" aria-controls="lang-'+lang+'" role="tab" data-toggle="tab">'+$('<p>').append($(flag)).html()+'</a></li>');  
49 - $('.lang-tab-content .tab-pane.active').removeClass('active');  
50 - $('.lang-tab-content').append($(data).find('.ajax-loaded').first()); 94 + var id = $(this).attr('href').substr(1);
  95 + $.get(form[id], { language_id: lang, widget_id: id }, function(data) {
  96 + $('#'+id+'-tabs li').removeClass('active');
  97 + $('#'+id+'-tabs').append('<li role="lang_inputs" class="active" data-lang="'+lang+'"><a href="#'+id+'-'+lang+'" aria-controls="'+id+'-'+lang+'" role="tab" data-toggle="tab">'+$('<p>').append($(flag)).html()+'</a></li>');
  98 + $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
  99 + $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
51 $('body').append($(data).filter('script')); 100 $('body').append($(data).filter('script'));
52 $(el).parent().remove(); 101 $(el).parent().remove();
53 - if(!$('#lang-dropdown li').length) {  
54 - $('#dropdownLang').addClass('disabled'); 102 + if(!$('#lang-'+id+' li').length) {
  103 + $('#'+id+'Lang').addClass('disabled');
55 } 104 }
56 - if($('#lang-tabs li').length > 1) {  
57 - $('#lang-tabs li').append('<span class="glyphicon glyphicon-remove-circle remove-lang"></span>') 105 + if($('#'+id+'-tabs li').length > 1) {
  106 + $('#'+id+'-tabs li').append('<span class="glyphicon glyphicon-remove-circle remove-lang"></span>')
58 } 107 }
59 }); 108 });
60 }); 109 });
61 $(document).on('click', '.remove-lang', function() { 110 $(document).on('click', '.remove-lang', function() {
62 var lang = $(this).parent().data('lang'); 111 var lang = $(this).parent().data('lang');
63 var flag = $(this).parent().find('span.flag').first().clone(); 112 var flag = $(this).parent().find('span.flag').first().clone();
64 - $('#lang-'+lang).remove();  
65 - $('#lang-dropdown').append('<li><a href="#lang-tabs" data-lang="'+lang+'">'+$('<p>').append($(flag)).html()+'</a></li>');  
66 - $('#dropdownLang').removeClass('disabled'); 113 + var id = $(this).parent().find('a[aria-controls]').first().attr('aria-controls').substr(0,8);
  114 + $('#'+id+'-'+lang).remove();
  115 + $('#lang-'+id).append('<li><a href="#'+id+'" data-lang="'+lang+'">'+$('<p>').append($(flag)).html()+'</a></li>');
  116 + $('#'+id+'Lang').removeClass('disabled');
67 $(this).parent().remove(); 117 $(this).parent().remove();
68 - if($('#lang-tabs li').length <= 1) {  
69 - $('#lang-tabs li').find('.remove-lang').remove(); 118 + if($('#'+id+'-tabs li').length <= 1) {
  119 + $('#'+id+'-tabs li').find('.remove-lang').remove();
70 } 120 }
71 - if(!$('#lang-tabs>li.active').length) {  
72 - $('#lang-tabs>li').first().find('a').tab('show'); 121 + if(!$('#'+id+'-tabs>li.active').length) {
  122 + $('#'+id+'-tabs>li').first().find('a').tab('show');
73 } 123 }
74 }); 124 });
75 - $(document).on('change', '.image_inputs_field', function() {  
76 - readURL(this); 125 + $(document).on('change', '.checkboxer .checkboxer_label input[type=radio]', function() {
  126 + $(this).parents('.checkboxer').find('.checkboxer_container').removeClass('active');
  127 + $(this).parents('.checkboxer_container').addClass('active');
77 }); 128 });
78 - $('a.remove_image').on('click', function(e) {  
79 - var el = $(this);  
80 - e.preventDefault();  
81 - if(confirm(confirm_message)) {  
82 - $.ajax({  
83 - type: 'post',  
84 - url: $(this).attr('href'),  
85 - data: $(this).data('params')  
86 - }).done(function() {  
87 - $(el).parents('.additional_image_container').remove();  
88 - });  
89 - }  
90 - return false; 129 + $.each($('.f32'), function(i, val) {
  130 + $(val).find('a[role=tab]').first().trigger('click');
91 }); 131 });
  132 + checkboxerInit();
92 }); 133 });
93 \ No newline at end of file 134 \ No newline at end of file
common/components/LangRequest.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace common\components; 3 namespace common\components;
4 4
5 use Yii; 5 use Yii;
  6 +use yii\base\InvalidConfigException;
6 use yii\web\Request; 7 use yii\web\Request;
7 use common\models\Language; 8 use common\models\Language;
8 use common\models\Page; 9 use common\models\Page;
@@ -29,10 +30,10 @@ class LangRequest extends Request @@ -29,10 +30,10 @@ class LangRequest extends Request
29 30
30 Language::setCurrent($lang_url); 31 Language::setCurrent($lang_url);
31 32
32 - if ($lang_url !== null && $lang_url === Language::getCurrent()->lang_code  
33 - && strpos($this->_lang_url, Language::getCurrent()->lang_code) === 1) 33 + if ($lang_url !== null && $lang_url === Language::getCurrent()->language_code
  34 + && strpos($this->_lang_url, Language::getCurrent()->language_code) === 1)
34 { 35 {
35 - $this->_lang_url = substr ($this->_lang_url, strlen (Language::getCurrent()->lang_code) + 1); 36 + $this->_lang_url = substr ($this->_lang_url, strlen (Language::getCurrent()->language_code) + 1);
36 } 37 }
37 } 38 }
38 39
common/components/LangUrlManager.php
@@ -9,16 +9,16 @@ class LangUrlManager extends UrlManager @@ -9,16 +9,16 @@ class LangUrlManager extends UrlManager
9 { 9 {
10 public function createUrl ($params) 10 public function createUrl ($params)
11 { 11 {
12 - if (isset ($params['lang_id'])) 12 + if (isset ($params['language_id']))
13 { 13 {
14 //Если указан идентификатор языка, то делаем попытку найти язык в БД, 14 //Если указан идентификатор языка, то делаем попытку найти язык в БД,
15 //иначе работаем с языком по умолчанию 15 //иначе работаем с языком по умолчанию
16 - if (($lang_code = Language::findOne($params['lang_id'])) === null) 16 + if (($lang_code = Language::findOne($params['language_id'])) === null)
17 { 17 {
18 $lang_code = Language::getDefaultLang(); 18 $lang_code = Language::getDefaultLang();
19 } 19 }
20 20
21 - unset ($params['lang_id']); 21 + unset ($params['language_id']);
22 22
23 } 23 }
24 else 24 else
common/config/.gitignore 0 → 100644
  1 +main-local.php
0 \ No newline at end of file 2 \ No newline at end of file
common/config/main.php
@@ -8,6 +8,9 @@ return [ @@ -8,6 +8,9 @@ return [
8 'userClass' => 'common\models\User' 8 'userClass' => 'common\models\User'
9 ] 9 ]
10 ], 10 ],
  11 + 'blog' => [
  12 + 'class' => 'common\modules\blog\Module',
  13 + ],
11 ], 14 ],
12 'components' => [ 15 'components' => [
13 'cache' => [ 16 'cache' => [
common/models/Catalog.php
@@ -23,21 +23,21 @@ class Catalog extends Model @@ -23,21 +23,21 @@ class Catalog extends Model
23 termin_lang.termin_title 23 termin_lang.termin_title
24 FROM termin_structure 24 FROM termin_structure
25 INNER JOIN termin_lang ON termin_lang.termin_id = termin_structure.termin_id 25 INNER JOIN termin_lang ON termin_lang.termin_id = termin_structure.termin_id
26 - AND termin_lang.lang_id = '.Yii::$app->params['lang_id'].' 26 + AND termin_lang.language_id = '.Yii::$app->params['language_id'].'
27 ORDER BY termin_structure.termin_id ASC, termin_structure.termin_pid ASC 27 ORDER BY termin_structure.termin_id ASC, termin_structure.termin_pid ASC
28 ')->queryAll(); 28 ')->queryAll();
29 } 29 }
30 30
31 /** 31 /**
32 * Выполняет поиск по параметрам 32 * Выполняет поиск по параметрам
33 - * @param array $param принимает [catalog_id, lang_id, return_one, return_field, show_all] 33 + * @param array $param принимает [catalog_id, language_id, return_one, return_field, show_all]
34 * @return array one | array all | string значение масива 34 * @return array one | array all | string значение масива
35 */ 35 */
36 public function finInfo (array $params = []) 36 public function finInfo (array $params = [])
37 { 37 {
38 Tools::ifNotExist ($params, array ( 38 Tools::ifNotExist ($params, array (
39 'catalog_id' => false, 39 'catalog_id' => false,
40 - 'lang_id' => false, 40 + 'language_id' => false,
41 'return_one' => false, 41 'return_one' => false,
42 'return_field' => false, 42 'return_field' => false,
43 'show_all' => false, 43 'show_all' => false,
@@ -57,9 +57,9 @@ class Catalog extends Model @@ -57,9 +57,9 @@ class Catalog extends Model
57 $WHERE['catalog.catalog_id'] = $params['catalog_id']; 57 $WHERE['catalog.catalog_id'] = $params['catalog_id'];
58 } 58 }
59 59
60 - if ($params['lang_id']) 60 + if ($params['language_id'])
61 { 61 {
62 - $WHERE['catalog_i18n.lang_id'] = $params['lang_id']; 62 + $WHERE['catalog_i18n.language_id'] = $params['language_id'];
63 } 63 }
64 64
65 if (! empty ($WHERE)) 65 if (! empty ($WHERE))
@@ -144,7 +144,7 @@ class Catalog extends Model @@ -144,7 +144,7 @@ class Catalog extends Model
144 */ 144 */
145 public function getRelationCatalogLangPlus() 145 public function getRelationCatalogLangPlus()
146 { 146 {
147 - return $this->getRelationCatalogLang()->where(['lang_id' => yii::$app->params['lang_id']]); 147 + return $this->getRelationCatalogLang()->where(['language_id' => yii::$app->params['language_id']]);
148 } 148 }
149 149
150 /** 150 /**
common/models/Language.php
@@ -8,7 +8,11 @@ use Yii; @@ -8,7 +8,11 @@ use Yii;
8 * This is the model class for table "language". 8 * This is the model class for table "language".
9 * 9 *
10 * @property integer $language_id 10 * @property integer $language_id
11 - * @property string $lang_code 11 + * @property string $language_code
  12 + * @property string $is_default
  13 + * @property string $language_name
  14 + * @property string $status
  15 + * @property string $country_code
12 */ 16 */
13 class Language extends \yii\db\ActiveRecord 17 class Language extends \yii\db\ActiveRecord
14 { 18 {
@@ -32,8 +36,8 @@ class Language extends \yii\db\ActiveRecord @@ -32,8 +36,8 @@ class Language extends \yii\db\ActiveRecord
32 $language = self::getLangByUrl($lang_code); 36 $language = self::getLangByUrl($lang_code);
33 self::$current = ($language === null) ? self::getDefaultLang() : $language; 37 self::$current = ($language === null) ? self::getDefaultLang() : $language;
34 // задаем 38 // задаем
35 - Yii::$app->language = self::$current->lang_code;  
36 - Yii::$app->params['lang_id'] = self::$current->language_id; 39 + Yii::$app->language = self::$current->language_code;
  40 + Yii::$app->params['language_id'] = self::$current->language_id;
37 } 41 }
38 42
39 //Получения объекта языка по умолчанию 43 //Получения объекта языка по умолчанию
@@ -48,7 +52,7 @@ class Language extends \yii\db\ActiveRecord @@ -48,7 +52,7 @@ class Language extends \yii\db\ActiveRecord
48 if ($lang_code === null) { 52 if ($lang_code === null) {
49 return null; 53 return null;
50 } else { 54 } else {
51 - $language = Language::find()->where('lang_code = :what', [':what' => $lang_code])->one(); 55 + $language = Language::find()->where('language_code = :what', [':what' => $lang_code])->one();
52 return $language === null ? null : $language; 56 return $language === null ? null : $language;
53 } 57 }
54 } 58 }
@@ -67,8 +71,8 @@ class Language extends \yii\db\ActiveRecord @@ -67,8 +71,8 @@ class Language extends \yii\db\ActiveRecord
67 public function rules() 71 public function rules()
68 { 72 {
69 return [ 73 return [
70 - [['lang_code'], 'required'],  
71 - [['lang_code'], 'string', 'max' => 4] 74 + [['language_code', 'language_name', 'country_code'], 'required'],
  75 + [['language_code', 'country_code'], 'string', 'max' => 4]
72 ]; 76 ];
73 } 77 }
74 78
@@ -79,13 +83,17 @@ class Language extends \yii\db\ActiveRecord @@ -79,13 +83,17 @@ class Language extends \yii\db\ActiveRecord
79 { 83 {
80 return [ 84 return [
81 'language_id' => Yii::t('app/Lang', 'Language ID'), 85 'language_id' => Yii::t('app/Lang', 'Language ID'),
82 - 'lang_code' => Yii::t('app/Lang', 'Lang Code'), 86 + 'language_code' => Yii::t('app/Lang', 'Lang Code'),
  87 + 'is_default' => Yii::t('app/Lang', 'Default lang'),
  88 + 'language_name' => Yii::t('app/Lang', 'Language Name'),
  89 + 'status' => Yii::t('app/Lang', 'Language Status'),
  90 + 'country_code' => Yii::t('app/Lang', 'Country Code'),
83 ]; 91 ];
84 } 92 }
85 93
86 public static function getActiveLanguages() 94 public static function getActiveLanguages()
87 { 95 {
88 - return Language::find()->where(['>=', 'language_id', 1])->andWhere(['active' => 1])->orderBy('is_default DESC')->indexBy('language_id')->all(); 96 + return Language::find()->where(['>=', 'language_id', 1])->andWhere(['status' => 1])->orderBy('is_default DESC')->indexBy('language_id')->all();
89 } 97 }
90 98
91 } 99 }
common/models/Media.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use common\modules\blog\models\Article;
  6 +use common\modules\blog\models\ArticleCategoryMedia;
  7 +use common\modules\blog\models\ArticleMedia;
  8 +use Yii;
  9 +use yii\db\ActiveRecord;
  10 +use yii\web\UploadedFile;
  11 +
  12 +/**
  13 + * This is the model class for table "media".
  14 + *
  15 + * @property integer $media_id
  16 + * @property string $hash
  17 + * @property string $extension
  18 + *
  19 + * @property ArticleCategoryMedia[] $articleCategoryMedia
  20 + * @property ArticleMedia[] $articleMedia
  21 + */
  22 +class Media extends ActiveRecord
  23 +{
  24 + /**
  25 + * @var UploadedFile[];
  26 + */
  27 + public $imageFile;
  28 +
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public static function tableName()
  33 + {
  34 + return 'media';
  35 + }
  36 +
  37 + /**
  38 + * @inheritdoc
  39 + */
  40 + public function rules()
  41 + {
  42 + return [
  43 + [['media_id'], 'integer'],
  44 + [['hash', 'extension'], 'string'],
  45 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpeg, jpg', 'skipOnEmpty' => true],
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * @inheritdoc
  51 + */
  52 + public function attributeLabels()
  53 + {
  54 + return [
  55 + 'media_id' => Yii::t('app', 'ID'),
  56 + 'hash' => Yii::t('app', 'Hash'),
  57 + 'extension' => Yii::t('app', 'Extension'),
  58 + ];
  59 + }
  60 +
  61 + /**
  62 + * @return \yii\db\ActiveQuery
  63 + */
  64 + public function getArticleCategoryMedia()
  65 + {
  66 + return $this->hasMany(ArticleCategoryMedia::className(), ['media_id' => 'media_id']);
  67 + }
  68 +
  69 + /**
  70 + * @return \yii\db\ActiveQuery
  71 + */
  72 + public function getArticleMedia()
  73 + {
  74 + return $this->hasMany(ArticleMedia::className(), ['media_id' => 'media_id']);
  75 + }
  76 +
  77 + public function getArticle()
  78 + {
  79 + return $this->hasMany(Article::className(), ['article_id' => 'article_id'])->via('articleMedia');
  80 + }
  81 +
  82 + public function upload()
  83 + {
  84 + if(!empty($this->imageFile) && $this->validate('imageFile'))
  85 + {
  86 + $uploaddir = \Yii::getAlias('@saveImageDir');
  87 + $this->hash = md5_file($this->imageFile->tempName).\Yii::$app->security->generateRandomString(5);
  88 + $this->extension = $this->imageFile->extension;
  89 + if(is_dir($uploaddir.$this->hash)) {
  90 + return false;
  91 + } else {
  92 + if(!mkdir($uploaddir.$this->hash, 0755)) {
  93 + return false;
  94 + }
  95 + }
  96 + $this->imageFile->saveAs($uploaddir.$this->hash.'/original.'.$this->imageFile->extension, false);
  97 + if($this->save(false)) {
  98 + return true;
  99 + } else {
  100 + $this->addError('imageFile', \Yii::t('app', 'Cannot load file'));
  101 + return false;
  102 + }
  103 + } else {
  104 + return false;
  105 + }
  106 + }
  107 +
  108 + public function delete()
  109 + {
  110 + $uploaddir = \Yii::getAlias('@saveImageDir');
  111 + if(is_dir($uploaddir.$this->hash)) {
  112 + $this->removeDir($uploaddir.$this->hash);
  113 + }
  114 + return parent::delete();
  115 + }
  116 +
  117 + public function removeDir($dir)
  118 + {
  119 + if($objs = glob($dir."/*")) {
  120 + foreach($objs as $obj) {
  121 + is_dir($obj) ? removeDir($obj) : unlink($obj);
  122 + }
  123 + }
  124 + rmdir($dir);
  125 + }
  126 +}
common/models/Tools.php
@@ -98,4 +98,19 @@ class Tools @@ -98,4 +98,19 @@ class Tools
98 98
99 return $url; 99 return $url;
100 } 100 }
  101 +
  102 + static function parseUrlParams($params)
  103 + {
  104 + $params = preg_split('/,\s*/', $params, -1, PREG_SPLIT_NO_EMPTY);
  105 + $result = [];
  106 + if($params) {
  107 + foreach($params as $param) {
  108 + $param = preg_split('/\s*=\s*/', $param);
  109 + if(!empty($param[0]) && !empty($param[1])) {
  110 + $result[$param[0]] = $param[1];
  111 + }
  112 + }
  113 + }
  114 + return $result;
  115 + }
101 } 116 }
102 \ No newline at end of file 117 \ No newline at end of file
common/modules/blog/controllers/AjaxController.php
@@ -7,6 +7,7 @@ use common\modules\blog\models\ArticleCategoryLang; @@ -7,6 +7,7 @@ use common\modules\blog\models\ArticleCategoryLang;
7 use common\modules\blog\models\ArticleCategoryMedia; 7 use common\modules\blog\models\ArticleCategoryMedia;
8 use common\modules\blog\models\ArticleLang; 8 use common\modules\blog\models\ArticleLang;
9 use common\modules\blog\models\ArticleMedia; 9 use common\modules\blog\models\ArticleMedia;
  10 +use yii\base\InvalidParamException;
10 use yii\web\Controller; 11 use yii\web\Controller;
11 use yii\web\ForbiddenHttpException; 12 use yii\web\ForbiddenHttpException;
12 use yii\web\NotFoundHttpException; 13 use yii\web\NotFoundHttpException;
@@ -26,24 +27,50 @@ class AjaxController extends Controller @@ -26,24 +27,50 @@ class AjaxController extends Controller
26 return true; 27 return true;
27 } 28 }
28 29
29 - public function actionCategoryForm($lang_id) 30 + public function actionCategoryForm($language_id, $widget_id)
30 { 31 {
31 - $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['active' => 1, 'language_id' => $lang_id])->one(); 32 + $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['status' => 1, 'language_id' => $language_id])->one();
32 if(!$model) { 33 if(!$model) {
33 throw new NotFoundHttpException('Language not found'); 34 throw new NotFoundHttpException('Language not found');
34 } 35 }
35 $category_lang = new ArticleCategoryLang(); 36 $category_lang = new ArticleCategoryLang();
36 - return $this->renderAjax('_category_form', ['model' => $model, 'category_lang' => $category_lang]); 37 + return $this->renderAjax('_category_form', ['model' => $model, 'category_lang' => $category_lang, 'widget_id' => $widget_id]);
37 } 38 }
38 39
39 - public function actionArticleForm($lang_id) 40 + public function actionArticleForm($language_id, $widget_id)
40 { 41 {
41 - $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['active' => 1, 'language_id' => $lang_id])->one(); 42 + $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['status' => 1, 'language_id' => $language_id])->one();
42 if(!$model) { 43 if(!$model) {
43 throw new NotFoundHttpException('Language not found'); 44 throw new NotFoundHttpException('Language not found');
44 } 45 }
45 $article_lang = new ArticleLang(); 46 $article_lang = new ArticleLang();
46 - return $this->renderAjax('_article_form', ['model' => $model, 'article_lang' => $article_lang]); 47 + return $this->renderAjax('_article_form', ['model' => $model, 'article_lang' => $article_lang, 'widget_id' => $widget_id]);
  48 + }
  49 +
  50 + public function actionArticleMediaForm($language_id, $widget_id, $type)
  51 + {
  52 + $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['status' => 1, 'language_id' => $language_id])->one();
  53 + if(!$model) {
  54 + throw new NotFoundHttpException('Language not found');
  55 + }
  56 + if(!in_array($type, ['full', 'preview'])) {
  57 + throw new InvalidParamException('Type must only be full/preview');
  58 + }
  59 + $article_lang = new ArticleMedia();
  60 + return $this->renderAjax('_article_media_form', ['model' => $model, 'article_lang' => $article_lang, 'widget_id' => $widget_id, 'type' => $type]);
  61 + }
  62 +
  63 + public function actionArticleCategoryMediaForm($language_id, $widget_id, $type)
  64 + {
  65 + $model = Language::find()->where(['>=', 'language_id', 1])->andWhere(['status' => 1, 'language_id' => $language_id])->one();
  66 + if(!$model) {
  67 + throw new NotFoundHttpException('Language not found');
  68 + }
  69 + if(!in_array($type, ['full', 'preview'])) {
  70 + throw new InvalidParamException('Type must only be full/preview');
  71 + }
  72 + $article_lang = new ArticleCategoryMedia();
  73 + return $this->renderAjax('_article_media_form', ['model' => $model, 'article_lang' => $article_lang, 'widget_id' => $widget_id, 'type' => $type]);
47 } 74 }
48 75
49 public function actionRemoveImage() 76 public function actionRemoveImage()
@@ -63,6 +90,23 @@ class AjaxController extends Controller @@ -63,6 +90,23 @@ class AjaxController extends Controller
63 } 90 }
64 } 91 }
65 92
  93 + public function actionRemoveCategoryImage()
  94 + {
  95 + $post = \Yii::$app->request->post();
  96 + if(!empty($post['category_media_id'])) {
  97 + $category_media = ArticleCategoryMedia::findOne($post['category_media_id']);
  98 + if($post['remove_media']) {
  99 + $media = $category_media->media->delete();
  100 + }
  101 + if(!empty($category_media)) {
  102 + $category_media->delete();
  103 + }
  104 + return true;
  105 + } else {
  106 + return false;
  107 + }
  108 + }
  109 +
66 public function actionRemoveImageCategory() 110 public function actionRemoveImageCategory()
67 { 111 {
68 $post = \Yii::$app->request->post(); 112 $post = \Yii::$app->request->post();
@@ -79,4 +123,10 @@ class AjaxController extends Controller @@ -79,4 +123,10 @@ class AjaxController extends Controller
79 return false; 123 return false;
80 } 124 }
81 } 125 }
  126 +
  127 + public function actionMultilangForm($model, $ajaxView, $widget_id, $language_id = NULL)
  128 + {
  129 + $model = new $model(['language_id' => $language_id]);
  130 + return $this->renderAjax($ajaxView, ['model' => $model, 'widget_id' => $widget_id]);
  131 + }
82 } 132 }
common/modules/blog/controllers/ArticleController.php
@@ -28,28 +28,31 @@ class ArticleController extends Controller @@ -28,28 +28,31 @@ class ArticleController extends Controller
28 { 28 {
29 $article_langs = array(); 29 $article_langs = array();
30 $article = new Article(); 30 $article = new Article();
  31 + $default_lang = Language::getDefaultLang();
31 $images = array(); 32 $images = array();
32 - $images['full'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_FULL]);  
33 - $images['preview'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_PREVIEW]);  
34 - $images['additional'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_ADDITIONAL]); 33 + $images[$default_lang->language_id]['full'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_FULL]);
  34 + $images[$default_lang->language_id]['preview'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_PREVIEW]);
  35 + $images[0]['additional'] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_ADDITIONAL]);
35 $article->loadDefaultValues(); 36 $article->loadDefaultValues();
36 $langs = Language::getActiveLanguages(); 37 $langs = Language::getActiveLanguages();
37 - $default_lang = Language::getDefaultLang();  
38 $isValid = false; 38 $isValid = false;
39 if(!empty(\Yii::$app->request->post())) { 39 if(!empty(\Yii::$app->request->post())) {
40 $isValid = true; 40 $isValid = true;
41 $article->load(\Yii::$app->request->post()); 41 $article->load(\Yii::$app->request->post());
42 - $article->author = \Yii::$app->user->getId(); 42 + $article->user_id = \Yii::$app->user->getId();
43 $isValid = $article->validate(); 43 $isValid = $article->validate();
44 - foreach($images as $index => $value) {  
45 - $images[$index]->type = $index;  
46 - if($index == 'additional') {  
47 - $images[$index]->imageFile = UploadedFile::getInstances($images[$index], "[{$index}]imageFile");  
48 - } else {  
49 - $images[$index]->imageFile = UploadedFile::getInstance($images[$index], "[{$index}]imageFile"); 44 + foreach(\Yii::$app->request->post()['ArticleMedia'] as $lang => $value) {
  45 + foreach($value as $type => $fields) {
  46 + $images[$lang][$type] = new ArticleMedia(['scenario' => $type]);
  47 + $images[$lang][$type]->type = $type;
  48 + $images[$lang][$type]->language_id = $lang;
  49 + $images[$lang][$type]->imageFile = UploadedFile::getInstance($images[$lang][$type], "[{$lang}][{$type}]imageFile");
  50 + $isValid = $images[$lang][$type]->validate(['imageFile']) && $isValid;
50 } 51 }
51 - $isValid = $images[$index]->validate(['imageFile']) && $isValid;  
52 } 52 }
  53 + $images[0]['additional']->language_id = 0;
  54 + $images[0]['additional']->type = 'additional';
  55 + $images[0]['additional']->imageFile = UploadedFile::getInstances($images[0]['additional'], "[0][additional]imageFile");
53 if(empty(\Yii::$app->request->post()['ArticleLang'])) { 56 if(empty(\Yii::$app->request->post()['ArticleLang'])) {
54 $article_langs[$default_lang->language_id] = new ArticleLang(); 57 $article_langs[$default_lang->language_id] = new ArticleLang();
55 $isValid = ArticleLang::validateMultiple($article_langs) && $isValid; 58 $isValid = ArticleLang::validateMultiple($article_langs) && $isValid;
@@ -69,18 +72,30 @@ class ArticleController extends Controller @@ -69,18 +72,30 @@ class ArticleController extends Controller
69 if(!empty($article_categories)) { 72 if(!empty($article_categories)) {
70 foreach($article_categories as $article_category) { 73 foreach($article_categories as $article_category) {
71 $articletocategory[$article_category] = new ArticleToCategory(); 74 $articletocategory[$article_category] = new ArticleToCategory();
72 - $articletocategory[$article_category]->category_id = $article_category; 75 + $articletocategory[$article_category]->article_category_id = $article_category;
73 $articletocategory[$article_category]->link('article', $article); 76 $articletocategory[$article_category]->link('article', $article);
74 } 77 }
75 } 78 }
76 $first = 1; 79 $first = 1;
77 - foreach($images as $index => $image) {  
78 - $images[$index]->upload($article->id); 80 + foreach($images as $lang => $value) {
  81 + foreach($value as $type => $fields) {
  82 + $images[$lang][$type]->upload($article->article_id);
  83 + if($first && $type != 'additional') {
  84 + $media_clone = clone $images[$lang][$type];
  85 + $media_clone->setIsNewRecord(true);
  86 + unset($media_clone->article_media_id);
  87 + $media_clone->language_id = 0;
  88 + $media_clone->upload($article->article_id);
  89 + unset($media_clone);
  90 + $first = 0;
  91 + }
  92 + }
79 } 93 }
  94 + $first = 1;
80 foreach($article_langs as $article_lang) { 95 foreach($article_langs as $article_lang) {
81 if($first) { 96 if($first) {
82 $article_lang_clone = clone $article_lang; 97 $article_lang_clone = clone $article_lang;
83 - $article_lang_clone->lang_id = 0; 98 + $article_lang_clone->language_id = 0;
84 $article_lang_clone->link('article', $article); 99 $article_lang_clone->link('article', $article);
85 unset($article_lang_clone); 100 unset($article_lang_clone);
86 } 101 }
@@ -102,49 +117,52 @@ class ArticleController extends Controller @@ -102,49 +117,52 @@ class ArticleController extends Controller
102 public function actionUpdate($id) 117 public function actionUpdate($id)
103 { 118 {
104 $article = Article::findOne($id); 119 $article = Article::findOne($id);
105 - $images = $article->getArticleMedia()->indexBy('type')->all();  
106 - if(!array_key_exists('full', $images)) {  
107 - $images['full'] = new ArticleMedia();  
108 - }  
109 - if(!array_key_exists('preview', $images)) {  
110 - $images['preview'] = new ArticleMedia();  
111 - }  
112 - foreach($images as $index => $image) {  
113 - $images[$index]->scenario = $index; 120 + $imagestack = $article->getArticleMedia()->all();
  121 + $images = [];
  122 + $images[0]['additional'][0] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_ADDITIONAL]);
  123 + $images[0]['additional'][0]->type = 'additional';
  124 + $images[0]['additional'][0]->language_id = 0;
  125 + foreach($imagestack as $image) {
  126 + if(in_array($image->type, ['full', 'preview'])) {
  127 + $images[$image->language_id][$image->type] = $image;
  128 + $images[$image->language_id][$image->type]->scenario = $image->type;
  129 + } else {
  130 + $images[$image->language_id][$image->type][$image->article_media_id] = $image;
  131 + $images[$image->language_id][$image->type][$image->article_media_id]->scenario = $image->type;
  132 + }
114 } 133 }
115 - $images['additional'] = array(  
116 - 0 => new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_ADDITIONAL])  
117 - );  
118 - $images['additional'] = array_merge($images['additional'], $article->getArticleMedia()->andWhere(['type' => 'additional'])->indexBy('id')->all());  
119 - foreach($images['additional'] as $index => $image) {  
120 - $images['additional'][$index]->scenario = 'additional'; 134 + foreach($images as $lang => $value) {
  135 + $images[$lang]['additional'][0] = new ArticleMedia(['scenario' => ArticleMedia::SCENARIO_ADDITIONAL]);
121 } 136 }
122 - $article_langs = $article->getArticleLangs()->where(['>=', 'lang_id', '1'])->indexBy('lang_id')->all(); 137 + $article_langs = $article->getArticleLangs()->where(['>=', 'language_id', '1'])->indexBy('language_id')->all();
123 $langs = Language::getActiveLanguages(); 138 $langs = Language::getActiveLanguages();
124 $default_lang = Language::getDefaultLang(); 139 $default_lang = Language::getDefaultLang();
125 $isValid = false; 140 $isValid = false;
126 if(!empty(\Yii::$app->request->post())) { 141 if(!empty(\Yii::$app->request->post())) {
127 $isValid = true; 142 $isValid = true;
128 $article->load(\Yii::$app->request->post()); 143 $article->load(\Yii::$app->request->post());
129 - ArticleToCategory::deleteAll(['article_id' => $article->id]); 144 + ArticleToCategory::deleteAll(['article_id' => $article->article_id]);
130 $article_categories = \Yii::$app->request->post('Article')['articleCategoriesArray']; 145 $article_categories = \Yii::$app->request->post('Article')['articleCategoriesArray'];
131 if(!empty($article_categories)) { 146 if(!empty($article_categories)) {
132 foreach($article_categories as $article_category) { 147 foreach($article_categories as $article_category) {
133 $articletocategory[$article_category] = new ArticleToCategory(); 148 $articletocategory[$article_category] = new ArticleToCategory();
134 - $articletocategory[$article_category]->category_id = $article_category; 149 + $articletocategory[$article_category]->article_category_id = $article_category;
135 $articletocategory[$article_category]->link('article', $article); 150 $articletocategory[$article_category]->link('article', $article);
136 } 151 }
137 } 152 }
138 $isValid = $article->validate(); 153 $isValid = $article->validate();
139 - foreach($images as $index => $value) {  
140 - if($index == 'additional') {  
141 - $images[$index][0]->type = $index;  
142 - $images[$index][0]->imageFile = UploadedFile::getInstances($images[$index][0], "[{$index}]imageFile");  
143 - $isValid = $images[$index][0]->validate(['imageFile']) && $isValid;  
144 - } else {  
145 - $images[$index]->type = $index;  
146 - $images[$index]->imageFile = UploadedFile::getInstance($images[$index], "[{$index}]imageFile");  
147 - $isValid = $images[$index]->validate(['imageFile']) && $isValid; 154 + $images[0]['additional'][0]->type = 'additional';
  155 + $images[0]['additional'][0]->language_id = 0;
  156 + $images[0]['additional'][0]->imageFile = UploadedFile::getInstances($images[0]['additional'][0], "[0][additional]imageFile");
  157 + $isValid = $images[0]['additional'][0]->validate(['imageFile']) && $isValid;
  158 + foreach(\Yii::$app->request->post()['ArticleMedia'] as $lang => $value) {
  159 + foreach($value as $type => $fields) {
  160 + if(!in_array($type, ['full', 'preview'])) continue;
  161 + $images[$lang][$type] = new ArticleMedia(['scenario' => $type]);
  162 + $images[$lang][$type]->language_id = $lang;
  163 + $images[$lang][$type]->type = $type;
  164 + $images[$lang][$type]->imageFile = UploadedFile::getInstance($images[$lang][$type], "[{$lang}][{$type}]imageFile");
  165 + $isValid = $images[$lang][$type]->validate(['imageFile']) && $isValid;
148 } 166 }
149 } 167 }
150 if(empty(\Yii::$app->request->post()['ArticleLang'])) { 168 if(empty(\Yii::$app->request->post()['ArticleLang'])) {
@@ -153,7 +171,7 @@ class ArticleController extends Controller @@ -153,7 +171,7 @@ class ArticleController extends Controller
153 foreach(\Yii::$app->request->post()['ArticleLang'] as $index => $article_lang) { 171 foreach(\Yii::$app->request->post()['ArticleLang'] as $index => $article_lang) {
154 if (!array_key_exists($index, $article_langs)) { 172 if (!array_key_exists($index, $article_langs)) {
155 $article_langs[$index] = new ArticleLang(); 173 $article_langs[$index] = new ArticleLang();
156 - $article_langs[$index]->article_id = $article->id; 174 + $article_langs[$index]->article_id = $article->article_id;
157 } 175 }
158 } 176 }
159 ArticleLang::loadMultiple($article_langs, \Yii::$app->request->post()); 177 ArticleLang::loadMultiple($article_langs, \Yii::$app->request->post());
@@ -162,12 +180,14 @@ class ArticleController extends Controller @@ -162,12 +180,14 @@ class ArticleController extends Controller
162 } 180 }
163 if($isValid) { 181 if($isValid) {
164 $article->save(false); 182 $article->save(false);
165 - foreach($images as $index => $image) {  
166 - if($index == 'additional') {  
167 - $images[$index][0]->upload($article->id);  
168 - } else {  
169 - if(!empty($images[$index]->imageFile)) {  
170 - $images[$index]->replace($article->id, true); 183 + foreach($images as $lang => $value) {
  184 + foreach($value as $type => $fields) {
  185 + if($type == 'additional') {
  186 + $images[$lang][$type][0]->upload($article->id);
  187 + } else {
  188 + if(!empty($images[$lang][$type]->imageFile)) {
  189 + $images[$lang][$type]->replace($article->article_id);
  190 + }
171 } 191 }
172 } 192 }
173 } 193 }
common/modules/blog/controllers/CategoryController.php
@@ -42,27 +42,30 @@ class CategoryController extends Controller @@ -42,27 +42,30 @@ class CategoryController extends Controller
42 { 42 {
43 $category_langs = array(); 43 $category_langs = array();
44 $category = new ArticleCategory(); 44 $category = new ArticleCategory();
  45 + $default_lang = Language::getDefaultLang();
45 $images = array(); 46 $images = array();
46 - $images['full'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_FULL]);  
47 - $images['preview'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_PREVIEW]);  
48 - $images['additional'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_ADDITIONAL]); 47 + $images[$default_lang->language_id]['full'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_FULL]);
  48 + $images[$default_lang->language_id]['preview'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_PREVIEW]);
  49 + $images[0]['additional'] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_ADDITIONAL]);
49 $category->loadDefaultValues(); 50 $category->loadDefaultValues();
50 $langs = Language::getActiveLanguages(); 51 $langs = Language::getActiveLanguages();
51 - $default_lang = Language::getDefaultLang();  
52 $isValid = false; 52 $isValid = false;
53 - foreach($images as $index => $value) {  
54 - $images[$index]->type = $index;  
55 - if($index == 'additional') {  
56 - $images[$index]->imageFile = UploadedFile::getInstances($images[$index], "[{$index}]imageFile");  
57 - } else {  
58 - $images[$index]->imageFile = UploadedFile::getInstance($images[$index], "[{$index}]imageFile");  
59 - }  
60 - $isValid = $images[$index]->validate(['imageFile']) && $isValid;  
61 - }  
62 if(!empty(\Yii::$app->request->post())) { 53 if(!empty(\Yii::$app->request->post())) {
63 $isValid = true; 54 $isValid = true;
64 $category->load(\Yii::$app->request->post()); 55 $category->load(\Yii::$app->request->post());
65 $isValid = $category->validate(); 56 $isValid = $category->validate();
  57 + foreach(\Yii::$app->request->post()['ArticleCategoryMedia'] as $lang => $value) {
  58 + foreach($value as $type => $fields) {
  59 + $images[$lang][$type] = new ArticleCategoryMedia(['scenario' => $type]);
  60 + $images[$lang][$type]->type = $type;
  61 + $images[$lang][$type]->language_id = $lang;
  62 + $images[$lang][$type]->imageFile = UploadedFile::getInstance($images[$lang][$type], "[{$lang}][{$type}]imageFile");
  63 + $isValid = $images[$lang][$type]->validate(['imageFile']) && $isValid;
  64 + }
  65 + }
  66 + $images[0]['additional']->language_id = 0;
  67 + $images[0]['additional']->type = 'additional';
  68 + $images[0]['additional']->imageFile = UploadedFile::getInstances($images[0]['additional'], "[0][additional]imageFile");
66 if(empty(\Yii::$app->request->post()['ArticleCategoryLang'])) { 69 if(empty(\Yii::$app->request->post()['ArticleCategoryLang'])) {
67 $category_langs[$default_lang->language_id] = new ArticleCategoryLang(); 70 $category_langs[$default_lang->language_id] = new ArticleCategoryLang();
68 $isValid = ArticleCategoryLang::validateMultiple($category_langs) && $isValid; 71 $isValid = ArticleCategoryLang::validateMultiple($category_langs) && $isValid;
@@ -79,13 +82,25 @@ class CategoryController extends Controller @@ -79,13 +82,25 @@ class CategoryController extends Controller
79 if($isValid) { 82 if($isValid) {
80 $category->save(false); 83 $category->save(false);
81 $first = 1; 84 $first = 1;
82 - foreach($images as $index => $image) {  
83 - $images[$index]->upload($category->id); 85 + foreach($images as $lang => $value) {
  86 + foreach($value as $type => $fields) {
  87 + $images[$lang][$type]->upload($category->article_category_id);
  88 + if($first && $type != 'additional') {
  89 + $media_clone = clone $images[$lang][$type];
  90 + $media_clone->setIsNewRecord(true);
  91 + unset($media_clone->article_category_media_id);
  92 + $media_clone->language_id = 0;
  93 + $media_clone->upload($category->article_category_id);
  94 + unset($media_clone);
  95 + $first = 0;
  96 + }
  97 + }
84 } 98 }
  99 + $first = 1;
85 foreach($category_langs as $category_lang) { 100 foreach($category_langs as $category_lang) {
86 if($first) { 101 if($first) {
87 $category_lang_clone = clone $category_lang; 102 $category_lang_clone = clone $category_lang;
88 - $category_lang_clone->lang_id = 0; 103 + $category_lang_clone->language_id = 0;
89 $category_lang_clone->link('category', $category); 104 $category_lang_clone->link('category', $category);
90 unset($category_lang_clone); 105 unset($category_lang_clone);
91 } 106 }
@@ -107,24 +122,24 @@ class CategoryController extends Controller @@ -107,24 +122,24 @@ class CategoryController extends Controller
107 public function actionUpdate($id) 122 public function actionUpdate($id)
108 { 123 {
109 $category = ArticleCategory::findOne($id); 124 $category = ArticleCategory::findOne($id);
110 - $images = $category->getArticleCategoryMedia()->indexBy('type')->all();  
111 - if(!array_key_exists('full', $images)) {  
112 - $images['full'] = new ArticleCategoryMedia();  
113 - }  
114 - if(!array_key_exists('preview', $images)) {  
115 - $images['preview'] = new ArticleCategoryMedia();  
116 - }  
117 - foreach($images as $index => $image) {  
118 - $images[$index]->scenario = $index; 125 + $imagestack = $category->getArticleCategoryMedia()->all();
  126 + $images = [];
  127 + $images[0]['additional'][0] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_ADDITIONAL]);
  128 + $images[0]['additional'][0]->type = 'additional';
  129 + $images[0]['additional'][0]->language_id = 0;
  130 + foreach($imagestack as $image) {
  131 + if(in_array($image->type, ['full', 'preview'])) {
  132 + $images[$image->language_id][$image->type] = $image;
  133 + $images[$image->language_id][$image->type]->scenario = $image->type;
  134 + } else {
  135 + $images[$image->language_id][$image->type][$image->article_category_media_id] = $image;
  136 + $images[$image->language_id][$image->type][$image->article_category_media_id]->scenario = $image->type;
  137 + }
119 } 138 }
120 - $images['additional'] = array(  
121 - 0 => new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_ADDITIONAL])  
122 - );  
123 - $images['additional'] = array_merge($images['additional'], $category->getArticleCategoryMedia()->andWhere(['type' => 'additional'])->indexBy('id')->all());  
124 - foreach($images['additional'] as $index => $image) {  
125 - $images['additional'][$index]->scenario = 'additional'; 139 + foreach($images as $lang => $value) {
  140 + $images[$lang]['additional'][0] = new ArticleCategoryMedia(['scenario' => ArticleCategoryMedia::SCENARIO_ADDITIONAL]);
126 } 141 }
127 - $category_langs = $category->getArticleCategoryLangs()->where(['>=', 'lang_id', '1'])->indexBy('lang_id')->all(); 142 + $category_langs = $category->getArticleCategoryLangs()->where(['>=', 'language_id', '1'])->indexBy('language_id')->all();
128 $langs = Language::getActiveLanguages(); 143 $langs = Language::getActiveLanguages();
129 $default_lang = Language::getDefaultLang(); 144 $default_lang = Language::getDefaultLang();
130 $isValid = false; 145 $isValid = false;
@@ -132,15 +147,18 @@ class CategoryController extends Controller @@ -132,15 +147,18 @@ class CategoryController extends Controller
132 $isValid = true; 147 $isValid = true;
133 $category->load(\Yii::$app->request->post()); 148 $category->load(\Yii::$app->request->post());
134 $isValid = $category->validate(); 149 $isValid = $category->validate();
135 - foreach($images as $index => $value) {  
136 - if($index == 'additional') {  
137 - $images[$index][0]->type = $index;  
138 - $images[$index][0]->imageFile = UploadedFile::getInstances($images[$index][0], "[{$index}]imageFile");  
139 - $isValid = $images[$index][0]->validate(['imageFile']) && $isValid;  
140 - } else {  
141 - $images[$index]->type = $index;  
142 - $images[$index]->imageFile = UploadedFile::getInstance($images[$index], "[{$index}]imageFile");  
143 - $isValid = $images[$index]->validate(['imageFile']) && $isValid; 150 + $images[0]['additional'][0]->type = 'additional';
  151 + $images[0]['additional'][0]->language_id = 0;
  152 + $images[0]['additional'][0]->imageFile = UploadedFile::getInstances($images[0]['additional'][0], "[0][additional]imageFile");
  153 + $isValid = $images[0]['additional'][0]->validate(['imageFile']) && $isValid;
  154 + foreach(\Yii::$app->request->post()['ArticleCategoryMedia'] as $lang => $value) {
  155 + foreach($value as $type => $fields) {
  156 + if(!in_array($type, ['full', 'preview'])) continue;
  157 + $images[$lang][$type] = new ArticleCategoryMedia(['scenario' => $type]);
  158 + $images[$lang][$type]->language_id = $lang;
  159 + $images[$lang][$type]->type = $type;
  160 + $images[$lang][$type]->imageFile = UploadedFile::getInstance($images[$lang][$type], "[{$lang}][{$type}]imageFile");
  161 + $isValid = $images[$lang][$type]->validate(['imageFile']) && $isValid;
144 } 162 }
145 } 163 }
146 if(empty(\Yii::$app->request->post()['ArticleCategoryLang'])) { 164 if(empty(\Yii::$app->request->post()['ArticleCategoryLang'])) {
@@ -149,7 +167,7 @@ class CategoryController extends Controller @@ -149,7 +167,7 @@ class CategoryController extends Controller
149 foreach(\Yii::$app->request->post()['ArticleCategoryLang'] as $index => $category_lang) { 167 foreach(\Yii::$app->request->post()['ArticleCategoryLang'] as $index => $category_lang) {
150 if(!array_key_exists($index, $category_langs)) { 168 if(!array_key_exists($index, $category_langs)) {
151 $category_langs[$index] = new ArticleCategoryLang(); 169 $category_langs[$index] = new ArticleCategoryLang();
152 - $category_langs[$index]->category_id = $category->id; 170 + $category_langs[$index]->article_category_id = $category->article_category_id;
153 } 171 }
154 } 172 }
155 ArticleCategoryLang::loadMultiple($category_langs, \Yii::$app->request->post()); 173 ArticleCategoryLang::loadMultiple($category_langs, \Yii::$app->request->post());
@@ -158,12 +176,14 @@ class CategoryController extends Controller @@ -158,12 +176,14 @@ class CategoryController extends Controller
158 } 176 }
159 if($isValid) { 177 if($isValid) {
160 $category->save(false); 178 $category->save(false);
161 - foreach($images as $index => $image) {  
162 - if($index == 'additional') {  
163 - $images[$index][0]->upload($category->id);  
164 - } else {  
165 - if(!empty($images[$index]->imageFile)) {  
166 - $images[$index]->replace($category->id, true); 179 + foreach($images as $lang => $value) {
  180 + foreach($value as $type => $fields) {
  181 + if($type == 'additional') {
  182 + $images[$lang][$type][0]->upload($category->article_category_id);
  183 + } else {
  184 + if(!empty($images[$lang][$type]->imageFile)) {
  185 + $images[$lang][$type]->replace($category->article_category_id);
  186 + }
167 } 187 }
168 } 188 }
169 } 189 }
common/modules/blog/models/Article.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use common\models\Media;
  6 +use common\models\User;
  7 +use common\modules\blog\behaviors\Autocomplete;
  8 +use Yii;
  9 +use yii\db\Query;
  10 +
  11 +/**
  12 + * This is the model class for table "article".
  13 + *
  14 + * @property integer $article_id
  15 + * @property integer $sort
  16 + * @property string $date_add
  17 + * @property string $date_update
  18 + * @property string $code
  19 + * @property integer $user_id
  20 + * @property string $tag
  21 + * @property integer $article_pid
  22 + * @property integer $status
  23 + * @property integer $comment
  24 + * @property integer $vote
  25 + *
  26 + * @property Article $parent
  27 + * @property Article[] $articles
  28 + * @property User $user
  29 + * @property ArticleLang[] $articleLangs
  30 + * @property ArticleMedia[] $articleMedia
  31 + * @property ArticleToCategory[] $articleToCategories
  32 + * @property Media[] $media
  33 + */
  34 +class Article extends \yii\db\ActiveRecord
  35 +{
  36 + /**
  37 + * @inheritdoc
  38 + */
  39 + public static function tableName()
  40 + {
  41 + return 'article';
  42 + }
  43 +
  44 + public function behaviors()
  45 + {
  46 + return [
  47 + [
  48 + 'class' => Autocomplete::className(),
  49 + 'attributes' => [
  50 + 'translit' => ['code'],
  51 + ]
  52 + ]
  53 + ];
  54 + }
  55 + /**
  56 + * @inheritdoc
  57 + */
  58 + public function rules()
  59 + {
  60 + return [
  61 + [['sort', 'article_pid', 'status', 'comment', 'vote'], 'integer'],
  62 + [['date_add', 'date_update'], 'safe'],
  63 + [['code'], 'required'],
  64 + [['code', 'tag'], 'string']
  65 + ];
  66 + }
  67 +
  68 + /**
  69 + * @inheritdoc
  70 + */
  71 + public function attributeLabels()
  72 + {
  73 + return [
  74 + 'article_id' => Yii::t('app', 'ID'),
  75 + 'sort' => Yii::t('app', 'Sort'),
  76 + 'date_add' => Yii::t('app', 'Create At'),
  77 + 'date_update' => Yii::t('app', 'Update At'),
  78 + 'code' => Yii::t('app', 'Code'),
  79 + 'user_id' => Yii::t('app', 'Author'),
  80 + 'tag' => Yii::t('app', 'Tags'),
  81 + 'article_pid' => Yii::t('app', 'Parent ID'),
  82 + 'status' => Yii::t('app', 'Active'),
  83 + 'comment' => Yii::t('app', 'Comments'),
  84 + 'vote' => Yii::t('app', 'Voting'),
  85 + ];
  86 + }
  87 +
  88 + /**
  89 + * @return \yii\db\ActiveQuery
  90 + */
  91 + public function getParent()
  92 + {
  93 + return $this->hasOne(Article::className(), ['article_id' => 'article_pid']);
  94 + }
  95 +
  96 + /**
  97 + * @return \yii\db\ActiveQuery
  98 + */
  99 + public function getArticles()
  100 + {
  101 + return $this->hasMany(Article::className(), ['article_pid' => 'article_id']);
  102 + }
  103 +
  104 + /**
  105 + * @return \yii\db\ActiveQuery
  106 + */
  107 + public function getUser()
  108 + {
  109 + return $this->hasOne(User::className(), ['id' => 'user_id']);
  110 + }
  111 +
  112 + /**
  113 + * @return \yii\db\ActiveQuery
  114 + */
  115 + public function getArticleLangs()
  116 + {
  117 + return $this->hasMany(ArticleLang::className(), ['article_id' => 'article_id']);
  118 + }
  119 +
  120 + /**
  121 + * @return \yii\db\ActiveQuery
  122 + */
  123 + public function getArticleMedia()
  124 + {
  125 + return $this->hasMany(ArticleMedia::className(), ['article_id' => 'article_id']);
  126 + }
  127 +
  128 + public function getMedia()
  129 + {
  130 + return $this->hasMany(Media::className(), ['article_id' => 'media_id'])->via('articleMedia');
  131 + }
  132 + /**
  133 + * @return \yii\db\ActiveQuery
  134 + */
  135 + public function getArticleToCategories()
  136 + {
  137 + return $this->hasMany(ArticleToCategory::className(), ['article_id' => 'article_id']);
  138 + }
  139 +
  140 + public function getArticleCategories()
  141 + {
  142 + return $this->hasMany(ArticleCategory::className(), ['article_category_id' => 'article_category_id'])->viaTable('article_to_category', ['article_id' => 'article_category_id']);
  143 + }
  144 +
  145 + public static function findArticleDropdown($id)
  146 + {
  147 + $query = new Query();
  148 + return $query->select(['l.name', 'a.article_id'])
  149 + ->from(['article a'])
  150 + ->leftJoin(['article_lang l'], 'a.article_id = l.article_id')
  151 + ->where(['l.language_id' => 0, 'a.status' => 1])
  152 + ->andWhere(['not', ['a.article_id' => $id]])
  153 + ->indexBy('article_id')
  154 + ->column();
  155 + }
  156 +
  157 + public function getArticleCategoriesArray()
  158 + {
  159 + return $this->getArticleToCategories()->select('article_category_id')->column();
  160 + }
  161 +}
common/modules/blog/models/ArticleCategory.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use common\modules\blog\behaviors\Autocomplete;
  6 +use Yii;
  7 +use yii\behaviors\TimestampBehavior;
  8 +use yii\db\ActiveRecord;
  9 +use yii\db\Query;
  10 +
  11 +/**
  12 + * This is the model class for table "article_category".
  13 + *
  14 + * @property integer $article_category_id
  15 + * @property integer $status
  16 + * @property integer $sort
  17 + * @property string $code
  18 + * @property string $date_add
  19 + * @property string $date_update
  20 + * @property string $tag
  21 + * @property integer $artucle_category_pid
  22 + *
  23 + * @property Article[] $articles
  24 + * @property ArticleCategory $parent
  25 + * @property ArticleCategory[] $articleCategories
  26 + * @property ArticleCategoryLang[] $articleCategoryLangs
  27 + * @property ArticleCategoryMedia[] $articleCategoryMedia
  28 + */
  29 +class ArticleCategory extends ActiveRecord
  30 +{
  31 + /**
  32 + * @inheritdoc
  33 + */
  34 + public static function tableName()
  35 + {
  36 + return 'article_category';
  37 + }
  38 +
  39 + public function behaviors()
  40 + {
  41 + return [
  42 + [
  43 + 'class' => Autocomplete::className(),
  44 + 'attributes' => [
  45 + 'translit' => ['code'],
  46 + ]
  47 + ]
  48 + ];
  49 + }
  50 + /**
  51 + * @inheritdoc
  52 + */
  53 + public function rules()
  54 + {
  55 + return [
  56 + [['status', 'sort', 'article_category_pid'], 'integer'],
  57 + [['code'], 'required'],
  58 + [['code', 'tag'], 'string'],
  59 + [['date_add', 'date_update'], 'safe'],
  60 + [['status'], 'boolean'],
  61 + ];
  62 + }
  63 +
  64 + /**
  65 + * @inheritdoc
  66 + */
  67 + public function attributeLabels()
  68 + {
  69 + return [
  70 + 'article_category_id' => Yii::t('app', 'ID'),
  71 + 'status' => Yii::t('app', 'Active'),
  72 + 'sort' => Yii::t('app', 'Sort'),
  73 + 'code' => Yii::t('app', 'Code'),
  74 + 'date_add' => Yii::t('app', 'Created At'),
  75 + 'date_update' => Yii::t('app', 'Updated At'),
  76 + 'tag' => Yii::t('app', 'Tags'),
  77 + 'article_category_pid' => Yii::t('app', 'Parent ID'),
  78 + ];
  79 + }
  80 +
  81 + /**
  82 + * @return \yii\db\ActiveQuery
  83 + */
  84 + public function getArticles()
  85 + {
  86 + return $this->hasMany(Article::className(), ['article_id' => 'article_id'])->viaTable('article_to_category', ['article_category_id' => 'article_category_id']) ;
  87 + }
  88 +
  89 + /**
  90 + * @return \yii\db\ActiveQuery
  91 + */
  92 + public function getParent()
  93 + {
  94 + return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_pid']);
  95 + }
  96 +
  97 + /**
  98 + * @return \yii\db\ActiveQuery
  99 + */
  100 + public function getArticleCategories()
  101 + {
  102 + return $this->hasMany(ArticleCategory::className(), ['article_category_pid' => 'article_category_id']);
  103 + }
  104 +
  105 + /**
  106 + * @return \yii\db\ActiveQuery
  107 + */
  108 + public function getArticleCategoryLangs()
  109 + {
  110 + return $this->hasMany(ArticleCategoryLang::className(), ['article_category_id' => 'article_category_id']);
  111 + }
  112 +
  113 + /**
  114 + * @return \yii\db\ActiveQuery
  115 + */
  116 + public function getArticleCategoryMedia()
  117 + {
  118 + return $this->hasMany(ArticleCategoryMedia::className(), ['article_category_id' => 'article_category_id']);
  119 + }
  120 +
  121 + public static function findArticleCategoryDropdown($id)
  122 + {
  123 + $query = new Query();
  124 + return $query->select(['l.name', 'c.article_category_id'])
  125 + ->from(['article_category c'])
  126 + ->leftJoin(['article_category_lang l'], 'c.article_category_id = l.article_category_id')
  127 + ->where(['l.language_id' => 0, 'c.status' => 1])
  128 + ->andWhere(['not', ['c.article_category_id' => $id]])
  129 + ->indexBy('article_category_id')
  130 + ->column();
  131 + }
  132 +
  133 +}
common/modules/blog/models/ArticleCategoryLang.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use common\modules\blog\behaviors\Autocomplete;
  6 +use Yii;
  7 +
  8 +/**
  9 + * This is the model class for table "article_category_lang".
  10 + *
  11 + * @property integer $article_category_language_id
  12 + * @property integer $language_id
  13 + * @property integer $article_category_id
  14 + * @property string $text
  15 + * @property string $preview
  16 + * @property string $seo_url
  17 + * @property string $name
  18 + * @property string $meta_title
  19 + * @property string $meta_descr
  20 + * @property string $meta_keyword
  21 + * @property string $h1_tag
  22 + * @property string $tag
  23 + *
  24 + * @property ArticleCategory $category
  25 + * @property Language $lang
  26 + */
  27 +class ArticleCategoryLang extends \yii\db\ActiveRecord
  28 +{
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public static function tableName()
  33 + {
  34 + return 'article_category_lang';
  35 + }
  36 +
  37 + public function behaviors()
  38 + {
  39 + return [
  40 + [
  41 + 'class' => Autocomplete::className(),
  42 + 'attributes' => [
  43 + 'repeat' => [['preview', 'text', false, 5, true, '...']],
  44 + ]
  45 + ]
  46 + ];
  47 + }
  48 + /**
  49 + * @inheritdoc
  50 + */
  51 + public function rules()
  52 + {
  53 + return [
  54 + [['language_id', 'article_category_id'], 'integer'],
  55 + [['text', 'name'], 'required'],
  56 + [['text', 'preview', 'seo_url', 'name', 'meta_title', 'meta_descr', 'meta_keyword', 'h1_tag', 'tag'], 'string'],
  57 + ['seo_url', function($attribute, $params) {
  58 + $pattern = "/^[a-zA-Z\d_-]+$/";
  59 + if(!preg_match($pattern, $this->$attribute)) {
  60 + $this->addError($attribute, Yii::t('app', "Pattern doesn't match."));
  61 + }
  62 + }]
  63 + ];
  64 + }
  65 +
  66 + /**
  67 + * @inheritdoc
  68 + */
  69 + public function attributeLabels()
  70 + {
  71 + return [
  72 + 'article_category_language_id' => Yii::t('app', 'ID'),
  73 + 'language_id' => Yii::t('app', 'Lang ID'),
  74 + 'article_category_id' => Yii::t('app', 'Category ID'),
  75 + 'text' => Yii::t('app', 'Text'),
  76 + 'preview' => Yii::t('app', 'Preview'),
  77 + 'seo_url' => Yii::t('app', 'Seo Url'),
  78 + 'name' => Yii::t('app', 'Name'),
  79 + 'meta_title' => Yii::t('app', 'Meta Title'),
  80 + 'meta_descr' => Yii::t('app', 'Meta Descr'),
  81 + 'meta_keyword' => Yii::t('app', 'Meta Keywords'),
  82 + 'h1_tag' => Yii::t('app', 'H1 Tag'),
  83 + 'tag' => Yii::t('app', 'Tags'),
  84 + ];
  85 + }
  86 +
  87 + /**
  88 + * @return \yii\db\ActiveQuery
  89 + */
  90 + public function getCategory()
  91 + {
  92 + return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_id']);
  93 + }
  94 +
  95 + /**
  96 + * @return \yii\db\ActiveQuery
  97 + */
  98 + public function getLang()
  99 + {
  100 + return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
  101 + }
  102 +}
common/modules/blog/models/ArticleCategoryMedia.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use common\models\Media;
  6 +use Yii;
  7 +
  8 +/**
  9 + * This is the model class for table "article_category_media".
  10 + *
  11 + * @property integer $article_category_media_id
  12 + * @property integer $article_category_id
  13 + * @property integer $media_id
  14 + * @property string $media_alt
  15 + * @property string $media_title
  16 + * @property string $media_caption
  17 + * @property string $type
  18 + * @property string $language_id
  19 + *
  20 + * @property ArticleCategory $category
  21 + * @property Media $media
  22 + * @property Language $lang
  23 + */
  24 +class ArticleCategoryMedia extends \yii\db\ActiveRecord
  25 +{
  26 + const SCENARIO_FULL = 'full';
  27 + const SCENARIO_PREVIEW = 'preview';
  28 + const SCENARIO_ADDITIONAL = 'additional';
  29 + public $imageFile;
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public static function tableName()
  34 + {
  35 + return 'article_category_media';
  36 + }
  37 +
  38 + public function scenarios()
  39 + {
  40 + $scenarios = parent::scenarios();
  41 + $scenarios[self::SCENARIO_FULL] = ['article_category_media_id', 'article_category_id', 'media_id', 'type', 'media_alt', 'media_title', 'media_caption', 'imageFile'];
  42 + $scenarios[self::SCENARIO_PREVIEW] = ['article_category_media_id', 'article_category_id', 'media_id', 'type', 'media_alt', 'media_title', 'media_caption', 'imageFile'];
  43 + $scenarios[self::SCENARIO_ADDITIONAL] = ['article_category_media_id', 'article_category_id', 'media_id', 'type', 'imageFile'];
  44 + return $scenarios;
  45 + }
  46 +
  47 + /**
  48 + * @inheritdoc
  49 + */
  50 + public function rules()
  51 + {
  52 + return [
  53 + [['article_category_id', 'media_id'], 'required'],
  54 + [['article_category_id', 'media_id'], 'integer'],
  55 + [['media_alt', 'media_title', 'media_caption'], 'string'],
  56 + [['type'], 'string', 'max' => 10],
  57 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'on' => self::SCENARIO_FULL],
  58 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'on' => self::SCENARIO_PREVIEW],
  59 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'maxFiles' => 10, 'on' => self::SCENARIO_ADDITIONAL]
  60 + ];
  61 + }
  62 +
  63 + /**
  64 + * @inheritdoc
  65 + */
  66 + public function attributeLabels()
  67 + {
  68 + return [
  69 + 'article_category_media_id' => Yii::t('app', 'ID'),
  70 + 'article_category_id' => Yii::t('app', 'Category ID'),
  71 + 'media_id' => Yii::t('app', 'Media ID'),
  72 + 'media_alt' => Yii::t('app', 'Media Alt'),
  73 + 'media_title' => Yii::t('app', 'Media Title'),
  74 + 'media_caption' => Yii::t('app', 'Media Caption'),
  75 + 'type' => Yii::t('app', 'Type'),
  76 + 'imageFile' => Yii::t('app', 'Image File'),
  77 + 'language_id' => Yii::t('app', 'Language ID'),
  78 + ];
  79 + }
  80 +
  81 + /**
  82 + * @return \yii\db\ActiveQuery
  83 + */
  84 + public function getCategory()
  85 + {
  86 + return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_id']);
  87 + }
  88 +
  89 + /**
  90 + * @return \yii\db\ActiveQuery
  91 + */
  92 + public function getMedia()
  93 + {
  94 + return $this->hasOne(Media::className(), ['media_id' => 'media_id']);
  95 + }
  96 +
  97 + public function upload($category_id)
  98 + {
  99 + $this->article_category_id = $category_id;
  100 + if(is_array($this->imageFile)) {
  101 + $ok = true;
  102 + foreach($this->imageFile as $image) {
  103 + $media_category = clone $this;
  104 + $media = new Media();
  105 + $media->imageFile = $image;
  106 + $media->upload();
  107 + $media_category->media_id = $media->media_id;
  108 + $ok = $media_category->save() && $ok;
  109 + unset($media_category);
  110 + }
  111 + return $ok;
  112 + } elseif(!empty($this->imageFile)) {
  113 + $media = new Media();
  114 + $media->imageFile = $this->imageFile;
  115 + $media->upload();
  116 + $this->media_id = $media->media_id;
  117 + return $this->save();
  118 + }
  119 + }
  120 +
  121 + public function replace($category_id, $removeMedia = false)
  122 + {
  123 + $this->article_category_id = $category_id;
  124 + if($removeMedia) {
  125 + $category_media = ArticleCategoryMedia::find()->select('media_id')->where(['article_category_id' => $this->article_category_id, 'type' => $this->type])->column();
  126 + $media = array();
  127 + foreach($category_media as $media_id) {
  128 + $media[] = Media::findOne(['media_id' => $media_id]);
  129 + }
  130 + $media = array_unique($media);
  131 + foreach($media as $one_media) {
  132 + if($one_media instanceof Media) {
  133 + $one_media->delete();
  134 + }
  135 + }
  136 + unset($media);
  137 + unset($category_media);
  138 + }
  139 + if(is_array($this->imageFile)) {
  140 + $ok = true;
  141 + foreach($this->imageFile as $image) {
  142 + $media_category = clone $this;
  143 + $media = new Media();
  144 + $media->imageFile = $image;
  145 + $media->upload();
  146 + $media_category->media_id = $media->media_id;
  147 + $ok = $media_category->save() && $ok;
  148 + unset($media_category);
  149 + }
  150 + return $ok;
  151 + } elseif(!empty($this->imageFile)) {
  152 + ArticleCategoryMedia::deleteAll(['category_id' => $this->article_category_id, 'type' => $this->type]);
  153 + $media = new Media();
  154 + $media->imageFile = $this->imageFile;
  155 + $media->upload();
  156 + $this->media_id = $media->media_id;
  157 + $this->setIsNewRecord(true);
  158 + return $this->save();
  159 + }
  160 + }
  161 +
  162 +}
common/modules/blog/models/ArticleLang.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use Yii;
  6 +use common\models\Language;
  7 +
  8 +/**
  9 + * This is the model class for table "article_lang".
  10 + *
  11 + * @property integer $article_language_id
  12 + * @property integer $language_id
  13 + * @property integer $article_id
  14 + * @property string $text
  15 + * @property string $seo_url
  16 + * @property string $name
  17 + * @property string $preview
  18 + * @property string $meta_title
  19 + * @property string $meta_descr
  20 + * @property string $meta_keyword
  21 + * @property string $h1_tag
  22 + * @property string $tag
  23 + *
  24 + * @property Article $article
  25 + * @property Language $lang
  26 + */
  27 +class ArticleLang extends \yii\db\ActiveRecord
  28 +{
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public static function tableName()
  33 + {
  34 + return 'article_lang';
  35 + }
  36 +
  37 + /**
  38 + * @inheritdoc
  39 + */
  40 + public function rules()
  41 + {
  42 + return [
  43 + [['language_id', 'text', 'name'], 'required'],
  44 + [['language_id', 'article_id'], 'integer'],
  45 + [['text', 'seo_url', 'name', 'preview', 'meta_title', 'meta_descr', 'meta_keyword', 'h1_tag', 'tag'], 'string']
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * @inheritdoc
  51 + */
  52 + public function attributeLabels()
  53 + {
  54 + return [
  55 + 'article_language_id' => Yii::t('app', 'ID'),
  56 + 'language_id' => Yii::t('app', 'Lang ID'),
  57 + 'article_id' => Yii::t('app', 'Article ID'),
  58 + 'text' => Yii::t('app', 'Text'),
  59 + 'seo_url' => Yii::t('app', 'Seo Url'),
  60 + 'name' => Yii::t('app', 'Name'),
  61 + 'preview' => Yii::t('app', 'Preview'),
  62 + 'meta_title' => Yii::t('app', 'Meta Title'),
  63 + 'meta_descr' => Yii::t('app', 'Meta Descr'),
  64 + 'meta_keyword' => Yii::t('app', 'Meta Keywords'),
  65 + 'h1_tag' => Yii::t('app', 'H1 Tag'),
  66 + 'tag' => Yii::t('app', 'Tags'),
  67 + ];
  68 + }
  69 +
  70 + /**
  71 + * @return \yii\db\ActiveQuery
  72 + */
  73 + public function getArticle()
  74 + {
  75 + return $this->hasOne(Article::className(), ['article_id' => 'article_id']);
  76 + }
  77 +
  78 + /**
  79 + * @return \yii\db\ActiveQuery
  80 + */
  81 + public function getLang()
  82 + {
  83 + return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
  84 + }
  85 +}
common/modules/blog/models/ArticleMedia.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use common\models\Media;
  6 +use Yii;
  7 +use yii\web\UploadedFile;
  8 +
  9 +/**
  10 + * This is the model class for table "article_media".
  11 + *
  12 + * @property integer $article_media_id
  13 + * @property integer $article_id
  14 + * @property integer $media_id
  15 + * @property string $type
  16 + * @property string $media_alt
  17 + * @property string $media_title
  18 + * @property string $media_caption
  19 + * @property integer $language_id
  20 + *
  21 + * @property Article $article
  22 + * @property Media $media
  23 + */
  24 +class ArticleMedia extends \yii\db\ActiveRecord
  25 +{
  26 + const SCENARIO_FULL = 'full';
  27 + const SCENARIO_PREVIEW = 'preview';
  28 + const SCENARIO_ADDITIONAL = 'additional';
  29 + public $imageFile;
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public static function tableName()
  34 + {
  35 + return 'article_media';
  36 + }
  37 +
  38 + public function scenarios()
  39 + {
  40 + $scenarios = parent::scenarios();
  41 + $scenarios[self::SCENARIO_FULL] = ['article_media_id', 'article_id', 'media_id', 'type', 'media_alt', 'media_title', 'media_caption', 'imageFile', 'language_id'];
  42 + $scenarios[self::SCENARIO_PREVIEW] = ['article_media_id', 'article_id', 'media_id', 'type', 'media_alt', 'media_title', 'media_caption', 'imageFile', 'language_id'];
  43 + $scenarios[self::SCENARIO_ADDITIONAL] = ['article_media_id', 'article_id', 'media_id', 'type', 'imageFile', 'language_id'];
  44 + return $scenarios;
  45 + }
  46 +
  47 + /**
  48 + * @inheritdoc
  49 + */
  50 + public function rules()
  51 + {
  52 + return [
  53 + [['article_id', 'media_id'], 'required'],
  54 + [['article_id', 'media_id', 'language_id'], 'integer'],
  55 + [['media_alt', 'media_title', 'media_caption'], 'string'],
  56 + [['type'], 'string', 'max' => 10],
  57 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'on' => self::SCENARIO_FULL],
  58 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'on' => self::SCENARIO_PREVIEW],
  59 + [['imageFile'], 'file', 'extensions' => 'png, gif, jpg, jpeg', 'skipOnEmpty' => true, 'maxFiles' => 10, 'on' => self::SCENARIO_ADDITIONAL]
  60 + ];
  61 + }
  62 +
  63 + /**
  64 + * @inheritdoc
  65 + */
  66 + public function attributeLabels()
  67 + {
  68 + return [
  69 + 'article_media_id' => Yii::t('app', 'ID'),
  70 + 'article_id' => Yii::t('app', 'Article ID'),
  71 + 'media_id' => Yii::t('app', 'Media ID'),
  72 + 'type' => Yii::t('app', 'Type'),
  73 + 'media_alt' => Yii::t('app', 'Media Alt'),
  74 + 'media_title' => Yii::t('app', 'Media Title'),
  75 + 'media_caption' => Yii::t('app', 'Media Caption'),
  76 + 'imageFile' => Yii::t('app', 'Image File'),
  77 + ];
  78 + }
  79 +
  80 + /**
  81 + * @return \yii\db\ActiveQuery
  82 + */
  83 + public function getArticle()
  84 + {
  85 + return $this->hasOne(Article::className(), ['article_id' => 'article_id']);
  86 + }
  87 +
  88 + /**
  89 + * @return \yii\db\ActiveQuery
  90 + */
  91 + public function getMedia()
  92 + {
  93 + return $this->hasOne(Media::className(), ['media_id' => 'media_id']);
  94 + }
  95 +
  96 + public function upload($article_id)
  97 + {
  98 + $this->article_id = $article_id;
  99 + if(is_array($this->imageFile)) {
  100 + $ok = true;
  101 + foreach($this->imageFile as $image) {
  102 + $media_article = clone $this;
  103 + $media = new Media();
  104 + $media->imageFile = $image;
  105 + $media->upload();
  106 + $media_article->media_id = $media->media_id;
  107 + $ok = $media_article->save() && $ok;
  108 + unset($media_article);
  109 + }
  110 + return $ok;
  111 + } elseif(!empty($this->imageFile)) {
  112 + $media = new Media();
  113 + $media->imageFile = $this->imageFile;
  114 + $media->upload();
  115 + $this->media_id = $media->media_id;
  116 + return $this->save();
  117 + }
  118 + }
  119 +
  120 + public function replace($article_id, $removeMedia = false)
  121 + {
  122 + $this->article_id = $article_id;
  123 + if($removeMedia && !$this->getIsNewRecord()) {
  124 + $article_media = ArticleMedia::find()->select('media_id')->where(['article_id' => $this->article_id, 'type' => $this->type, 'language_id' => $this->language_id])->column();
  125 + $media = array();
  126 + foreach($article_media as $media_id) {
  127 + $media[] = Media::findOne(['media_id' => $media_id]);
  128 + }
  129 + $media = array_unique($media);
  130 + foreach($media as $one_media) {
  131 + if($one_media instanceof Media) {
  132 + $one_media->delete();
  133 + }
  134 + }
  135 + unset($media);
  136 + unset($article_media);
  137 + }
  138 + if(is_array($this->imageFile)) {
  139 + $ok = true;
  140 + foreach($this->imageFile as $image) {
  141 + $media_article = clone $this;
  142 + $media = new Media();
  143 + $media->imageFile = $image;
  144 + $media->upload();
  145 + $media_article->media_id = $media->media_id;
  146 + $ok = $media_article->save() && $ok;
  147 + unset($media_article);
  148 + }
  149 + return $ok;
  150 + } elseif(!empty($this->imageFile)) {
  151 + ArticleMedia::deleteAll(['article_id' => $this->article_id, 'type' => $this->type, 'language_id' => $this->language_id]);
  152 + $media = new Media();
  153 + $media->imageFile = $this->imageFile;
  154 + $media->upload();
  155 + $this->media_id = $media->media_id;
  156 + $this->setIsNewRecord(true);
  157 + return $this->save();
  158 + }
  159 + }
  160 +
  161 +}
common/modules/blog/models/ArticleToCategory.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\modules\blog\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "article_to_category".
  9 + *
  10 + * @property integer $article_id
  11 + * @property integer $article_category_id
  12 + *
  13 + * @property Article $article
  14 + * @property ArticleCategory $category
  15 + */
  16 +class ArticleToCategory extends \yii\db\ActiveRecord
  17 +{
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public static function tableName()
  22 + {
  23 + return 'article_to_category';
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function rules()
  30 + {
  31 + return [
  32 + [['article_id', 'article_category_id'], 'integer']
  33 + ];
  34 + }
  35 +
  36 + /**
  37 + * @inheritdoc
  38 + */
  39 + public function attributeLabels()
  40 + {
  41 + return [
  42 + 'article_id' => Yii::t('app', 'Article ID'),
  43 + 'article_category_id' => Yii::t('app', 'Category ID'),
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * @return \yii\db\ActiveQuery
  49 + */
  50 + public function getArticle()
  51 + {
  52 + return $this->hasOne(Article::className(), ['article_id' => 'article_id']);
  53 + }
  54 +
  55 + /**
  56 + * @return \yii\db\ActiveQuery
  57 + */
  58 + public function getCategory()
  59 + {
  60 + return $this->hasOne(ArticleCategory::className(), ['article_category_id' => 'article_category_id']);
  61 + }
  62 +}
common/modules/blog/views/ajax/_article_form.php
@@ -3,31 +3,36 @@ @@ -3,31 +3,36 @@
3 use yii\bootstrap\ActiveField; 3 use yii\bootstrap\ActiveField;
4 use mihaildev\ckeditor\CKEditor; 4 use mihaildev\ckeditor\CKEditor;
5 5
6 -$form = \yii\bootstrap\ActiveForm::begin(); 6 +if(empty($form)) {
  7 + $new_form = true;
  8 + $form = \yii\bootstrap\ActiveForm::begin();
  9 +}
7 ?> 10 ?>
8 -<div role="" class="tab-pane active ajax-loaded" id="lang-<?=$model->language_id?>"> 11 +<div role="" class="tab-pane active ajax-loaded" id="<?=$widget_id?>-<?=$model->language_id?>">
9 12
10 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]lang_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?> 13 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]language_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?>
11 14
12 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]text", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?> 15 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]text", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?>
13 16
14 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]preview", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?> 17 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]preview", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?>
15 18
16 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]seo_url"]))->textInput() ?> 19 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]seo_url"]))->textInput() ?>
17 20
18 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]name"]))->textInput() ?> 21 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]name"]))->textInput() ?>
19 22
20 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]meta_title"]))->textInput() ?> 23 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]meta_title"]))->textInput() ?>
21 24
22 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]meta_descr"]))->textarea() ?> 25 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]meta_descr"]))->textarea() ?>
23 26
24 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]meta_keywords"]))->textInput() ?> 27 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]meta_keyword"]))->textInput() ?>
25 28
26 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]h1_tag"]))->textInput() ?> 29 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]h1_tag"]))->textInput() ?>
27 30
28 - <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id]tags"]))->textInput() ?> 31 + <?= (new ActiveField(['model' => $model, 'attribute' => "[$model->language_id]tag"]))->textInput() ?>
29 32
30 </div> 33 </div>
31 <?php 34 <?php
32 -$form->end(); 35 + if($new_form) {
  36 + $form->end();
  37 + }
33 ?> 38 ?>
common/modules/blog/views/ajax/_article_media_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\bootstrap\ActiveField;
  4 +use mihaildev\ckeditor\CKEditor;
  5 +
  6 +$form = \yii\bootstrap\ActiveForm::begin();
  7 +?>
  8 +<div role="" class="tab-pane active ajax-loaded" id="<?=$widget_id?>-<?=$model->language_id?>">
  9 +
  10 + <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id][$type]language_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?>
  11 +
  12 + <?= (new ActiveField(['model' => $article_lang, 'attribute' => "[$model->language_id][$type]imageFile"]))->fileInput(['class' => 'image_inputs_field']) ?>
  13 +
  14 +</div>
  15 +<?php
  16 +$form->end();
  17 +?>
common/modules/blog/views/ajax/_category_form.php
@@ -5,9 +5,9 @@ use mihaildev\ckeditor\CKEditor; @@ -5,9 +5,9 @@ use mihaildev\ckeditor\CKEditor;
5 5
6 $form = \yii\bootstrap\ActiveForm::begin(); 6 $form = \yii\bootstrap\ActiveForm::begin();
7 ?> 7 ?>
8 -<div role="" class="tab-pane active ajax-loaded" id="lang-<?=$model->language_id?>"> 8 +<div role="" class="tab-pane active ajax-loaded" id="<?=$widget_id?>-<?=$model->language_id?>">
9 9
10 - <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]lang_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?> 10 + <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]language_id"]))->label(false)->hiddenInput(['value' => $model->language_id]) ?>
11 11
12 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]text", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?> 12 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]text", 'form' => $form]))->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ]]); ?>
13 13
@@ -21,11 +21,11 @@ $form = \yii\bootstrap\ActiveForm::begin(); @@ -21,11 +21,11 @@ $form = \yii\bootstrap\ActiveForm::begin();
21 21
22 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]meta_descr"]))->textarea() ?> 22 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]meta_descr"]))->textarea() ?>
23 23
24 - <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]meta_keywords"]))->textInput() ?> 24 + <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]meta_keyword"]))->textInput() ?>
25 25
26 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]h1_tag"]))->textInput() ?> 26 <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]h1_tag"]))->textInput() ?>
27 27
28 - <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]tags"]))->textInput() ?> 28 + <?= (new ActiveField(['model' => $category_lang, 'attribute' => "[$model->language_id]tag"]))->textInput() ?>
29 29
30 </div> 30 </div>
31 <?php 31 <?php
common/modules/blog/views/article/_form.php
1 <?php 1 <?php
2 use common\modules\blog\models\ArticleCategory; 2 use common\modules\blog\models\ArticleCategory;
3 -use yii\bootstrap\ActiveForm; 3 +use common\modules\blog\models\ArticleMedia;
  4 +use common\widgets\Multilang;
  5 + use common\widgets\Multilanguage;
  6 + use yii\bootstrap\ActiveForm;
4 use common\modules\blog\models\Article; 7 use common\modules\blog\models\Article;
5 use yii\bootstrap\Html; 8 use yii\bootstrap\Html;
6 use mihaildev\ckeditor\CKEditor; 9 use mihaildev\ckeditor\CKEditor;
@@ -17,100 +20,117 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;); @@ -17,100 +20,117 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;);
17 20
18 <?= $form->field($article, 'code')->hint(Yii::t('app', 'Insensitive latin non-space'))->textInput() ?> 21 <?= $form->field($article, 'code')->hint(Yii::t('app', 'Insensitive latin non-space'))->textInput() ?>
19 22
20 - <?= $form->field($article, 'tags')->hint(Yii::t('app', 'Comma-separated'))->textInput() ?> 23 + <?= $form->field($article, 'tag')->hint(Yii::t('app', 'Comma-separated'))->textInput() ?>
21 24
22 <?= $form->field($article, 'sort')->input('number') ?> 25 <?= $form->field($article, 'sort')->input('number') ?>
23 26
24 - <?= $form->field($article, 'parent_id')  
25 - ->dropDownList(Article::findArticleDropdown($article->id), ['prompt' => Yii::t('app', 'Select parent')]) ?> 27 + <?= $form->field($article, 'article_pid')
  28 + ->dropDownList(Article::findArticleDropdown($article->article_id), ['prompt' => Yii::t('app', 'Select parent')]) ?>
26 29
27 <?= $form->field($article, 'articleCategoriesArray') 30 <?= $form->field($article, 'articleCategoriesArray')
28 ->dropDownList(ArticleCategory::findArticleCategoryDropdown(NULL), ['multiple' => 'multiple'])->label(\Yii::t('app', 'Article Categories Array')); ?> 31 ->dropDownList(ArticleCategory::findArticleCategoryDropdown(NULL), ['multiple' => 'multiple'])->label(\Yii::t('app', 'Article Categories Array')); ?>
29 32
30 - <?= $form->field($article, 'active')->checkbox() ?> 33 + <?= $form->field($article, 'status')->checkbox() ?>
31 34
32 <ul class="nav nav-tabs" id="image-tabs" role="tablist"> 35 <ul class="nav nav-tabs" id="image-tabs" role="tablist">
33 - <?php  
34 - $first = 1;  
35 - foreach($images as $index => $image) {  
36 - ?>  
37 - <li role="image_inputs" class="<?php if($first) { echo 'active'; }?>" data-type="<?=$index?>"><a href="#image-<?=$index?>" aria-controls="image-<?=$index?>" role="tab" data-toggle="tab"><span><?= \Yii::t('app', $index)?></span></a></li>  
38 - <?php  
39 - $first = 0;  
40 - }  
41 - ?> 36 + <li role="image_inputs" class="active" data-type="full"><a href="#image-full" aria-controls="image-full" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'full')?></span></a></li>
  37 + <li role="image_inputs" class="" data-type="preview"><a href="#image-preview" aria-controls="image-preview" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'preview')?></span></a></li>
  38 + <li role="image_inputs" class="" data-type="additional"><a href="#image-additional" aria-controls="image-additional" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'additional')?></span></a></li>
42 </ul> 39 </ul>
43 <div class="tab-content image-tab-content"> 40 <div class="tab-content image-tab-content">
44 - <?php  
45 - $first = 1;  
46 - foreach($images as $index => $image) { 41 + <div role="" class="tab-pane active main-tab" id="image-full">
  42 + <?php
  43 + $imagelang = Multilang::begin([
  44 + 'ajaxpath' => Url::to(['/blog/ajax/article-media-form?type=full']),
  45 + 'form' => $form,
  46 + 'data_langs' => $article->getIsNewRecord()?$images:ArticleMedia::find()->where(['article_id' => $article->article_id, 'type' => 'full'])->indexBy('language_id')->all()
  47 + ]);
  48 + $first = 1;
  49 + foreach($images as $lang => $value) {
  50 + if(!array_key_exists('full', $value)) continue;
  51 + ?>
  52 + <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="<?=$imagelang->id?>-<?=$lang?>">
  53 + <?php
  54 + echo $form->field($images[$lang]['full'], "[{$lang}][full]language_id")->label(false)->hiddenInput(['value' => $lang]);
  55 + echo $form->field($images[$lang]['full'], "[{$lang}][full]imageFile")->fileInput(['class' => 'image_inputs_field']);
  56 + if(!empty($images[$lang]['full']->article_media_id)) {
  57 + echo "<img src='/images/upload/{$images[$lang]['full']->media->hash}/original.{$images[$lang]['full']->media->extension}' width='100' class='image_inputs_prev'>";
  58 + }
  59 + ?>
  60 + </div>
  61 + <?php
  62 + $first = 0;
  63 + }
  64 + $imagelang->end();
47 ?> 65 ?>
48 - <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="image-<?=$index?>">  
49 - <?php if($index == 'additional') {  
50 - echo $form->field(is_array($image)?$images[$index][0]:$images[$index], "[{$index}]imageFile[]")->fileInput(['multiple' => 'multiple', 'class' => 'image_inputs_field']);  
51 - if(is_array($image) && count($image) > 1) {  
52 - foreach($image as $oneindex => $oneimage) {  
53 - if($oneindex) {  
54 - ?>  
55 - <div class="additional_image_container">  
56 - <img src='/images/upload/<?= $oneimage->media->hash ?>/original.<?= $oneimage->media->extension ?>' width='100'>  
57 - <a  
58 - href="<?= Url::to(['ajax/remove-image']) ?>"  
59 - class="remove_image glyphicon glyphicon-remove-circle"  
60 - data-params='<?= Json::encode(['article_media_id' => $oneimage->id, 'remove_media' => true]) ?>',  
61 - ></a>  
62 - </div>  
63 - <?php  
64 - }  
65 - } 66 + </div>
  67 + <div role="" class="tab-pane" id="image-preview">
  68 + <?php
  69 + $imagelang = Multilang::begin([
  70 + 'ajaxpath' => Url::to(['/blog/ajax/article-media-form?type=preview']),
  71 + 'form' => $form,
  72 + 'data_langs' => $article->getIsNewRecord()?$images:ArticleMedia::find()->where(['article_id' => $article->article_id, 'type' => 'preview'])->indexBy('language_id')->all()
  73 + ]);
  74 + $first = 1;
  75 + foreach($images as $lang => $value) {
  76 + if(!array_key_exists('preview', $value)) continue;
  77 + ?>
  78 + <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="<?=$imagelang->id?>-<?=$lang?>">
  79 + <?php
  80 + echo $form->field($images[$lang]['preview'], "[{$lang}][preview]language_id")->label(false)->hiddenInput(['value' => $lang]);
  81 + echo $form->field($images[$lang]['preview'], "[{$lang}][preview]imageFile")->fileInput(['class' => 'image_inputs_field']);
  82 + if(!empty($images[$lang]['preview']->article_media_id)) {
  83 + echo "<img src='/images/upload/{$images[$lang]['preview']->media->hash}/original.{$images[$lang]['preview']->media->extension}' width='100' class='image_inputs_prev'>";
66 } 84 }
67 - } else {  
68 - echo $form->field($images[$index], "[{$index}]imageFile")->fileInput(['class' => 'image_inputs_field']);  
69 - if(!empty($image->id)) {  
70 - echo "<img src='/images/upload/{$image->media->hash}/original.{$image->media->extension}' width='100' class='image_inputs_prev'>"; 85 + ?>
  86 + </div>
  87 + <?php
  88 + $first = 0;
  89 + }
  90 + $imagelang->end();
  91 + ?>
  92 + </div>
  93 + <div role="" class="tab-pane" id="image-additional">
  94 + <?php
  95 + echo $form->field(is_array($images[0]['additional'])?$images[0]['additional'][0]:$images[0]['additional'], "[0][additional]imageFile[]")->fileInput(['multiple' => 'multiple', 'class' => 'image_inputs_field']);
  96 + if(is_array($images[0]['additional']) && count($images[0]['additional']) > 1) {
  97 + foreach($images[0]['additional'] as $onefield => $oneimage) {
  98 + if($onefield) {
  99 + ?>
  100 + <div class="additional_image_container">
  101 + <img src='/images/upload/<?= $oneimage->media->hash ?>/original.<?= $oneimage->media->extension ?>' width='100'>
  102 + <a
  103 + href="<?= Url::to(['ajax/remove-image']) ?>"
  104 + class="remove_image glyphicon glyphicon-remove-circle"
  105 + data-params='<?= Json::encode(['article_media_id' => $oneimage->article_media_id, 'remove_media' => true]) ?>',
  106 + ></a>
  107 + </div>
  108 + <?php
71 } 109 }
72 } 110 }
73 - ?>  
74 - </div>  
75 - <?php  
76 - $first = 0;  
77 - }  
78 - ?> 111 + }
  112 + ?>
  113 + </div>
79 </div> 114 </div>
80 115
81 <hr> 116 <hr>
82 117
83 - <div class="dropdown pull-right">  
84 - <button class="btn btn-default dropdown-toggle" type="button" id="dropdownLang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">  
85 - <?= Yii::t('app', 'Add language') ?>  
86 - <span class="caret"></span>  
87 - </button>  
88 - <ul class="dropdown-menu f32" id="lang-dropdown" aria-labelledby="dropdownMenu1">  
89 - <?php foreach($langs as $index => $lang) {  
90 - if(in_array($index, array_keys($article_langs))) continue;  
91 - ?>  
92 - <li><a href="#lang-tabs" data-lang="<?=$lang->language_id?>"><span class="flag <?=$lang->country_code?>"></span></a></li>  
93 - <?php } ?>  
94 - </ul>  
95 - </div>  
96 - <ul class="nav nav-tabs f32" id="lang-tabs" role="tablist">  
97 - <?php  
98 - $first = 1;  
99 - foreach($article_langs as $index => $article_lang) {  
100 - ?>  
101 - <li role="lang_inputs" class="<?php if($first) { echo 'active'; }?>" data-lang="<?=$index?>"><a href="#lang-<?=$index?>" aria-controls="lang-<?=$index?>" role="tab" data-toggle="tab"><span class="flag <?=$langs[$index]->country_code?>"></span></a></li>  
102 - <?php  
103 - $first = 0;  
104 - }  
105 - ?>  
106 - </ul>  
107 - <div class="tab-content lang-tab-content"> 118 + <?php
  119 + echo Multilanguage::widget([
  120 + 'data' => $article_langs,
  121 + 'form' => $form,
  122 + 'ajaxView' => '@common/modules/blog/views/ajax/_article_form',
  123 + ]);
  124 + /*
  125 + $multilang = Multilang::begin(['ajaxpath' => Url::to(['/blog/ajax/article-form']), 'form' => $form, 'data_langs' => $article_langs]);
  126 + ?>
108 <?php 127 <?php
109 $first = 1; 128 $first = 1;
110 foreach($article_langs as $index => $article_lang) { 129 foreach($article_langs as $index => $article_lang) {
111 ?> 130 ?>
112 - <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="lang-<?=$index?>">  
113 - <?= $form->field($article_langs[$index], "[$index]lang_id")->label(false)->hiddenInput(['value' => $index]) ?> 131 + <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="<?=$multilang->id?>-<?=$index?>">
  132 +
  133 + <?= $form->field($article_langs[$index], "[$index]language_id")->label(false)->hiddenInput(['value' => $index]) ?>
114 134
115 <?= $form->field($article_langs[$index], "[$index]text")->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> 135 <?= $form->field($article_langs[$index], "[$index]text")->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?>
116 136
@@ -135,7 +155,10 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;); @@ -135,7 +155,10 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;);
135 $first = 0; 155 $first = 0;
136 } 156 }
137 ?> 157 ?>
138 - </div> 158 + <?php
  159 + $multilang->end();
  160 + */
  161 + ?>
139 162
140 <div class="form-group"> 163 <div class="form-group">
141 <?= Html::submitButton($article->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $article->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 164 <?= Html::submitButton($article->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $article->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
common/modules/blog/views/article/index.php
@@ -8,12 +8,12 @@ use common\models\Language; @@ -8,12 +8,12 @@ use common\models\Language;
8 echo GridView::widget([ 8 echo GridView::widget([
9 'dataProvider' => $dataProvider, 9 'dataProvider' => $dataProvider,
10 'columns' => [ 10 'columns' => [
11 - 'id', 11 + 'article_id',
12 'code', 12 'code',
13 - 'create_at', 13 + 'date_add',
14 [ 14 [
15 'value' => function($data) { 15 'value' => function($data) {
16 - return $data->author0->firstname.' '.$data->author0->lastname; 16 + return $data->user->firstname.' '.$data->user->lastname;
17 }, 17 },
18 'header' => Yii::t('app', 'Author') 18 'header' => Yii::t('app', 'Author')
19 ], 19 ],
@@ -21,7 +21,7 @@ echo GridView::widget([ @@ -21,7 +21,7 @@ echo GridView::widget([
21 'class' => Column::className(), 21 'class' => Column::className(),
22 'header' => Yii::t('app', 'Name'), 22 'header' => Yii::t('app', 'Name'),
23 'content' => function($model, $key, $index, $column) { 23 'content' => function($model, $key, $index, $column) {
24 - return $model->getArticleLangs()->where(['lang_id' => Language::getDefaultLang()->language_id])->one()->name; 24 + return $model->getArticleLangs()->where(['language_id' => Language::getDefaultLang()->language_id])->one()->name;
25 } 25 }
26 ], 26 ],
27 [ 27 [
common/modules/blog/views/category/_form.php
1 <?php 1 <?php
  2 +use common\modules\blog\models\ArticleCategoryMedia;
  3 +use common\widgets\Multilang;
2 use yii\bootstrap\ActiveForm; 4 use yii\bootstrap\ActiveForm;
3 use common\modules\blog\models\ArticleCategory; 5 use common\modules\blog\models\ArticleCategory;
4 use yii\bootstrap\Html; 6 use yii\bootstrap\Html;
@@ -15,97 +17,107 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;); @@ -15,97 +17,107 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;);
15 17
16 <?= $form->field($category, 'code')->hint(Yii::t('app', 'Insensitive latin non-space'))->textInput() ?> 18 <?= $form->field($category, 'code')->hint(Yii::t('app', 'Insensitive latin non-space'))->textInput() ?>
17 19
18 - <?= $form->field($category, 'tags')->hint(Yii::t('app', 'Comma-separated'))->textInput() ?> 20 + <?= $form->field($category, 'tag')->hint(Yii::t('app', 'Comma-separated'))->textInput() ?>
19 21
20 <?= $form->field($category, 'sort')->input('number') ?> 22 <?= $form->field($category, 'sort')->input('number') ?>
21 23
22 - <?= $form->field($category, 'parent_id')  
23 - ->dropDownList(ArticleCategory::findArticleCategoryDropdown($category->id), ['prompt' => Yii::t('app', 'Select parent')]) ?> 24 + <?= $form->field($category, 'article_category_pid')
  25 + ->dropDownList(ArticleCategory::findArticleCategoryDropdown($category->article_category_id), ['prompt' => Yii::t('app', 'Select parent')]) ?>
24 26
25 - <?= $form->field($category, 'active')->checkbox() ?> 27 + <?= $form->field($category, 'status')->checkbox() ?>
26 28
27 <ul class="nav nav-tabs" id="image-tabs" role="tablist"> 29 <ul class="nav nav-tabs" id="image-tabs" role="tablist">
28 - <?php  
29 - $first = 1;  
30 - foreach($images as $index => $image) {  
31 - ?>  
32 - <li role="image_inputs" class="<?php if($first) { echo 'active'; }?>" data-type="<?=$index?>"><a href="#image-<?=$index?>" aria-controls="image-<?=$index?>" role="tab" data-toggle="tab"><span><?= \Yii::t('app', $index)?></span></a></li>  
33 - <?php  
34 - $first = 0;  
35 - }  
36 - ?> 30 + <li role="image_inputs" class="active" data-type="full"><a href="#image-full" aria-controls="image-full" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'full')?></span></a></li>
  31 + <li role="image_inputs" class="" data-type="preview"><a href="#image-preview" aria-controls="image-preview" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'preview')?></span></a></li>
  32 + <li role="image_inputs" class="" data-type="additional"><a href="#image-additional" aria-controls="image-additional" role="tab" data-toggle="tab"><span><?= \Yii::t('app', 'additional')?></span></a></li>
37 </ul> 33 </ul>
38 <div class="tab-content image-tab-content"> 34 <div class="tab-content image-tab-content">
39 - <?php  
40 - $first = 1;  
41 - foreach($images as $index => $image) { 35 + <div role="" class="tab-pane active main-tab" id="image-full">
  36 + <?php
  37 + $imagelang = Multilang::begin([
  38 + 'ajaxpath' => Url::to(['/blog/ajax/article-category-media-form?type=full']),
  39 + 'form' => $form,
  40 + 'data_langs' => $category->getIsNewRecord()?$images:ArticleCategoryMedia::find()->where(['article_category_id' => $category->article_category_id, 'type' => 'full'])->indexBy('language_id')->all()
  41 + ]);
  42 + $first = 1;
  43 + foreach($images as $lang => $value) {
  44 + if(!array_key_exists('full', $value)) continue;
  45 + ?>
  46 + <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="<?=$imagelang->id?>-<?=$lang?>">
  47 + <?php
  48 + echo $form->field($images[$lang]['full'], "[{$lang}][full]language_id")->label(false)->hiddenInput(['value' => $lang]);
  49 + echo $form->field($images[$lang]['full'], "[{$lang}][full]imageFile")->fileInput(['class' => 'image_inputs_field']);
  50 + if(!empty($images[$lang]['full']->article_category_media_id)) {
  51 + echo "<img src='/images/upload/{$images[$lang]['full']->media->hash}/original.{$images[$lang]['full']->media->extension}' width='100' class='image_inputs_prev'>";
  52 + }
  53 + ?>
  54 + </div>
  55 + <?php
  56 + $first = 0;
  57 + }
  58 + $imagelang->end();
42 ?> 59 ?>
43 - <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="image-<?=$index?>">  
44 - <?php if($index == 'additional') {  
45 - echo $form->field(is_array($image)?$images[$index][0]:$images[$index], "[{$index}]imageFile[]")->fileInput(['multiple' => 'multiple', 'class' => 'image_inputs_field']);  
46 - if(is_array($image) && count($image) > 1) {  
47 - foreach($image as $oneindex => $oneimage) {  
48 - if($oneindex) {  
49 - ?>  
50 - <div class="additional_image_container">  
51 - <img src='/images/upload/<?= $oneimage->media->hash ?>/original.<?= $oneimage->media->extension ?>' width='100'>  
52 - <a  
53 - href="<?= Url::to(['ajax/remove-image-category']) ?>"  
54 - class="remove_image glyphicon glyphicon-remove-circle"  
55 - data-params='<?= Json::encode(['category_media_id' => $oneimage->id, 'remove_media' => true]) ?>',  
56 - ></a>  
57 - </div>  
58 - <?php  
59 - }  
60 - } 60 + </div>
  61 + <div role="" class="tab-pane" id="image-preview">
  62 + <?php
  63 + $imagelang = Multilang::begin([
  64 + 'ajaxpath' => Url::to(['/blog/ajax/article-category-media-form?type=preview']),
  65 + 'form' => $form,
  66 + 'data_langs' => $category->getIsNewRecord()?$images:ArticleCategoryMedia::find()->where(['article_category_id' => $category->article_category_id, 'type' => 'preview'])->indexBy('language_id')->all()
  67 + ]);
  68 + $first = 1;
  69 + foreach($images as $lang => $value) {
  70 + if(!array_key_exists('preview', $value)) continue;
  71 + ?>
  72 + <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="<?=$imagelang->id?>-<?=$lang?>">
  73 + <?php
  74 + echo $form->field($images[$lang]['preview'], "[{$lang}][preview]language_id")->label(false)->hiddenInput(['value' => $lang]);
  75 + echo $form->field($images[$lang]['preview'], "[{$lang}][preview]imageFile")->fileInput(['class' => 'image_inputs_field']);
  76 + if(!empty($images[$lang]['preview']->article_category_media_id)) {
  77 + echo "<img src='/images/upload/{$images[$lang]['preview']->media->hash}/original.{$images[$lang]['preview']->media->extension}' width='100' class='image_inputs_prev'>";
61 } 78 }
62 - } else {  
63 - echo $form->field($images[$index], "[{$index}]imageFile")->fileInput(['class' => 'image_inputs_field']);  
64 - if(!empty($image->id)) {  
65 - echo "<img src='/images/upload/{$image->media->hash}/original.{$image->media->extension}' width='100' class='image_inputs_prev'>"; 79 + ?>
  80 + </div>
  81 + <?php
  82 + $first = 0;
  83 + }
  84 + $imagelang->end();
  85 + ?>
  86 + </div>
  87 + <div role="" class="tab-pane" id="image-additional">
  88 + <?php
  89 + echo $form->field(is_array($images[0]['additional'])?$images[0]['additional'][0]:$images[0]['additional'], "[0][additional]imageFile[]")->fileInput(['multiple' => 'multiple', 'class' => 'image_inputs_field']);
  90 + if(is_array($images[0]['additional']) && count($images[0]['additional']) > 1) {
  91 + foreach($images[0]['additional'] as $onefield => $oneimage) {
  92 + if($onefield) {
  93 + ?>
  94 + <div class="additional_image_container">
  95 + <img src='/images/upload/<?= $oneimage->media->hash ?>/original.<?= $oneimage->media->extension ?>' width='100'>
  96 + <a
  97 + href="<?= Url::to(['ajax/remove-image']) ?>"
  98 + class="remove_image glyphicon glyphicon-remove-circle"
  99 + data-params='<?= Json::encode(['article_category_media_id' => $oneimage->article_category_media_id, 'remove_media' => true]) ?>',
  100 + ></a>
  101 + </div>
  102 + <?php
66 } 103 }
67 } 104 }
68 - ?>  
69 - </div>  
70 - <?php  
71 - $first = 0;  
72 - }  
73 - ?> 105 + }
  106 + ?>
  107 + </div>
74 </div> 108 </div>
75 109
76 <hr> 110 <hr>
77 111
78 - <div class="dropdown pull-right">  
79 - <button class="btn btn-default dropdown-toggle" type="button" id="dropdownLang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">  
80 - <?= Yii::t('app', 'Add language') ?>  
81 - <span class="caret"></span>  
82 - </button>  
83 - <ul class="dropdown-menu f32" id="lang-dropdown" aria-labelledby="dropdownMenu1">  
84 - <?php foreach($langs as $index => $lang) {  
85 - if(in_array($index, array_keys($category_langs))) continue;  
86 - ?>  
87 - <li><a href="#lang-tabs" data-lang="<?=$lang->language_id?>"><span class="flag <?=$lang->country_code?>"></span></a></li>  
88 - <?php } ?>  
89 - </ul>  
90 - </div>  
91 - <ul class="nav nav-tabs f32" id="lang-tabs" role="tablist">  
92 - <?php  
93 - $first = 1;  
94 - foreach($category_langs as $index => $category_lang) {  
95 - ?>  
96 - <li role="lang_inputs" class="<?php if($first) { echo 'active'; }?>" data-lang="<?=$index?>"><a href="#lang-<?=$index?>" aria-controls="lang-<?=$index?>" role="tab" data-toggle="tab"><span class="flag <?=$langs[$index]->country_code?>"></span></a></li>  
97 - <?php  
98 - $first = 0;  
99 - }  
100 - ?>  
101 - </ul>  
102 - <div class="tab-content lang-tab-content"> 112 + <?php
  113 + $multilang = Multilang::begin(['ajaxpath' => Url::to(['/blog/ajax/category-form']), 'form' => $form, 'data_langs' => $category_langs])
  114 + ?>
103 <?php 115 <?php
104 $first = 1; 116 $first = 1;
105 foreach($category_langs as $index => $category_lang) { 117 foreach($category_langs as $index => $category_lang) {
106 ?> 118 ?>
107 <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="lang-<?=$index?>"> 119 <div role="" class="tab-pane <?php if($first) { echo 'active main-tab'; } ?>" id="lang-<?=$index?>">
108 - <?= $form->field($category_langs[$index], "[$index]lang_id")->label(false)->hiddenInput(['value' => $index]) ?> 120 + <?= $form->field($category_langs[$index], "[$index]language_id")->label(false)->hiddenInput(['value' => $index]) ?>
109 121
110 <?= $form->field($category_langs[$index], "[$index]text")->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> 122 <?= $form->field($category_langs[$index], "[$index]text")->widget(CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?>
111 123
@@ -119,18 +131,20 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;); @@ -119,18 +131,20 @@ $uploaddir = \Yii::getAlias(&#39;@saveImageDir&#39;);
119 131
120 <?= $form->field($category_langs[$index], "[$index]meta_descr")->textarea(); ?> 132 <?= $form->field($category_langs[$index], "[$index]meta_descr")->textarea(); ?>
121 133
122 - <?= $form->field($category_langs[$index], "[$index]meta_keywords")->textInput() ?> 134 + <?= $form->field($category_langs[$index], "[$index]meta_keyword")->textInput() ?>
123 135
124 <?= $form->field($category_langs[$index], "[$index]h1_tag")->textInput() ?> 136 <?= $form->field($category_langs[$index], "[$index]h1_tag")->textInput() ?>
125 137
126 - <?= $form->field($category_langs[$index], "[$index]tags")->textInput() ?> 138 + <?= $form->field($category_langs[$index], "[$index]tag")->textInput() ?>
127 139
128 </div> 140 </div>
129 <?php 141 <?php
130 $first = 0; 142 $first = 0;
131 } 143 }
132 ?> 144 ?>
133 - </div> 145 + <?php
  146 + $multilang->end();
  147 + ?>
134 148
135 <div class="form-group"> 149 <div class="form-group">
136 <?= Html::submitButton($category->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $category->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 150 <?= Html::submitButton($category->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $category->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
common/modules/blog/views/category/index.php
@@ -7,15 +7,15 @@ use common\models\Language; @@ -7,15 +7,15 @@ use common\models\Language;
7 echo GridView::widget([ 7 echo GridView::widget([
8 'dataProvider' => $dataProvider, 8 'dataProvider' => $dataProvider,
9 'columns' => [ 9 'columns' => [
10 - 'id', 10 + 'article_category_id',
11 'code', 11 'code',
12 - 'created_at',  
13 - 'updated_at', 12 + 'date_add',
  13 + 'date_update',
14 [ 14 [
15 'class' => Column::className(), 15 'class' => Column::className(),
16 'header' => Yii::t('app', 'Name'), 16 'header' => Yii::t('app', 'Name'),
17 'content' => function($model, $key, $index, $column) { 17 'content' => function($model, $key, $index, $column) {
18 - return $model->getArticleCategoryLangs()->where(['lang_id' => Language::getDefaultLang()->language_id])->one()->name; 18 + return $model->getArticleCategoryLangs()->where(['language_id' => Language::getDefaultLang()->language_id])->one()->name;
19 } 19 }
20 ], 20 ],
21 [ 21 [
common/modules/blog/views/default/index.php
1 <?php 1 <?php
  2 +
  3 +use yii\behaviors\BlameableBehavior;
  4 +use yii\web\Application;
  5 +
  6 +$behavior = new BlameableBehavior();
  7 +var_dump($behavior->value);
2 \ No newline at end of file 8 \ No newline at end of file
common/translation/ru/app.php
@@ -58,9 +58,23 @@ return [ @@ -58,9 +58,23 @@ return [
58 'Category update' => 'Редактирование категории', 58 'Category update' => 'Редактирование категории',
59 'Article create' => 'Создание статьи', 59 'Article create' => 'Создание статьи',
60 'Update category' => 'Редактирование категории', 60 'Update category' => 'Редактирование категории',
61 - 'Select parent' => 'Выберать родителя', 61 + 'Select parent' => 'Выбрать родителя',
62 'Blog' => 'Блог', 62 'Blog' => 'Блог',
63 'Static pages' => 'Статические страницы', 63 'Static pages' => 'Статические страницы',
  64 + 'Create Admin Menu' => 'Создать элемент меню',
  65 + 'Admin Menus' => 'Административное меню',
  66 + 'Hide Min' => 'Спрятать в свернутом',
  67 + 'Path' => 'Путь',
  68 + 'Params' => 'Параметры',
  69 + 'Parent item' => 'Родительский элемент',
  70 + 'Active Menu' => 'Активный',
  71 + 'Not Active Menu' => 'Неактивный',
  72 + 'Show Menu Min' => 'Отобразить',
  73 + 'Hide Menu Min' => 'Спрятать',
  74 + 'Update' => 'Редактировать',
  75 + 'Delete' => 'Удалить',
  76 + 'Settings categories' => 'Разделы настроек',
  77 + 'Back' => 'Назад',
64 78
65 // Вова 79 // Вова
66 'page' => 'Страница', 80 'page' => 'Страница',
@@ -72,7 +86,7 @@ return [ @@ -72,7 +86,7 @@ return [
72 'meta_description' => 'Meta Description', 86 'meta_description' => 'Meta Description',
73 'text' => 'Текст', 87 'text' => 'Текст',
74 'page_alias' => 'alias', 88 'page_alias' => 'alias',
75 - 'lang_id' => 'ID языка', 89 + 'language_id' => 'ID языка',
76 'common' => 'Общее', 90 'common' => 'Общее',
77 'lang' => 'Языковые переменные', 91 'lang' => 'Языковые переменные',
78 'termin' => 'Термин', 92 'termin' => 'Термин',
common/translation/uk/app.php
@@ -14,7 +14,7 @@ return [ @@ -14,7 +14,7 @@ return [
14 'meta_description' => 'Meta Description', 14 'meta_description' => 'Meta Description',
15 'text' => 'Текст', 15 'text' => 'Текст',
16 'page_alias' => 'alias', 16 'page_alias' => 'alias',
17 - 'lang_id' => 'ID мови', 17 + 'language_id' => 'ID мови',
18 'common' => 'Загальне', 18 'common' => 'Загальне',
19 'lang' => 'Мовні змінні', 19 'lang' => 'Мовні змінні',
20 'termin' => 'Термін', 20 'termin' => 'Термін',
common/widgets/Multilang.php 0 → 100644
  1 +<?php
  2 +namespace common\widgets;
  3 +use common\models\Language;
  4 +use yii\base\InvalidParamException;
  5 +use yii\base\Widget;
  6 +use yii\bootstrap\ActiveForm;
  7 +
  8 +class Multilang extends Widget
  9 +{
  10 + public $id;
  11 +
  12 + public $langs;
  13 +
  14 + public $data_langs = [];
  15 +
  16 + public $ajaxpath;
  17 +
  18 + public $form;
  19 +
  20 + public function init()
  21 + {
  22 + parent::init();
  23 + if(empty($this->id)) {
  24 + $this->id = \Yii::$app->security->generateRandomString(8);
  25 + }
  26 + if(empty($this->langs)) {
  27 + $this->langs = Language::getActiveLanguages();
  28 + }
  29 + if(empty($this->ajaxpath)) {
  30 + throw new InvalidParamException('ajaxpath must be set');
  31 + }
  32 + if(empty($this->form)) {
  33 + throw new InvalidParamException('form must be set');
  34 + }
  35 + ob_start();
  36 + echo $this->render('multilang-begin', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
  37 + }
  38 +
  39 + public function run()
  40 + {
  41 + echo $this->render('multilang-end', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
  42 + $content = ob_get_clean();
  43 + return $content;
  44 + }
  45 +}
0 \ No newline at end of file 46 \ No newline at end of file
common/widgets/Multilanguage.php 0 → 100644
  1 +<?php
  2 +namespace common\widgets;
  3 +use common\models\Language;
  4 +use common\modules\blog\controllers\AjaxController;
  5 +use yii\base\InvalidParamException;
  6 +use yii\base\Widget;
  7 +use yii\bootstrap\ActiveForm;
  8 +
  9 +class Multilanguage extends Widget
  10 +{
  11 + public $id;
  12 +
  13 + public $model_name;
  14 +
  15 + public $table_name;
  16 +
  17 + public $langs;
  18 +
  19 + public $default_lang;
  20 +
  21 + public $data;
  22 +
  23 + public $handler = '/blog/ajax/multilang-form';
  24 +
  25 + public $form;
  26 +
  27 + public $ajaxView;
  28 +
  29 + public function init()
  30 + {
  31 + parent::init();
  32 + $this->default_lang = Language::getDefaultLang();
  33 + if(empty($this->langs)) {
  34 + $this->langs = Language::getActiveLanguages();
  35 + }
  36 + if(empty($this->form)) {
  37 + throw new InvalidParamException('Form must be set');
  38 + }
  39 + if(empty($this->ajaxView)) {
  40 + throw new InvalidParamException('Ajaxview must be set');
  41 + }
  42 + if(empty($this->data) || !is_array($this->data)) {
  43 + throw new InvalidParamException('Data must be set and be array');
  44 + } else {
  45 + $first = 1;
  46 + foreach ($this->data as $lang => $item) {
  47 + if ($first) {
  48 + $this->model_name = $item->className();
  49 + $this->table_name = $item->tableName();
  50 + $first = 0;
  51 + } else {
  52 + if($item->className() !== $this->model_name || $item->tableName() !== $this->table_name) {
  53 + throw new InvalidParamException('Every data element must have the same class and table');
  54 + }
  55 + }
  56 + }
  57 + }
  58 + }
  59 +
  60 + public function run()
  61 + {
  62 + echo $this->render('multilanguage-begin', [
  63 + 'id' => $this->id,
  64 + 'model_name' => $this->model_name,
  65 + 'table_name' => $this->table_name,
  66 + 'data' => $this->data,
  67 + 'langs' => $this->langs,
  68 + 'handler' => $this->handler,
  69 + 'default_lang' => $this->default_lang,
  70 + 'ajaxView' => $this->ajaxView,
  71 + ]);
  72 + foreach($this->data as $lang => $item) {
  73 + $item->language_id = $lang;
  74 + echo $this->render($this->ajaxView, ['model' => $item, 'form' => $this->form, 'widget_id' => $this->id]);
  75 + }
  76 + echo $this->render('multilanguage-end', [
  77 + 'id' => $this->id,
  78 + 'model_name' => $this->model_name,
  79 + 'table_name' => $this->table_name,
  80 + 'data' => $this->data,
  81 + 'langs' => $this->langs,
  82 + 'handler' => $this->handler,
  83 + 'default_lang' => $this->default_lang,
  84 + 'ajaxView' => $this->ajaxView,
  85 + ]);
  86 + }
  87 +}
0 \ No newline at end of file 88 \ No newline at end of file
common/widgets/views/multilang-begin.php 0 → 100644
  1 +<?php
  2 +use yii\helpers\Url;
  3 +?>
  4 +<div class="dropdown pull-right">
  5 + <button class="btn btn-default dropdown-toggle" type="button" id="<?=$id?>Lang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  6 + <?= Yii::t('app', 'Add language') ?>
  7 + <span class="caret"></span>
  8 + </button>
  9 + <ul class="dropdown-menu f32 old" id="lang-<?=$id?>" aria-labelledby="<?=$id?>Menu">
  10 + <?php foreach($langs as $index => $lang) {
  11 + if(in_array($index, array_keys($data_langs))) continue;
  12 + ?>
  13 + <li><a href="#<?=$id?>" data-lang="<?=$lang->language_id?>"><span class="flag <?=$lang->country_code?>"></span></a></li>
  14 + <?php } ?>
  15 + </ul>
  16 +</div>
  17 +<ul class="nav nav-tabs f32" id="<?=$id?>-tabs" role="tablist">
  18 + <?php
  19 + $first = 1;
  20 + foreach($data_langs as $index => $data_lang) {
  21 + if(!$index) continue;
  22 + ?>
  23 + <li role="lang_inputs" class="<?php if($first) { echo 'active'; }?>" data-lang="<?=$index?>"><a href="#<?=$id?>-<?=$index?>" aria-controls="<?=$id?>-<?=$index?>" role="tab" data-toggle="tab"><span class="flag <?=$langs[$index]->country_code?>"></span></a></li>
  24 + <?php
  25 + $first = 0;
  26 + }
  27 + ?>
  28 +</ul>
  29 +<div class="tab-content lang-tab-content" id="tab-content-<?=$id?>">
  30 +
common/widgets/views/multilang-end.php 0 → 100644
  1 +<?php
  2 +use yii\helpers\Url;
  3 +?>
  4 +</div>
  5 +<script>
  6 + if(typeof form === 'undefined') {
  7 + var form = [];
  8 + }
  9 + form['<?=$id?>'] = '<?=$ajaxpath?>';
  10 +</script>
0 \ No newline at end of file 11 \ No newline at end of file
common/widgets/views/multilanguage-begin.php 0 → 100644
  1 +<?php
  2 +use yii\helpers\Url;
  3 +?>
  4 +<div class="dropdown pull-right">
  5 + <button class="btn btn-default dropdown-toggle" type="button" id="<?=$id?>Lang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  6 + <?= Yii::t('app', 'Add language') ?>
  7 + <span class="caret"></span>
  8 + </button>
  9 + <ul class="dropdown-menu f32" id="lang-<?=$id?>" aria-labelledby="<?=$id?>Menu">
  10 + <?php foreach($langs as $index => $lang) {
  11 + if(in_array($index, array_keys($data))) continue;
  12 + ?>
  13 + <li><a href="#<?=$id?>" data-lang="<?=$lang->language_id?>"><span class="flag <?=$lang->country_code?>"></span></a></li>
  14 + <?php } ?>
  15 + </ul>
  16 +</div>
  17 +<ul class="nav nav-tabs f32" id="<?=$id?>-tabs" role="tablist">
  18 + <?php
  19 + foreach($data as $index => $data_lang) {
  20 + if(!$index) continue;
  21 + ?>
  22 + <li role="lang_inputs" data-lang="<?=$index?>"><a href="#<?=$id?>-<?=$index?>" aria-controls="<?=$id?>-<?=$index?>" role="tab" data-toggle="tab"><span class="flag <?=$langs[$index]->country_code?>"></span></a></li>
  23 + <?php
  24 + }
  25 + ?>
  26 +</ul>
  27 +<div class="tab-content lang-tab-content" id="tab-content-<?=$id?>">
  28 +
common/widgets/views/multilanguage-end.php 0 → 100644
  1 +<?php
  2 +use yii\helpers\Url;
  3 +?>
  4 +</div>
  5 +<script>
  6 + if(typeof form === 'undefined') {
  7 + var form = [];
  8 + }
  9 + form['<?=$id?>'] = {handler:'<?=$handler?>', view:'<?=$ajaxView?>', model: '<?=str_replace("\\", "\\\\", $model_name)?>'};
  10 +</script>
0 \ No newline at end of file 11 \ No newline at end of file
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 "irc": "irc://irc.freenode.net/yii", 12 "irc": "irc://irc.freenode.net/yii",
13 "source": "https://github.com/yiisoft/yii2" 13 "source": "https://github.com/yiisoft/yii2"
14 }, 14 },
15 - "minimum-stability": "stable", 15 + "minimum-stability": "dev",
16 "require": { 16 "require": {
17 "php": ">=5.4.0", 17 "php": ">=5.4.0",
18 "yiisoft/yii2": ">=2.0.6", 18 "yiisoft/yii2": ">=2.0.6",
db-migration/artbox_db.backup deleted
No preview for this file type
db-migration/artbox_db3.backup deleted
No preview for this file type
db-migration/catalog.backup deleted
No preview for this file type
db-migration/yarik.sql deleted
1 --- --------------------------------------------------------  
2 --- Хост: 127.0.0.1  
3 --- Версия сервера: PostgreSQL 9.4.4, compiled by Visual C++ build 1800, 32-bit  
4 --- ОС Сервера:  
5 --- HeidiSQL Версия: 9.3.0.4984  
6 --- --------------------------------------------------------  
7 -  
8 -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;  
9 -/*!40101 SET NAMES */;  
10 -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;  
11 -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;  
12 -  
13 --- Дамп структуры для таблица public.article  
14 -CREATE TABLE IF NOT EXISTS "article" (  
15 - "id" INTEGER NOT NULL DEFAULT nextval('article_id_seq'::regclass) COMMENT E'',  
16 - "sort" INTEGER NOT NULL DEFAULT 100 COMMENT E'',  
17 - "create_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now() COMMENT E'',  
18 - "update_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now() COMMENT E'',  
19 - "code" CHARACTER VARYING NOT NULL COMMENT E'',  
20 - "category_id" INTEGER NOT NULL DEFAULT 1 COMMENT E'',  
21 - "author" INTEGER NOT NULL COMMENT E'',  
22 - "tags" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
23 - "parent_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
24 - "active" SMALLINT NOT NULL DEFAULT 0 COMMENT E'',  
25 - "comments" SMALLINT NOT NULL DEFAULT 0::smallint COMMENT E'',  
26 - "voting" SMALLINT NOT NULL DEFAULT 0::smallint COMMENT E'',  
27 - KEY ("author"),  
28 - PRIMARY KEY ("id"),  
29 - KEY ("parent_id"),  
30 - KEY ("category_id"),  
31 - KEY ("id")  
32 -);  
33 -  
34 --- Дамп данных таблицы public.article: 3 rows  
35 -/*!40000 ALTER TABLE "article" DISABLE KEYS */;  
36 -INSERT INTO "article" ("id", "sort", "create_at", "update_at", "code", "category_id", "author", "tags", "parent_id", "active", "comments", "voting") VALUES  
37 - (5, 100, E'2015-12-04 14:52:39.54', E'2015-12-04 14:52:39.54', E'test_article', 1, 1, E'test, tag', NULL, 1, 0, 0),  
38 - (6, 100, E'2015-12-04 14:52:52.403', E'2015-12-04 14:52:52.403', E'test_article2', 1, 1, E'test, tag', NULL, 1, 0, 0),  
39 - (12, 100, E'2015-12-04 14:52:52.403', E'2015-12-04 14:52:52.403', E'test_article3', 1, 1, E'test, tag', 5, 1, 0, 0);  
40 -/*!40000 ALTER TABLE "article" ENABLE KEYS */;  
41 -  
42 -  
43 --- Дамп структуры для таблица public.article_category  
44 -CREATE TABLE IF NOT EXISTS "article_category" (  
45 - "id" INTEGER NOT NULL DEFAULT nextval('article_category_id_seq'::regclass) COMMENT E'',  
46 - "sort" INTEGER NOT NULL DEFAULT 100 COMMENT E'',  
47 - "code" CHARACTER VARYING NOT NULL COMMENT E'',  
48 - "created_at" TIME WITHOUT TIME ZONE NOT NULL DEFAULT now() COMMENT E'',  
49 - "updated_at" TIME WITHOUT TIME ZONE NOT NULL DEFAULT now() COMMENT E'',  
50 - "tags" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
51 - "parent_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
52 - "active" SMALLINT NOT NULL DEFAULT 0 COMMENT E'',  
53 - PRIMARY KEY ("id"),  
54 - KEY ("parent_id"),  
55 - KEY ("id")  
56 -);  
57 -  
58 --- Дамп данных таблицы public.article_category: 2 rows  
59 -/*!40000 ALTER TABLE "article_category" DISABLE KEYS */;  
60 -INSERT INTO "article_category" ("id", "sort", "code", "created_at", "updated_at", "tags", "parent_id", "active") VALUES  
61 - (1, 100, E'static_pages', E'14:08:02.74', E'14:08:02.74', NULL, NULL, 1),  
62 - (2, 100, E'qwerty', E'11:00:35.954', E'11:00:35.954', E'qwerty', NULL, 0);  
63 -/*!40000 ALTER TABLE "article_category" ENABLE KEYS */;  
64 -  
65 -  
66 --- Дамп структуры для таблица public.article_category_lang  
67 -CREATE TABLE IF NOT EXISTS "article_category_lang" (  
68 - "id" INTEGER NOT NULL DEFAULT nextval('article_category_lang_id_seq'::regclass) COMMENT E'',  
69 - "lang_id" INTEGER NOT NULL DEFAULT 0 COMMENT E'',  
70 - "category_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
71 - "text" TEXT NOT NULL COMMENT E'',  
72 - "preview" TEXT NULL DEFAULT NULL COMMENT E'',  
73 - "seo_url" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
74 - "name" CHARACTER VARYING NOT NULL COMMENT E'',  
75 - "meta_title" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
76 - "meta_descr" TEXT NULL DEFAULT NULL COMMENT E'',  
77 - "meta_keywords" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
78 - "h1_tag" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
79 - "tags" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
80 - PRIMARY KEY ("id"),  
81 - KEY ("category_id"),  
82 - KEY ("lang_id"),  
83 - KEY ("id")  
84 -);  
85 -  
86 --- Дамп данных таблицы public.article_category_lang: 3 rows  
87 -/*!40000 ALTER TABLE "article_category_lang" DISABLE KEYS */;  
88 -INSERT INTO "article_category_lang" ("id", "lang_id", "category_id", "text", "preview", "seo_url", "name", "meta_title", "meta_descr", "meta_keywords", "h1_tag", "tags") VALUES  
89 - (1, 0, 1, E'Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem ', E'Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem ', E'lorem', E'Lorem ipsum', E'Lorem title', E'Lorem description', E'lorem, keyword', E'Lorem h1 tag', E'lorem tag'),  
90 - (2, 2, 2, E'qwerty', E'qwerty', E'qwerty', E'qwerty', E'qwerty', E'qwerty', E'qwerty', E'qwerty', E'qwerty'),  
91 - (3, 1, 2, E'йцукен', E'йцукен', E'йцукен', E'йцукен', E'йцукен', E'йцукен', E'йцукен', E'йцукен', E'йцукен');  
92 -/*!40000 ALTER TABLE "article_category_lang" ENABLE KEYS */;  
93 -  
94 -  
95 --- Дамп структуры для таблица public.article_category_media  
96 -CREATE TABLE IF NOT EXISTS "article_category_media" (  
97 - "id" INTEGER NOT NULL DEFAULT nextval('article_category_media_id_seq'::regclass) COMMENT E'',  
98 - "category_id" INTEGER NOT NULL COMMENT E'',  
99 - "media_id" INTEGER NOT NULL COMMENT E'',  
100 - "media_alt" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
101 - "media_title" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
102 - "media_caption" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
103 - "type" CHARACTER VARYING(10) NOT NULL DEFAULT 'additional'::character varying COMMENT E'',  
104 - PRIMARY KEY ("id"),  
105 - KEY ("media_id"),  
106 - KEY ("category_id"),  
107 - KEY ("id")  
108 -);  
109 -  
110 --- Дамп данных таблицы public.article_category_media: 0 rows  
111 -/*!40000 ALTER TABLE "article_category_media" DISABLE KEYS */;  
112 -/*!40000 ALTER TABLE "article_category_media" ENABLE KEYS */;  
113 -  
114 -  
115 --- Дамп структуры для таблица public.article_lang  
116 -CREATE TABLE IF NOT EXISTS "article_lang" (  
117 - "id" INTEGER NOT NULL DEFAULT nextval('article_lang_id_seq'::regclass) COMMENT E'',  
118 - "lang_id" INTEGER NOT NULL COMMENT E'',  
119 - "article_id" INTEGER NOT NULL COMMENT E'',  
120 - "text" TEXT NOT NULL COMMENT E'',  
121 - "seo_url" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
122 - "name" CHARACTER VARYING NOT NULL COMMENT E'',  
123 - "preview" TEXT NULL DEFAULT NULL COMMENT E'',  
124 - "meta_title" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
125 - "meta_descr" TEXT NULL DEFAULT NULL COMMENT E'',  
126 - "meta_keywords" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
127 - "h1_tag" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
128 - "tags" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
129 - PRIMARY KEY ("id"),  
130 - KEY ("article_id"),  
131 - KEY ("lang_id"),  
132 - KEY ("id")  
133 -);  
134 -  
135 --- Дамп данных таблицы public.article_lang: 2 rows  
136 -/*!40000 ALTER TABLE "article_lang" DISABLE KEYS */;  
137 -INSERT INTO "article_lang" ("id", "lang_id", "article_id", "text", "seo_url", "name", "preview", "meta_title", "meta_descr", "meta_keywords", "h1_tag", "tags") VALUES  
138 - (1, 0, 5, E'Lorem Lorem Lorem', E'article1', E'artivle1', E'Lorem preview', E'Lorem title', E'Lorem description', E'lorem, keyword', E'lorem h1 tag', E'tag, lorem'),  
139 - (2, 0, 12, E'Lorem Lorem Lorem', E'article3', E'artivle3\r\n', E'Lorem preview', E'Lorem title', E'Lorem description', E'lorem, keyword', E'lorem h1 tag', E'tag, lorem');  
140 -/*!40000 ALTER TABLE "article_lang" ENABLE KEYS */;  
141 -  
142 -  
143 --- Дамп структуры для таблица public.article_media  
144 -CREATE TABLE IF NOT EXISTS "article_media" (  
145 - "id" INTEGER NOT NULL DEFAULT nextval('article_media_id_seq'::regclass) COMMENT E'',  
146 - "article_id" INTEGER NOT NULL COMMENT E'',  
147 - "media_id" INTEGER NOT NULL COMMENT E'',  
148 - "type" CHARACTER VARYING(10) NOT NULL DEFAULT 'additional'::character varying COMMENT E'',  
149 - "media_alt" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
150 - "media_title" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
151 - "media_caption" CHARACTER VARYING NULL DEFAULT NULL COMMENT E'',  
152 - PRIMARY KEY ("id"),  
153 - KEY ("media_id"),  
154 - KEY ("article_id"),  
155 - KEY ("id")  
156 -);  
157 -  
158 --- Дамп данных таблицы public.article_media: 0 rows  
159 -/*!40000 ALTER TABLE "article_media" DISABLE KEYS */;  
160 -/*!40000 ALTER TABLE "article_media" ENABLE KEYS */;  
161 -  
162 -  
163 --- Дамп структуры для таблица public.media  
164 -CREATE TABLE IF NOT EXISTS "media" (  
165 - "id" INTEGER NOT NULL DEFAULT nextval('media_id_seq'::regclass) COMMENT E'',  
166 - "hash" CHARACTER VARYING NOT NULL COMMENT E'',  
167 - PRIMARY KEY ("id"),  
168 - KEY ("id")  
169 -);  
170 -  
171 --- Дамп данных таблицы public.media: 0 rows  
172 -/*!40000 ALTER TABLE "media" DISABLE KEYS */;  
173 -/*!40000 ALTER TABLE "media" ENABLE KEYS */;  
174 -  
175 -  
176 --- Дамп структуры для таблица public.option  
177 -CREATE TABLE IF NOT EXISTS "option" (  
178 - "model" CHARACTER VARYING(200) NULL DEFAULT NULL COMMENT E'',  
179 - "option_id" INTEGER NOT NULL DEFAULT nextval('option_option_id_seq'::regclass) COMMENT E'',  
180 - "model_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
181 - "name" CHARACTER VARYING(200) NULL DEFAULT NULL COMMENT E'',  
182 - "template" CHARACTER VARYING(200) NULL DEFAULT NULL COMMENT E'',  
183 - "parent_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
184 - "translate" BIT(1) NULL DEFAULT NULL COMMENT E'',  
185 - "created_at" TIMESTAMP WITHOUT TIME ZONE NULL DEFAULT now() COMMENT E'',  
186 - KEY ("option_id"),  
187 - KEY ("parent_id"),  
188 - PRIMARY KEY ("option_id")  
189 -);  
190 -  
191 --- Дамп данных таблицы public.option: 0 rows  
192 -/*!40000 ALTER TABLE "option" DISABLE KEYS */;  
193 -/*!40000 ALTER TABLE "option" ENABLE KEYS */;  
194 -  
195 -  
196 --- Дамп структуры для таблица public.option_lang  
197 -CREATE TABLE IF NOT EXISTS "option_lang" (  
198 - "primary" INTEGER NOT NULL DEFAULT nextval('option_lang_primary_seq'::regclass) COMMENT E'',  
199 - "id" INTEGER NULL DEFAULT NULL COMMENT E'',  
200 - "lang_id" INTEGER NULL DEFAULT NULL COMMENT E'',  
201 - "value" TEXT NULL DEFAULT NULL COMMENT E'',  
202 - KEY ("id"),  
203 - PRIMARY KEY ("primary")  
204 -);  
205 -  
206 --- Дамп данных таблицы public.option_lang: 0 rows  
207 -/*!40000 ALTER TABLE "option_lang" DISABLE KEYS */;  
208 -/*!40000 ALTER TABLE "option_lang" ENABLE KEYS */;  
209 -/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;  
210 -/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;  
211 -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;  
db-migration/yarik/lang.backup 0 → 100644
No preview for this file type
db-migration/article_option_migration.backup renamed to db-migration/yarik/newnames.backup
No preview for this file type
db-migration/yarik/public.backup 0 → 100644
No preview for this file type
frontend/config/main.php
@@ -16,9 +16,7 @@ return [ @@ -16,9 +16,7 @@ return [
16 'bootstrap' => ['log'], 16 'bootstrap' => ['log'],
17 'controllerNamespace' => 'frontend\controllers', 17 'controllerNamespace' => 'frontend\controllers',
18 'modules' => [ 18 'modules' => [
19 - 'blog' => [  
20 - 'class' => 'common\modules\blog\Module',  
21 - ], 19 +
22 ], 20 ],
23 'components' => [ 21 'components' => [
24 //'PageController'=>[ 22 //'PageController'=>[
frontend/controllers/OptionValuesController.php
@@ -68,7 +68,7 @@ class OptionValuesController extends Controller @@ -68,7 +68,7 @@ class OptionValuesController extends Controller
68 foreach($post['OptionValues']['option_value_text'] as $lang => $value) { 68 foreach($post['OptionValues']['option_value_text'] as $lang => $value) {
69 $models[$lang] = new OptionValues(); 69 $models[$lang] = new OptionValues();
70 $models[$lang]->load(Yii::$app->request->post()); 70 $models[$lang]->load(Yii::$app->request->post());
71 - $models[$lang]->option_lang_id = $lang; 71 + $models[$lang]->option_language_id = $lang;
72 $models[$lang]->option_value_text = $value; 72 $models[$lang]->option_value_text = $value;
73 if($first && $id) { 73 if($first && $id) {
74 $models[$lang]->option_value_parent = $id; 74 $models[$lang]->option_value_parent = $id;
frontend/controllers/SiteController.php
@@ -36,7 +36,7 @@ class SiteController extends Controller @@ -36,7 +36,7 @@ class SiteController extends Controller
36 return [ 36 return [
37 'access' => [ 37 'access' => [
38 'class' => AccessControl::className(), 38 'class' => AccessControl::className(),
39 - 'only' => ['logout', 'signup'], 39 + 'only' => ['logout', 'signup', 'index'],
40 'rules' => [ 40 'rules' => [
41 [ 41 [
42 'actions' => ['signup'], 42 'actions' => ['signup'],
@@ -48,6 +48,11 @@ class SiteController extends Controller @@ -48,6 +48,11 @@ class SiteController extends Controller
48 'allow' => true, 48 'allow' => true,
49 'roles' => ['@'], 49 'roles' => ['@'],
50 ], 50 ],
  51 + [
  52 + 'actions' => ['index'],
  53 + 'allow' => true,
  54 + 'roles' => ['@'],
  55 + ]
51 ], 56 ],
52 ], 57 ],
53 'verbs' => [ 58 'verbs' => [
@@ -298,10 +303,10 @@ class SiteController extends Controller @@ -298,10 +303,10 @@ class SiteController extends Controller
298 $option_values[$key] = new OptionValues(); 303 $option_values[$key] = new OptionValues();
299 $option_values[$key]['option_value_id'] = $options_to_values[$key]->getAttribute('option_value_id'); 304 $option_values[$key]['option_value_id'] = $options_to_values[$key]->getAttribute('option_value_id');
300 $option_values[$key]['option_value_text'] = $val['option_value']; 305 $option_values[$key]['option_value_text'] = $val['option_value'];
301 - if($options_to_values[$key]->option->getAttribute('option_translatable') == 0 || empty($val['option_lang_id'])) {  
302 - $option_values[$key]['option_lang_id'] = 0; 306 + if($options_to_values[$key]->option->getAttribute('option_translatable') == 0 || empty($val['option_language_id'])) {
  307 + $option_values[$key]['option_language_id'] = 0;
303 } else { 308 } else {
304 - $option_values[$key]['option_lang_id'] = $val['option_lang_id']; 309 + $option_values[$key]['option_language_id'] = $val['option_language_id'];
305 } 310 }
306 if(!$option_values[$key]->save()) { 311 if(!$option_values[$key]->save()) {
307 $options_to_values[$key]->delete(); 312 $options_to_values[$key]->delete();
frontend/models/Language.php
@@ -61,6 +61,6 @@ class Language extends \yii\db\ActiveRecord @@ -61,6 +61,6 @@ class Language extends \yii\db\ActiveRecord
61 */ 61 */
62 public function getOptionValues() 62 public function getOptionValues()
63 { 63 {
64 - return $this->hasMany(OptionValues::className(), ['option_lang_id' => 'language_id']); 64 + return $this->hasMany(OptionValues::className(), ['option_language_id' => 'language_id']);
65 } 65 }
66 } 66 }
frontend/models/LanguageLang.php
@@ -9,7 +9,7 @@ use Yii; @@ -9,7 +9,7 @@ use Yii;
9 * 9 *
10 * @property integer $language_id 10 * @property integer $language_id
11 * @property string $lang_title 11 * @property string $lang_title
12 - * @property integer $lang_id 12 + * @property integer $language_id
13 * 13 *
14 * @property Language $language 14 * @property Language $language
15 */ 15 */
@@ -43,7 +43,7 @@ class LanguageLang extends \yii\db\ActiveRecord @@ -43,7 +43,7 @@ class LanguageLang extends \yii\db\ActiveRecord
43 return [ 43 return [
44 'language_id' => Yii::t('app', 'Language ID'), 44 'language_id' => Yii::t('app', 'Language ID'),
45 'lang_title' => Yii::t('app', 'Lang Title'), 45 'lang_title' => Yii::t('app', 'Lang Title'),
46 - 'lang_id' => Yii::t('app', 'Lang ID'), 46 + 'language_id' => Yii::t('app', 'Lang ID'),
47 ]; 47 ];
48 } 48 }
49 49
frontend/models/Option.php
@@ -31,7 +31,7 @@ class Option extends \yii\db\ActiveRecord @@ -31,7 +31,7 @@ class Option extends \yii\db\ActiveRecord
31 { 31 {
32 return [ 32 return [
33 [['model', 'model_id', 'name', 'template'], 'required'], 33 [['model', 'model_id', 'name', 'template'], 'required'],
34 - [['model_id', 'parent_id'], 'integer'], 34 + [['model_id', 'option_pid'], 'integer'],
35 [['model', 'name', 'template'], 'string', 'max' => 200] 35 [['model', 'name', 'template'], 'string', 'max' => 200]
36 ]; 36 ];
37 } 37 }
@@ -47,29 +47,30 @@ class Option extends \yii\db\ActiveRecord @@ -47,29 +47,30 @@ class Option extends \yii\db\ActiveRecord
47 'model_id' => Yii::t('app', 'Model ID'), 47 'model_id' => Yii::t('app', 'Model ID'),
48 'name' => Yii::t('app', 'Name'), 48 'name' => Yii::t('app', 'Name'),
49 'template' => Yii::t('app', 'Template'), 49 'template' => Yii::t('app', 'Template'),
50 - 'parent_id' => Yii::t('app', 'Parent ID'),  
51 - 'created_at' => Yii::t('app', 'Date created'), 50 + 'option_pid' => Yii::t('app', 'Parent ID'),
  51 + 'date_add' => Yii::t('app', 'Date created'),
  52 + 'translate' => Yii::t('app', 'Translatable'),
52 ]; 53 ];
53 } 54 }
54 55
55 public function getLangs() { 56 public function getLangs() {
56 - return (new Language())->find()->where(['>', 'language_id', 0])->andWhere(['active' => 1])->asArray()->all(); 57 + return (new Language())->find()->where(['>', 'language_id', 0])->andWhere(['status' => 1])->asArray()->all();
57 } 58 }
58 59
59 public static function change($id, $post, $modeldb, $model_id) { 60 public static function change($id, $post, $modeldb, $model_id) {
60 $models[$id] = Option::findOne($id); 61 $models[$id] = Option::findOne($id);
61 $modellang[$id] = array(); 62 $modellang[$id] = array();
62 - $langs = OptionLang::findAll(['id' => $id]); 63 + $langs = OptionLang::findAll(['option_language_id' => $id]);
63 foreach($langs as $lang) { 64 foreach($langs as $lang) {
64 - $modellang[$id][$lang->lang_id] = $lang; 65 + $modellang[$id][$lang->language_id] = $lang;
65 } 66 }
66 - $children = (new Option())->find()->where(['parent_id' => $id])->all(); 67 + $children = (new Option())->find()->where(['option_pid' => $id])->all();
67 foreach($children as $child) { 68 foreach($children as $child) {
68 $models[$child->option_id] = $child; 69 $models[$child->option_id] = $child;
69 $modellang[$child->option_id] = array(); 70 $modellang[$child->option_id] = array();
70 - $langs = OptionLang::findAll(['id' =>$child->option_id]); 71 + $langs = OptionLang::findAll(['option_id' =>$child->option_id]);
71 foreach($langs as $lang) { 72 foreach($langs as $lang) {
72 - $modellang[$child->option_id][$lang->lang_id] = $lang; 73 + $modellang[$child->option_id][$lang->language_id] = $lang;
73 } 74 }
74 } 75 }
75 $ok = 1; 76 $ok = 1;
@@ -77,7 +78,7 @@ class Option extends \yii\db\ActiveRecord @@ -77,7 +78,7 @@ class Option extends \yii\db\ActiveRecord
77 foreach($post['Option'] as $key => $option) { 78 foreach($post['Option'] as $key => $option) {
78 if(in_array($key, array('model', 'model_id'))) { continue; } 79 if(in_array($key, array('model', 'model_id'))) { continue; }
79 if(empty($option['value'][$models[$key]->name]) && !empty($option['lang'])) { 80 if(empty($option['value'][$models[$key]->name]) && !empty($option['lang'])) {
80 - foreach($option['lang'] as $lang_id => $lang) { 81 + foreach($option['lang'] as $language_id => $lang) {
81 if(!empty($lang)) { 82 if(!empty($lang)) {
82 $option['value'][$models[$key]->name] = $lang; 83 $option['value'][$models[$key]->name] = $lang;
83 break; 84 break;
@@ -91,16 +92,16 @@ class Option extends \yii\db\ActiveRecord @@ -91,16 +92,16 @@ class Option extends \yii\db\ActiveRecord
91 $modellang[$key][0]->addError('value', 'Value must be set'); 92 $modellang[$key][0]->addError('value', 'Value must be set');
92 } 93 }
93 if(!empty($option['lang'])) { 94 if(!empty($option['lang'])) {
94 - foreach($option['lang'] as $lang_id => $lang) {  
95 - if(empty($modellang[$key][$lang_id])) {  
96 - $modellang[$key][$lang_id] = new OptionLang();  
97 - $modellang[$key][$lang_id]->id = $models[$key]->option_id;  
98 - $modellang[$key][$lang_id]->lang_id = $lang_id;  
99 - $modellang[$key][$lang_id]->value = $lang; 95 + foreach($option['lang'] as $language_id => $lang) {
  96 + if(empty($modellang[$key][$language_id])) {
  97 + $modellang[$key][$language_id] = new OptionLang();
  98 + $modellang[$key][$language_id]->option_id = $models[$key]->option_id;
  99 + $modellang[$key][$language_id]->language_id = $language_id;
  100 + $modellang[$key][$language_id]->value = $lang;
100 } else { 101 } else {
101 - $modellang[$key][$lang_id]->value = $lang; 102 + $modellang[$key][$language_id]->value = $lang;
102 } 103 }
103 - if(!$modellang[$key][$lang_id]->save()) { 104 + if(!$modellang[$key][$language_id]->save()) {
104 $ok = 0; 105 $ok = 0;
105 } 106 }
106 } 107 }
@@ -146,7 +147,7 @@ class Option extends \yii\db\ActiveRecord @@ -146,7 +147,7 @@ class Option extends \yii\db\ActiveRecord
146 $models[$index][$key]->translate = $option[$key]['translate']?1:0; 147 $models[$index][$key]->translate = $option[$key]['translate']?1:0;
147 $models[$index][$key]->name = $key; 148 $models[$index][$key]->name = $key;
148 if(!$first) { 149 if(!$first) {
149 - $models[$index][$key]->parent_id = $parentid; 150 + $models[$index][$key]->option_pid = $parentid;
150 } 151 }
151 $modelslang[$index][$key][0] = new OptionLang(); 152 $modelslang[$index][$key][0] = new OptionLang();
152 if(!empty($option['lang'][$key])) { 153 if(!empty($option['lang'][$key])) {
@@ -161,16 +162,16 @@ class Option extends \yii\db\ActiveRecord @@ -161,16 +162,16 @@ class Option extends \yii\db\ActiveRecord
161 if($first) { 162 if($first) {
162 $parentid = $models[$index][$key]->option_id; 163 $parentid = $models[$index][$key]->option_id;
163 } 164 }
164 - $modelslang[$index][$key][0]->id = $models[$index][$key]->option_id;  
165 - $modelslang[$index][$key][0]->lang_id = 0; 165 + $modelslang[$index][$key][0]->option_id = $models[$index][$key]->option_id;
  166 + $modelslang[$index][$key][0]->language_id = 0;
166 $modelslang[$index][$key][0]->value = $value; 167 $modelslang[$index][$key][0]->value = $value;
167 if($modelslang[$index][$key][0]->save()) { 168 if($modelslang[$index][$key][0]->save()) {
168 if(!empty($option['lang'][$key])) { 169 if(!empty($option['lang'][$key])) {
169 foreach($option['lang'][$key] as $code => $lang) { 170 foreach($option['lang'][$key] as $code => $lang) {
170 if(!empty($lang)) { 171 if(!empty($lang)) {
171 $modelslang[$index][$key][$code] = new OptionLang(); 172 $modelslang[$index][$key][$code] = new OptionLang();
172 - $modelslang[$index][$key][$code]->id = $models[$index][$key]->option_id;  
173 - $modelslang[$index][$key][$code]->lang_id = $code; 173 + $modelslang[$index][$key][$code]->option_id = $models[$index][$key]->option_id;
  174 + $modelslang[$index][$key][$code]->language_id = $code;
174 $modelslang[$index][$key][$code]->value = $lang; 175 $modelslang[$index][$key][$code]->value = $lang;
175 if(!$modelslang[$index][$key][$code]->save()) { 176 if(!$modelslang[$index][$key][$code]->save()) {
176 $ok = 0; 177 $ok = 0;
@@ -187,8 +188,8 @@ class Option extends \yii\db\ActiveRecord @@ -187,8 +188,8 @@ class Option extends \yii\db\ActiveRecord
187 foreach($option['lang'][$key] as $code => $lang) { 188 foreach($option['lang'][$key] as $code => $lang) {
188 if(!empty($lang)) { 189 if(!empty($lang)) {
189 $modelslang[$index][$key][$code] = new OptionLang(); 190 $modelslang[$index][$key][$code] = new OptionLang();
190 - $modelslang[$index][$key][$code]->id = $models[$index][$key]->option_id;  
191 - $modelslang[$index][$key][$code]->lang_id = $code; 191 + $modelslang[$index][$key][$code]->option_id = $models[$index][$key]->option_id;
  192 + $modelslang[$index][$key][$code]->language_id = $code;
192 $modelslang[$index][$key][$code]->value = $lang; 193 $modelslang[$index][$key][$code]->value = $lang;
193 } 194 }
194 } 195 }
@@ -205,12 +206,12 @@ class Option extends \yii\db\ActiveRecord @@ -205,12 +206,12 @@ class Option extends \yii\db\ActiveRecord
205 $newflag->model_id = $model_id; 206 $newflag->model_id = $model_id;
206 $newflag->name = 'is_new'; 207 $newflag->name = 'is_new';
207 $newflag->template = 'checkbox'; 208 $newflag->template = 'checkbox';
208 - $newflag->parent_id = $parentid; 209 + $newflag->option_pid = $parentid;
209 $newflag->translate = 0; 210 $newflag->translate = 0;
210 if($newflag->save()) { 211 if($newflag->save()) {
211 $newflaglang = new OptionLang(); 212 $newflaglang = new OptionLang();
212 - $newflaglang->id = $newflag->option_id;  
213 - $newflaglang->lang_id = 0; 213 + $newflaglang->option_id = $newflag->option_id;
  214 + $newflaglang->language_id = 0;
214 $newflaglang->value = '1'; 215 $newflaglang->value = '1';
215 if(!$newflaglang->save()) { 216 if(!$newflaglang->save()) {
216 $newflag->delete(); 217 $newflag->delete();
@@ -242,19 +243,19 @@ class Option extends \yii\db\ActiveRecord @@ -242,19 +243,19 @@ class Option extends \yii\db\ActiveRecord
242 } 243 }
243 244
244 public function getOptions() { 245 public function getOptions() {
245 - return $this->hasMany(Option::className(), ['parent_id' => 'option_id'])->indexBy('name'); 246 + return $this->hasMany(Option::className(), ['option_pid' => 'option_id'])->indexBy('name');
246 } 247 }
247 248
248 public function getOption() { 249 public function getOption() {
249 - return $this->hasOne(Option::className(), ['option_id' => 'parent_id']); 250 + return $this->hasOne(Option::className(), ['option_id' => 'option_pid']);
250 } 251 }
251 252
252 public function getOptionLangs() { 253 public function getOptionLangs() {
253 - return $this->hasMany(OptionLang::className(), ['id' => 'option_id']); 254 + return $this->hasMany(OptionLang::className(), ['option_id' => 'option_id']);
254 } 255 }
255 256
256 public function getOptionDefaultLang($array = false) { 257 public function getOptionDefaultLang($array = false) {
257 - $query = $this->getOptionLangs()->where(['lang_id' => 0]); 258 + $query = $this->getOptionLangs()->where(['language_id' => 0]);
258 if($array) { 259 if($array) {
259 $query->asArray(); 260 $query->asArray();
260 } 261 }
frontend/models/OptionLang.php
@@ -8,7 +8,7 @@ use Yii; @@ -8,7 +8,7 @@ use Yii;
8 * This is the model class for table "option_lang". 8 * This is the model class for table "option_lang".
9 * 9 *
10 * @property integer $id 10 * @property integer $id
11 - * @property integer $lang_id 11 + * @property integer $language_id
12 * @property string $value 12 * @property string $value
13 */ 13 */
14 class OptionLang extends \yii\db\ActiveRecord 14 class OptionLang extends \yii\db\ActiveRecord
@@ -27,8 +27,8 @@ class OptionLang extends \yii\db\ActiveRecord @@ -27,8 +27,8 @@ class OptionLang extends \yii\db\ActiveRecord
27 public function rules() 27 public function rules()
28 { 28 {
29 return [ 29 return [
30 - [['id', 'lang_id'], 'required'],  
31 - [['id', 'lang_id'], 'integer'], 30 + [['option_id', 'language_id'], 'required'],
  31 + [['option_id', 'language_id'], 'integer'],
32 [['value'], 'string'] 32 [['value'], 'string']
33 ]; 33 ];
34 } 34 }
@@ -39,8 +39,8 @@ class OptionLang extends \yii\db\ActiveRecord @@ -39,8 +39,8 @@ class OptionLang extends \yii\db\ActiveRecord
39 public function attributeLabels() 39 public function attributeLabels()
40 { 40 {
41 return [ 41 return [
42 - 'id' => Yii::t('app', 'ID'),  
43 - 'lang_id' => Yii::t('app', 'Lang ID'), 42 + 'option_id' => Yii::t('app', 'ID'),
  43 + 'language_id' => Yii::t('app', 'Lang ID'),
44 'value' => Yii::t('app', 'Value'), 44 'value' => Yii::t('app', 'Value'),
45 ]; 45 ];
46 } 46 }
frontend/models/OptionLangSearch.php
@@ -18,7 +18,7 @@ class OptionLangSearch extends OptionLang @@ -18,7 +18,7 @@ class OptionLangSearch extends OptionLang
18 public function rules() 18 public function rules()
19 { 19 {
20 return [ 20 return [
21 - [['primary', 'id', 'lang_id'], 'integer'], 21 + [['option_language_id', 'option_id', 'language_id'], 'integer'],
22 [['value'], 'safe'], 22 [['value'], 'safe'],
23 ]; 23 ];
24 } 24 }
@@ -56,9 +56,9 @@ class OptionLangSearch extends OptionLang @@ -56,9 +56,9 @@ class OptionLangSearch extends OptionLang
56 } 56 }
57 57
58 $query->andFilterWhere([ 58 $query->andFilterWhere([
59 - 'primary' => $this->primary,  
60 - 'id' => $this->id,  
61 - 'lang_id' => $this->lang_id, 59 + 'option_language_id' => $this->option_language_id,
  60 + 'option_id' => $this->option_id,
  61 + 'language_id' => $this->language_id,
62 ]); 62 ]);
63 63
64 $query->andFilterWhere(['like', 'value', $this->value]); 64 $query->andFilterWhere(['like', 'value', $this->value]);