Commit cf4b4fe7107e8bfad0c5ec3fa5d2cc7e2fe4f632
Merge remote-tracking branch 'origin/master'
Showing
23 changed files
with
394 additions
and
96 deletions
Show diff stats
backend/controllers/CatalogController.php
... | ... | @@ -85,7 +85,7 @@ class CatalogController extends Controller |
85 | 85 | { |
86 | 86 | $model = $this->findModel($id); |
87 | 87 | $model_lang = CatalogLang::find() |
88 | - ->where(['catalog' => $id, 'lang_id' => 1]) | |
88 | + ->where(['catalog_id' => $id, 'lang_id' => 1]) | |
89 | 89 | ->one(); |
90 | 90 | |
91 | 91 | if ($model->load(Yii::$app->request->post())) | ... | ... |
backend/controllers/MenuController.php
... | ... | @@ -66,8 +66,8 @@ class MenuController extends Controller |
66 | 66 | |
67 | 67 | $menu = yii::$app->db->createCommand(' |
68 | 68 | SELECT * |
69 | - FROM `menu` | |
70 | - LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id | |
69 | + FROM menu | |
70 | + LEFT JOIN termin_lang ON termin_lang.termin_id = menu.termin_id | |
71 | 71 | ')->queryAll(); |
72 | 72 | |
73 | 73 | |
... | ... | @@ -105,8 +105,8 @@ class MenuController extends Controller |
105 | 105 | $model = $this->findModel($id); |
106 | 106 | $menu = yii::$app->db->createCommand(' |
107 | 107 | SELECT * |
108 | - FROM `menu` | |
109 | - LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id | |
108 | + FROM menu | |
109 | + LEFT JOIN termin_lang ON termin_lang.termin_id = menu.termin_id | |
110 | 110 | ')->queryAll() + ['termin_id' => 0, 'termin_title' => 'ROOT']; |
111 | 111 | |
112 | 112 | ... | ... |
backend/models/SearchCatalog.php
... | ... | @@ -11,8 +11,12 @@ use common\models\Catalog; |
11 | 11 | * SearchCatalog represents the model behind the search form about `common\models\Catalog`. |
12 | 12 | */ |
13 | 13 | class SearchCatalog extends Catalog |
14 | -{ | |
15 | - public $title; | |
14 | +{ | |
15 | + /** | |
16 | + * для поиска | |
17 | + * @var $title | |
18 | + */ | |
19 | + var $title; | |
16 | 20 | |
17 | 21 | /** |
18 | 22 | * @inheritdoc |
... | ... | @@ -20,8 +24,7 @@ class SearchCatalog extends Catalog |
20 | 24 | public function rules() |
21 | 25 | { |
22 | 26 | return [ |
23 | - [['id', 'parent_id', 'type', 'subtype', 'status', 'sort'], 'integer'], | |
24 | - [['cover', 'options'], 'safe'], | |
27 | + [['catalog_id', 'parent_id', 'status', 'sort'], 'integer'], | |
25 | 28 | // + поиск по title |
26 | 29 | [['title'], 'safe'] |
27 | 30 | ]; |
... | ... | @@ -54,7 +57,7 @@ class SearchCatalog extends Catalog |
54 | 57 | // + поиск по title |
55 | 58 | $dataProvider->setSort([ |
56 | 59 | 'attributes' => [ |
57 | - 'id', | |
60 | + 'catalog_id', | |
58 | 61 | 'title' => [ |
59 | 62 | 'asc' => ['title' => SORT_ASC], |
60 | 63 | 'desc' => ['title' => SORT_DESC], |
... | ... | @@ -65,34 +68,31 @@ class SearchCatalog extends Catalog |
65 | 68 | ]); |
66 | 69 | |
67 | 70 | $this->load($params); |
71 | + | |
72 | + // + поиск по title | |
73 | + $query->joinWith(['relationCatalogLangPlus']); | |
68 | 74 | |
69 | 75 | if (!$this->validate()) |
70 | 76 | { |
71 | 77 | // uncomment the following line if you do not want to return any records when validation fails |
72 | 78 | // $query->where('0=1'); |
73 | - | |
74 | - // + поиск по title | |
75 | - $query->joinWith(['catalog_i18n']); | |
76 | - | |
79 | + | |
77 | 80 | return $dataProvider; |
78 | 81 | } |
79 | 82 | |
80 | 83 | $query->andFilterWhere([ |
81 | - 'id' => $this->id, | |
84 | + 'catalog_id' => $this->catalog_id, | |
82 | 85 | 'parent_id' => $this->parent_id, |
83 | - 'type' => $this->type, | |
84 | - 'subtype' => $this->subtype, | |
85 | 86 | 'status' => $this->status, |
86 | 87 | 'sort' => $this->sort, |
87 | 88 | ]); |
88 | 89 | |
89 | - $query->andFilterWhere(['like', 'cover', $this->cover]) | |
90 | - ->andFilterWhere(['like', 'options', $this->options]); | |
90 | + $query->andFilterWhere(['like', 'cover', $this->cover]); | |
91 | 91 | |
92 | 92 | // + поиск по title |
93 | 93 | if (! empty ($this->title)) |
94 | 94 | { |
95 | - $query->joinWith(['relationTable' => function ($q) | |
95 | + $query->joinWith(['relationCatalogLangPlus' => function ($q) | |
96 | 96 | { |
97 | 97 | $q->where(['like', 'catalog_i18n.title', $this->title]); |
98 | 98 | }]); | ... | ... |
backend/views/catalog/_form.php
... | ... | @@ -2,6 +2,8 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\widgets\ActiveForm; |
5 | +use yii\helpers\ArrayHelper; | |
6 | +use common\models\Catalog; | |
5 | 7 | |
6 | 8 | /* @var $this yii\web\View */ |
7 | 9 | /* @var $model common\models\Catalog */ |
... | ... | @@ -14,22 +16,37 @@ use yii\widgets\ActiveForm; |
14 | 16 | |
15 | 17 | <?= $form->field($model, 'title')->textInput() ?> |
16 | 18 | |
17 | - <?= $form->field($model, 'parent_id')->textInput() ?> | |
18 | - | |
19 | - <?= $form->field($model, 'type')->textInput() ?> | |
20 | - | |
21 | - <?= $form->field($model, 'subtype')->textInput() ?> | |
19 | + <?= $form->field($model, 'parent_id')->dropDownList( | |
20 | + ArrayHelper::map($model->find()->all(), 'parent_id', 'title') | |
21 | + ) | |
22 | + ?> | |
22 | 23 | |
23 | 24 | <?= $form->field($model, 'cover')->textInput(['maxlength' => true]) ?> |
25 | + | |
26 | + <?= $form->field($model, 'status')->dropDownList([ | |
27 | + '1' => Yii::t('action', 'show'), | |
28 | + '0' => Yii::t('action', 'hide'), | |
29 | + ]); | |
30 | + | |
31 | + echo '<pre>'; | |
32 | + | |
33 | + $array = $model->findInfo([ | |
34 | + 'catalog_id' => 1, | |
35 | + 'return_one' => true, | |
36 | + 'to_array' => false, | |
37 | + ]); | |
38 | + | |
39 | + var_dump($array->relationCatalogLang2->title); | |
40 | + //var_dump($array->relationCatalogLang2->title); | |
41 | + | |
42 | + echo '</pre>'; | |
24 | 43 | |
25 | - <?= $form->field($model, 'options')->textInput() ?> | |
26 | - | |
27 | - <?= $form->field($model, 'status')->textInput() ?> | |
44 | + ?> | |
28 | 45 | |
29 | 46 | <?= $form->field($model, 'sort')->textInput() ?> |
30 | 47 | |
31 | 48 | <div class="form-group"> |
32 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
49 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('action', 'add') : Yii::t('action', 'update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
33 | 50 | </div> |
34 | 51 | |
35 | 52 | <?php ActiveForm::end(); ?> | ... | ... |
backend/views/catalog/_search.php
... | ... | @@ -15,18 +15,12 @@ use yii\widgets\ActiveForm; |
15 | 15 | 'method' => 'get', |
16 | 16 | ]); ?> |
17 | 17 | |
18 | - <?= $form->field($model, 'id') ?> | |
18 | + <?= $form->field($model, 'catalog_id') ?> | |
19 | 19 | |
20 | 20 | <?= $form->field($model, 'parent_id') ?> |
21 | - | |
22 | - <?= $form->field($model, 'type') ?> | |
23 | - | |
24 | - <?= $form->field($model, 'subtype') ?> | |
25 | - | |
21 | + | |
26 | 22 | <?= $form->field($model, 'cover') ?> |
27 | - | |
28 | - <?php // echo $form->field($model, 'options') ?> | |
29 | - | |
23 | + | |
30 | 24 | <?php // echo $form->field($model, 'status') ?> |
31 | 25 | |
32 | 26 | <?php // echo $form->field($model, 'sort') ?> | ... | ... |
backend/views/catalog/index.php
... | ... | @@ -25,12 +25,9 @@ $this->params['breadcrumbs'][] = $this->title; |
25 | 25 | 'columns' => [ |
26 | 26 | ['class' => 'yii\grid\SerialColumn'], |
27 | 27 | |
28 | - 'id', | |
28 | + 'catalog_id', | |
29 | 29 | 'parent_id', |
30 | - 'title', | |
31 | - 'type', | |
32 | - 'subtype', | |
33 | - // 'options', | |
30 | + 'title', | |
34 | 31 | // 'status', |
35 | 32 | // 'sort', |
36 | 33 | ... | ... |
backend/views/catalog/update.php
... | ... | @@ -7,9 +7,9 @@ use yii\helpers\Html; |
7 | 7 | |
8 | 8 | $this->title = Yii::t('app', 'Update {modelClass}: ', [ |
9 | 9 | 'modelClass' => 'Catalog', |
10 | -]) . ' ' . $model->id; | |
10 | +]) . ' ' . $model->catalog_id; | |
11 | 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Catalogs'), 'url' => ['index']]; |
12 | -$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
12 | +$this->params['breadcrumbs'][] = ['label' => $model->catalog_id, 'url' => ['view', 'id' => $model->catalog_id]]; | |
13 | 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); |
14 | 14 | ?> |
15 | 15 | <div class="catalog-update"> | ... | ... |
backend/views/catalog/view.php
... | ... | @@ -6,7 +6,7 @@ use yii\widgets\DetailView; |
6 | 6 | /* @var $this yii\web\View */ |
7 | 7 | /* @var $model common\models\Catalog */ |
8 | 8 | |
9 | -$this->title = $model->id; | |
9 | +$this->title = $model->catalog_id; | |
10 | 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Catalogs'), 'url' => ['index']]; |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
... | ... | @@ -15,8 +15,8 @@ $this->params['breadcrumbs'][] = $this->title; |
15 | 15 | <h1><?= Html::encode($this->title) ?></h1> |
16 | 16 | |
17 | 17 | <p> |
18 | - <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
19 | - <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | |
18 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'catalog_id' => $model->catalog_id], ['class' => 'btn btn-primary']) ?> | |
19 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'catalog_id' => $model->catalog_id], [ | |
20 | 20 | 'class' => 'btn btn-danger', |
21 | 21 | 'data' => [ |
22 | 22 | 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), |
... | ... | @@ -28,12 +28,9 @@ $this->params['breadcrumbs'][] = $this->title; |
28 | 28 | <?= DetailView::widget([ |
29 | 29 | 'model' => $model, |
30 | 30 | 'attributes' => [ |
31 | - 'id', | |
32 | - 'parent_id', | |
33 | - 'type', | |
34 | - 'subtype', | |
35 | - 'cover', | |
36 | - 'options', | |
31 | + 'catalog_id', | |
32 | + 'parent_id', | |
33 | + 'cover', | |
37 | 34 | 'status', |
38 | 35 | 'sort', |
39 | 36 | ], | ... | ... |
backend/views/layouts/left.php
... | ... | @@ -30,9 +30,10 @@ |
30 | 30 | [ |
31 | 31 | 'options' => ['class' => 'sidebar-menu'], |
32 | 32 | 'items' => [ |
33 | - ['label' => Yii::t('app', 'Pages'), 'icon' => 'fa fa-file-code-o', 'url' => ['/page/']], | |
34 | - ['label' => 'Каталог', 'icon' => 'fa fa-file-code-o', 'url' => ['/catalog/']], | |
35 | - ['label' => 'Меню', 'icon' => 'fa fa-file-code-o', 'url' => ['/menu/']], | |
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/']], | |
36 | 37 | ['label' => 'Заявки', 'icon' => 'fa fa-file-code-o', 'url' => ['/site/requests/']], |
37 | 38 | ['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii']], |
38 | 39 | ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug']], | ... | ... |
common/models/Catalog.php
... | ... | @@ -3,21 +3,20 @@ |
3 | 3 | namespace common\models; |
4 | 4 | |
5 | 5 | use Yii; |
6 | +use yii\data\ActiveDataProvider; | |
6 | 7 | |
7 | 8 | /** |
8 | 9 | * This is the model class for table "catalog". |
9 | 10 | * |
10 | 11 | * @property integer $id |
11 | - * @property integer $parent_id | |
12 | - * @property integer $type | |
13 | - * @property integer $subtype | |
12 | + * @property integer $parent_id | |
14 | 13 | * @property string $cover |
15 | 14 | * @property string $options |
16 | 15 | * @property integer $status |
17 | 16 | * @property integer $sort |
18 | 17 | */ |
19 | 18 | class Catalog extends \yii\db\ActiveRecord |
20 | -{ | |
19 | +{ | |
21 | 20 | /** |
22 | 21 | * @inheritdoc |
23 | 22 | */ |
... | ... | @@ -32,40 +31,105 @@ class Catalog extends \yii\db\ActiveRecord |
32 | 31 | public function rules() |
33 | 32 | { |
34 | 33 | return [ |
35 | - [['parent_id', 'type', 'subtype', 'status', 'sort'], 'integer'], | |
36 | - [['options'], 'string'], | |
34 | + [['parent_id', 'status', 'sort'], 'integer'], | |
37 | 35 | [['cover'], 'string', 'max' => 32], |
38 | 36 | ]; |
39 | 37 | } |
40 | - | |
38 | + | |
41 | 39 | /** |
42 | 40 | * @inheritdoc |
43 | 41 | */ |
44 | 42 | public function attributeLabels() |
45 | 43 | { |
46 | 44 | return [ |
47 | - 'id' => Yii::t('app', 'ID'), | |
45 | + 'catalog_id' => Yii::t('app', 'ID'), | |
48 | 46 | 'parent_id' => Yii::t('app', 'Parent ID'), |
49 | - 'type' => Yii::t('app', 'Type'), | |
50 | - 'subtype' => Yii::t('app', 'Subtype'), | |
51 | - 'cover' => Yii::t('app', 'Cover'), | |
52 | - 'options' => Yii::t('app', 'Options'), | |
47 | + 'cover' => Yii::t('app', 'Cover'), | |
53 | 48 | 'status' => Yii::t('app', 'Status'), |
54 | 49 | 'sort' => Yii::t('app', 'Sort'), |
55 | 50 | ]; |
56 | 51 | } |
52 | + | |
53 | + /** | |
54 | + * Выполняет поиск по параметрам | |
55 | + * @param array $param принимает [catalog_id, lang_id, return_one, return_field, show_all] | |
56 | + * @return array one | array all | string значение масива | |
57 | + */ | |
58 | + public function finInfo (array $params = []) | |
59 | + { | |
60 | + Tools::ifNotExist ($params, array ( | |
61 | + 'catalog_id' => false, | |
62 | + 'lang_id' => false, | |
63 | + 'return_one' => false, | |
64 | + 'return_field' => false, | |
65 | + 'show_all' => false, | |
66 | + 'to_array' => true, | |
67 | + )); | |
68 | + | |
69 | + $model = new Catalog(); | |
70 | + | |
71 | + $query = $model->find()->select('*'); | |
72 | + | |
73 | + $query->joinWith(['relationCatalogLang2']); | |
74 | + | |
75 | + $WHERE = array (); | |
76 | + | |
77 | + if ($params['catalog_id'] !== false) | |
78 | + { | |
79 | + $WHERE['catalog.catalog_id'] = $params['catalog_id']; | |
80 | + } | |
81 | + | |
82 | + if ($params['lang_id'] !== false) | |
83 | + { | |
84 | + $WHERE['catalog_i18n.lang_id'] = $params['lang_id']; | |
85 | + } | |
86 | + | |
87 | + if (! empty ($WHERE)) | |
88 | + { | |
89 | + $query->where($WHERE); | |
90 | + } | |
91 | + | |
92 | + if ($params['to_array'] !== false) | |
93 | + { | |
94 | + $query = $query->asArray(); | |
95 | + } | |
96 | + | |
97 | + if ($params['return_one'] !== false || $params['return_field'] !== false) | |
98 | + { | |
99 | + | |
100 | + $result = $params['return_field'] !== false ? $query->one($params['return_field']) : $query->one(); | |
101 | + } | |
102 | + else | |
103 | + { | |
104 | + $result = $query->all(); | |
105 | + } | |
106 | + | |
107 | + return $result; | |
108 | + } | |
57 | 109 | |
58 | 110 | /** |
59 | 111 | * @return \yii\db\ActiveQuery |
60 | 112 | */ |
61 | - public function getRelationTable() | |
113 | + public function getRelationCatalogLangPlus() | |
114 | + { | |
115 | + return $this->getRelationCatalogLang2()->where(['lang_id' => yii::$app->params['lang_id']]); | |
116 | + } | |
117 | + | |
118 | + /** | |
119 | + * @return \yii\db\ActiveQuery | |
120 | + */ | |
121 | + public function getRelationCatalogLang2() | |
62 | 122 | { |
63 | - return $this->hasOne(CatalogLang::className(), ['catalog' => 'id']); | |
123 | + return $this->hasOne(CatalogLang::className(), ['catalog_id' => 'catalog_id']); | |
64 | 124 | } |
65 | - | |
125 | + | |
66 | 126 | public function getTitle() |
67 | 127 | { |
68 | - return $this->relationTable->title; | |
128 | + return $this->relationCatalogLangPlus->title; | |
129 | + } | |
130 | + | |
131 | + public function getParentTitle() | |
132 | + { | |
133 | + return $this->relationCatalogLangPlus->title; | |
69 | 134 | } |
70 | - | |
71 | 135 | } | ... | ... |
common/models/CatalogLang.php
... | ... | @@ -7,7 +7,7 @@ use Yii; |
7 | 7 | /** |
8 | 8 | * This is the model class for table "catalog_i18n". |
9 | 9 | * |
10 | - * @property integer $catalog | |
10 | + * @property integer $catalog_id | |
11 | 11 | * @property integer $lang_id |
12 | 12 | * @property string $title |
13 | 13 | * @property string $alias |
... | ... | @@ -32,8 +32,8 @@ class CatalogLang extends \yii\db\ActiveRecord |
32 | 32 | public function rules() |
33 | 33 | { |
34 | 34 | return [ |
35 | - [['catalog', 'lang_id', 'title', 'alias'], 'required'], | |
36 | - [['catalog', 'lang_id'], 'integer'], | |
35 | + [['catalog_id', 'lang_id', 'title', 'alias'], 'required'], | |
36 | + [['catalog_id', 'lang_id'], 'integer'], | |
37 | 37 | [['title'], 'string', 'max' => 1024], |
38 | 38 | [['alias'], 'string', 'max' => 128], |
39 | 39 | [['meta_title', 'meta_keywords', 'meta_description', 'full_alias'], 'string', 'max' => 255], |
... | ... | @@ -47,7 +47,7 @@ class CatalogLang extends \yii\db\ActiveRecord |
47 | 47 | public function attributeLabels() |
48 | 48 | { |
49 | 49 | return [ |
50 | - 'catalog' => Yii::t('app', 'Catalog'), | |
50 | + 'catalog_id' => Yii::t('app', 'catalog_id'), | |
51 | 51 | 'lang_id' => Yii::t('app', 'Lang ID'), |
52 | 52 | 'title' => Yii::t('app', 'Title'), |
53 | 53 | 'alias' => Yii::t('app', 'Alias'), | ... | ... |
common/models/Menu.php
... | ... | @@ -22,25 +22,23 @@ class Menu extends \yii\db\ActiveRecord |
22 | 22 | { |
23 | 23 | return yii::$app->db->createCommand(' |
24 | 24 | SELECT |
25 | - `menu`.menu_id, `menu`.menu_pid, `menu`.level, | |
26 | - `termin_lang`.termin_title, `termin_lang`.termin_alias, | |
27 | - `template`.template_file | |
28 | - FROM `menu` | |
29 | - INNER JOIN `menu_location` ON `menu_location`.menu_location_id = `menu`.menu_location_id | |
30 | - AND `menu_location`.menu_location_name = "'.$location_name.'" | |
31 | - INNER JOIN `termin` ON `termin`.termin_id = `menu`.termin_id | |
32 | - INNER JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id | |
33 | - AND `termin_lang`.lang_id = '.yii::$app->params['lang_id.'].' | |
34 | - INNER JOIN `template` ON `template`.template_id = `termin_lang`.template_id | |
35 | - ORDER BY `menu`.level ASC, `menu`.sortorder ASC | |
25 | + menu.menu_id, menu.menu_pid, menu.level, | |
26 | + termin_lang.termin_title, termin_lang.termin_alias | |
27 | + FROM menu | |
28 | + INNER JOIN menu_location ON menu_location.menu_location_id = menu.menu_location_id | |
29 | + AND menu_location.menu_location_name = \''.$location_name.'\' | |
30 | + INNER JOIN termin ON termin.termin_id = menu.termin_id | |
31 | + INNER JOIN termin_lang ON termin_lang.termin_id = menu.termin_id | |
32 | + AND termin_lang.lang_id = '.Yii::$app->params['lang_id'].' | |
33 | + ORDER BY menu.level ASC, menu.sortorder ASC | |
36 | 34 | ')->queryAll(); |
37 | 35 | /* |
38 | 36 | return $this->find() |
39 | - ->selectOption('`termin_lang`.termin_title') | |
37 | + ->selectOption('termin_lang.termin_title') | |
40 | 38 | ->from('menu') |
41 | 39 | ->join( |
42 | 40 | 'INNER JOIN', |
43 | - '`termin_lang`.termin_id = `menu`.termin_id', | |
41 | + 'termin_lang.termin_id = menu.termin_id', | |
44 | 42 | ['lang_id' => yii::$app->params['lang_id']]) |
45 | 43 | ->all(); |
46 | 44 | */ | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | +use yii\db\Query; | |
8 | + | |
9 | +/** | |
10 | + * Signup form | |
11 | + */ | |
12 | +class ShopCategory extends Model | |
13 | +{ | |
14 | + /** | |
15 | + * весь список терминов | |
16 | + */ | |
17 | + static function get () | |
18 | + { | |
19 | + return yii::$app->db->createCommand(' | |
20 | + SELECT | |
21 | + termin_structure.termin_id, | |
22 | + termin_structure.termin_pid, | |
23 | + termin_lang.termin_title | |
24 | + FROM termin_structure | |
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'].' | |
27 | + ORDER BY termin_structure.termin_id ASC, termin_structure.termin_pid ASC | |
28 | + ')->queryAll(); | |
29 | + } | |
30 | + | |
31 | + // =================== | |
32 | + // ==== STRUCTURE ==== | |
33 | + // =================== | |
34 | + | |
35 | + var $mass = array (); | |
36 | + | |
37 | + public function build () | |
38 | + { | |
39 | + if ($this->mass = self::get ()) | |
40 | + { | |
41 | + return $this->getRecrusive (8); | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + public function findChild ($id) | |
46 | + { | |
47 | + $mass = array (); | |
48 | + | |
49 | + foreach ($this->mass as $row) | |
50 | + { | |
51 | + if ($row['termin_pid'] == $id) | |
52 | + { | |
53 | + $mass[] = $row; | |
54 | + } | |
55 | + } | |
56 | + | |
57 | + return $mass; | |
58 | + } | |
59 | + | |
60 | + public function getRecrusive ($menu_id) | |
61 | + { | |
62 | + $items = $this->findChild($menu_id); | |
63 | + | |
64 | + if (! empty ($items)) | |
65 | + { | |
66 | + echo '<ul>'; | |
67 | + | |
68 | + foreach ($items as $row) | |
69 | + { | |
70 | + echo '<li>'.$row['termin_title'].'</li>'; | |
71 | + | |
72 | + if ($row['termin_pid'] != 0) | |
73 | + { | |
74 | + $this->getRecrusive($row['termin_id']); | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + echo '</ul>'; | |
79 | + } | |
80 | + | |
81 | + } | |
82 | + | |
83 | + // ===== | |
84 | + | |
85 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "social". | |
9 | + * | |
10 | + * @property integer $social_id | |
11 | + * @property string $social_name | |
12 | + * @property integer $social_user_id | |
13 | + * @property integer $user_id | |
14 | + */ | |
15 | +class Social extends \yii\db\ActiveRecord | |
16 | +{ | |
17 | + /** | |
18 | + * @inheritdoc | |
19 | + */ | |
20 | + public static function tableName() | |
21 | + { | |
22 | + return 'social'; | |
23 | + } | |
24 | + | |
25 | + /** | |
26 | + * @inheritdoc | |
27 | + */ | |
28 | + public function rules() | |
29 | + { | |
30 | + return [ | |
31 | + [['social_user_id', 'user_id'], 'integer'], | |
32 | + [['social_name'], 'string', 'max' => 255] | |
33 | + ]; | |
34 | + } | |
35 | + | |
36 | + /** | |
37 | + * @inheritdoc | |
38 | + */ | |
39 | + public function attributeLabels() | |
40 | + { | |
41 | + return [ | |
42 | + 'social_id' => Yii::t('app', 'Social ID'), | |
43 | + 'social_name' => Yii::t('app', 'Social Name'), | |
44 | + 'social_user_id' => Yii::t('app', 'Social User ID'), | |
45 | + 'user_id' => Yii::t('app', 'User ID'), | |
46 | + ]; | |
47 | + } | |
48 | +} | ... | ... |
common/translation/ru/action.php
db-migration/artbox_db.backup
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
1 | +<?php | |
2 | +namespace frontend\controllers; | |
3 | + | |
4 | +use Yii; | |
5 | +use common\models\LoginForm; | |
6 | +use frontend\models\PasswordResetRequestForm; | |
7 | +use frontend\models\ResetPasswordForm; | |
8 | +use frontend\models\SignupForm; | |
9 | +use frontend\models\ContactForm; | |
10 | +use frontend\models\Options; | |
11 | +use frontend\models\OptionValues; | |
12 | +use yii\base\InvalidParamException; | |
13 | +use yii\web\BadRequestHttpException; | |
14 | +use yii\web\Controller; | |
15 | +use yii\filters\VerbFilter; | |
16 | +use yii\filters\AccessControl; | |
17 | +use frontend\models\OptionsToValues; | |
18 | +use yii\validators\EmailValidator; | |
19 | +use common\models\User; | |
20 | +use yii\helpers\VarDumper; | |
21 | +use common\models\Page; | |
22 | +use frontend\models\Option; | |
23 | +use common\models\Social; | |
24 | + | |
25 | + | |
26 | +/** | |
27 | + * Site controller | |
28 | + */ | |
29 | +class CatalogController extends Controller | |
30 | +{ | |
31 | + /** | |
32 | + * @inheritdoc | |
33 | + */ | |
34 | + public function behaviors() | |
35 | + { | |
36 | + return [ | |
37 | + 'verbs' => [ | |
38 | + 'class' => VerbFilter::className(), | |
39 | + 'actions' => [ | |
40 | + 'delete' => ['post'], | |
41 | + ], | |
42 | + ], | |
43 | + ]; | |
44 | + } | |
45 | + | |
46 | + /** | |
47 | + * @inheritdoc | |
48 | + */ | |
49 | + public function actions() | |
50 | + { | |
51 | + return [ | |
52 | + 'error' => [ | |
53 | + 'class' => 'yii\web\ErrorAction', | |
54 | + ], | |
55 | + 'captcha' => [ | |
56 | + 'class' => 'yii\captcha\CaptchaAction', | |
57 | + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | |
58 | + ], | |
59 | + ]; | |
60 | + } | |
61 | + | |
62 | + /** | |
63 | + * Displays homepage. | |
64 | + * | |
65 | + * @return mixed | |
66 | + */ | |
67 | + public function actionIndex() | |
68 | + { | |
69 | + return $this->render('index'); | |
70 | + } | |
71 | + | |
72 | +} | ... | ... |
frontend/controllers/SiteController.php
... | ... | @@ -20,6 +20,8 @@ use common\models\User; |
20 | 20 | use yii\helpers\VarDumper; |
21 | 21 | use common\models\Page; |
22 | 22 | use frontend\models\Option; |
23 | +use common\models\Social; | |
24 | + | |
23 | 25 | |
24 | 26 | /** |
25 | 27 | * Site controller |
... | ... | @@ -101,8 +103,13 @@ class SiteController extends Controller |
101 | 103 | */ |
102 | 104 | public function actionLogin() |
103 | 105 | { |
106 | + | |
107 | + // creat new model table Social and new model User | |
108 | + $social = new Social(); | |
109 | + $user = new User(); | |
104 | 110 | |
105 | 111 | $serviceName = Yii::$app->getRequest()->getQueryParam('service'); |
112 | + | |
106 | 113 | if (isset($serviceName)) { |
107 | 114 | /** @var $eauth \nodge\eauth\ServiceBase */ |
108 | 115 | $eauth = Yii::$app->get('eauth')->getIdentity($serviceName); |
... | ... | @@ -111,11 +118,24 @@ class SiteController extends Controller |
111 | 118 | |
112 | 119 | try { |
113 | 120 | if ($eauth->authenticate()) { |
114 | -// var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit; | |
115 | - | |
116 | 121 | $identity = User::findByEAuth($eauth); |
117 | 122 | Yii::$app->getUser()->login($identity); |
118 | 123 | |
124 | + //Save date get social network in database | |
125 | + if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) { | |
126 | + $name = explode(' ',$identity[profile][name]); | |
127 | + $user->firstname = $name[0]; | |
128 | + $user->lastname = $name[1]; | |
129 | + $user->id_system_date = date("d.m.y.H:i:s"); | |
130 | + $user->save(); | |
131 | + $social->social_name = $identity[profile][service]; | |
132 | + $social->social_user_id = $identity[profile][id]; | |
133 | + $social->user_id = $user->id; | |
134 | + $social->validate(); | |
135 | + $social->errors; | |
136 | + $social->save(); | |
137 | + } | |
138 | + | |
119 | 139 | // special redirect with closing popup window |
120 | 140 | $eauth->redirect(); |
121 | 141 | } |
... | ... | @@ -170,7 +190,6 @@ class SiteController extends Controller |
170 | 190 | */ |
171 | 191 | public function actionContact() |
172 | 192 | { |
173 | - | |
174 | 193 | //Yii::$app->user->logout(); |
175 | 194 | $identity = Yii::$app->getUser()->getIdentity(); |
176 | 195 | var_dump($identity[profile]); | ... | ... |
frontend/views/layouts/main.php
... | ... | @@ -35,11 +35,11 @@ AppAsset::register($this); |
35 | 35 | ] |
36 | 36 | ]); |
37 | 37 | |
38 | -/* | |
39 | 38 | echo Nav::widget([ |
40 | 39 | 'options' => ['class' => 'navbar-nav navbar-right'], |
41 | 40 | 'items' => (new MenuTree())->build('TOP') |
42 | 41 | ]); |
42 | +/* | |
43 | 43 | |
44 | 44 | $menuItems = [ |
45 | 45 | ['label' => 'Home', 'url' => ['/site/index']], | ... | ... |