Commit 9f55ae516dbd5aa209e269404000ef1deac60da3
1 parent
fead6679
big shot
Showing
76 changed files
with
854 additions
and
14 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace backend\controllers; | |
4 | + | |
5 | +use common\models\Slider; | |
6 | +use Yii; | |
7 | +use common\models\Objectkb; | |
8 | +use common\models\ObjectkbSearch; | |
9 | +use yii\web\Controller; | |
10 | +use yii\web\NotFoundHttpException; | |
11 | +use yii\filters\VerbFilter; | |
12 | + | |
13 | +/** | |
14 | + * ObjectkbController implements the CRUD actions for Objectkb model. | |
15 | + */ | |
16 | +class ObjectkbController extends Controller | |
17 | +{ | |
18 | + protected $allSliders; | |
19 | + | |
20 | + public function init() | |
21 | + { | |
22 | + parent::init(); // TODO: Change the autogenerated stub | |
23 | + | |
24 | + $this->allSliders = Slider::find()->all(); | |
25 | + | |
26 | + } | |
27 | + /** | |
28 | + * @inheritdoc | |
29 | + */ | |
30 | + public function behaviors() | |
31 | + { | |
32 | + return [ | |
33 | + 'verbs' => [ | |
34 | + 'class' => VerbFilter::className(), | |
35 | + 'actions' => [ | |
36 | + 'delete' => ['POST'], | |
37 | + ], | |
38 | + ], | |
39 | + ]; | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * Lists all Objectkb models. | |
44 | + * @return mixed | |
45 | + */ | |
46 | + public function actionIndex() | |
47 | + { | |
48 | + $searchModel = new ObjectkbSearch(); | |
49 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
50 | + | |
51 | + return $this->render('index', [ | |
52 | + 'searchModel' => $searchModel, | |
53 | + 'dataProvider' => $dataProvider, | |
54 | + ]); | |
55 | + } | |
56 | + | |
57 | + /** | |
58 | + * Displays a single Objectkb model. | |
59 | + * @param integer $id | |
60 | + * @return mixed | |
61 | + */ | |
62 | + public function actionView($id) | |
63 | + { | |
64 | + return $this->render('view', [ | |
65 | + 'model' => $this->findModel($id), | |
66 | + ]); | |
67 | + } | |
68 | + | |
69 | + /** | |
70 | + * Creates a new Objectkb model. | |
71 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
72 | + * @return mixed | |
73 | + */ | |
74 | + public function actionCreate() | |
75 | + { | |
76 | + $model = new Objectkb(); | |
77 | + $sliders = $this->allSliders; | |
78 | + $model->generateLangs(); | |
79 | + | |
80 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
81 | + return $this->redirect( | |
82 | + [ | |
83 | + 'view', | |
84 | + 'id' => $model->id, | |
85 | + ] | |
86 | + ); | |
87 | + } else { | |
88 | + return $this->render( | |
89 | + 'create', | |
90 | + [ | |
91 | + 'model' => $model, | |
92 | + 'modelLangs' => $model->modelLangs, | |
93 | + 'sliders' => $sliders, | |
94 | + ] | |
95 | + ); | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + /** | |
100 | + * Updates an existing Objectkb model. | |
101 | + * If update is successful, the browser will be redirected to the 'view' page. | |
102 | + * @param integer $id | |
103 | + * @return mixed | |
104 | + */ | |
105 | + public function actionUpdate($id) | |
106 | + { | |
107 | + $model = $this->findModel($id); | |
108 | + $model->generateLangs(); | |
109 | + | |
110 | + if ($model->loadWithLangs(\Yii::$app->request)) { | |
111 | + if ($model->saveWithLangs()) { | |
112 | + return $this->redirect( | |
113 | + [ | |
114 | + 'view', | |
115 | + 'id' => $model->id, | |
116 | + ] | |
117 | + ); | |
118 | + } | |
119 | + } | |
120 | + | |
121 | + return $this->render('update', [ | |
122 | + 'model' => $model, | |
123 | + 'modelLangs' => $model->modelLangs, | |
124 | + 'sliders' => $this->allSliders, | |
125 | + ]); | |
126 | + | |
127 | + } | |
128 | + | |
129 | + /** | |
130 | + * Deletes an existing Objectkb model. | |
131 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
132 | + * @param integer $id | |
133 | + * @return mixed | |
134 | + */ | |
135 | + public function actionDelete($id) | |
136 | + { | |
137 | + $this->findModel($id)->delete(); | |
138 | + | |
139 | + return $this->redirect(['index']); | |
140 | + } | |
141 | + | |
142 | + /** | |
143 | + * Finds the Objectkb model based on its primary key value. | |
144 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
145 | + * @param integer $id | |
146 | + * @return Objectkb the loaded model | |
147 | + * @throws NotFoundHttpException if the model cannot be found | |
148 | + */ | |
149 | + protected function findModel($id) | |
150 | + { | |
151 | + if (($model = Objectkb::findOne($id)) !== null) { | |
152 | + return $model; | |
153 | + } else { | |
154 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
155 | + } | |
156 | + } | |
157 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use yii\helpers\Html; | |
4 | + use yii\widgets\ActiveForm; | |
5 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | |
6 | + use artbox\core\widgets\LanguageForm; | |
7 | + | |
8 | + /** | |
9 | + * @var \yii\web\View $this | |
10 | + * @var \common\models\Objectkb $model | |
11 | + * @var \common\models\ObjectkbLang[] $modelLangs | |
12 | + * @var \common\models\Slider[] $sliders | |
13 | + */ | |
14 | +?> | |
15 | + | |
16 | +<div class="objectkb-form"> | |
17 | + | |
18 | + <?php | |
19 | + $items = []; | |
20 | + // $items['defValue'] = "choose slider"; | |
21 | + | |
22 | + foreach ($sliders as $slider) { | |
23 | + $items[ "{$slider->id}" ] = $slider->slider_name; | |
24 | + } | |
25 | + | |
26 | + $form = ActiveForm::begin(); | |
27 | + ?> | |
28 | + | |
29 | + <?= $form->field($model, 'slider_id') | |
30 | + ->dropDownList( | |
31 | + $items, | |
32 | + [ | |
33 | + 'prompt' => [ | |
34 | + 'text' => 'Please select', | |
35 | + 'options' => [ | |
36 | + 'value' => 'none', | |
37 | + 'class' => 'prompt', | |
38 | + 'label' => 'Select slider by name', | |
39 | + ], | |
40 | + ], | |
41 | + ] | |
42 | + ) ?> | |
43 | + | |
44 | + <?= LanguageForm::widget( | |
45 | + [ | |
46 | + 'modelLangs' => $modelLangs, | |
47 | + 'formView' => '@backend/views/objectkb/_form_language', | |
48 | + 'form' => $form, | |
49 | + ] | |
50 | + ) ?> | |
51 | + | |
52 | + <?= $form->field($model, 'sort') | |
53 | + ->textInput() ?> | |
54 | + | |
55 | + <?= $form->field($model, 'image_mini_id') | |
56 | + ->widget( | |
57 | + ImageManagerInputWidget::className(), | |
58 | + [ | |
59 | + 'aspectRatio' => ( 16 / 9 ), | |
60 | + //set the aspect ratio | |
61 | + 'showPreview' => true, | |
62 | + //false to hide the preview | |
63 | + 'showDeletePickedImageConfirm' => false, | |
64 | + //on true show warning before detach image | |
65 | + ] | |
66 | + ) | |
67 | + ?> | |
68 | + | |
69 | + <?= $form->field($model, 'status') | |
70 | + ->checkbox() ?> | |
71 | + | |
72 | + <div class="form-group"> | |
73 | + <?= Html::submitButton( | |
74 | + $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), | |
75 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
76 | + ) ?> | |
77 | + </div> | |
78 | + | |
79 | + <?php ActiveForm::end(); ?> | |
80 | + | |
81 | +</div> | ... | ... |
1 | +<?php | |
2 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | |
3 | + use artbox\core\models\Language; | |
4 | + use dosamigos\tinymce\TinyMce; | |
5 | + use yii\web\View; | |
6 | + use yii\widgets\ActiveForm; | |
7 | + | |
8 | + /** | |
9 | + * @var \artbox\core\models\SlideLang $model_lang | |
10 | + * @var Language $language | |
11 | + * @var ActiveForm $form | |
12 | + * @var View $this | |
13 | + */ | |
14 | + echo $form->field($model_lang, '[' . $language->id . ']aliasValue') | |
15 | + ->textInput(); | |
16 | + | |
17 | + echo $form->field($model_lang, '[' . $language->id . ']upper_text') | |
18 | + ->textInput([ 'maxlength' => true ]); | |
19 | + | |
20 | + echo $form->field($model_lang, '[' . $language->id . ']about_object_text') | |
21 | + ->textInput([ 'maxlength' => true ]); | |
22 | + | |
23 | + echo $form->field($model_lang, '[' . $language->id . ']object_name') | |
24 | + ->textInput([ 'maxlength' => true ]); | |
25 | + | |
26 | + echo $form->field($model_lang, '[' . $language->id . ']meta_title') | |
27 | + ->textInput([ 'maxlength' => true ]); | |
28 | + | |
29 | + echo $form->field($model_lang, '[' . $language->id . ']meta_description') | |
30 | + ->textInput([ 'maxlength' => true ]); | |
31 | + | |
32 | + echo $form->field($model_lang, '[' . $language->id . ']h1') | |
33 | + ->textInput([ 'maxlength' => true ]); | |
34 | + | |
35 | + | |
36 | +?> | |
0 | 37 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\ObjectkbSearch */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="objectkb-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, 'slider_id') ?> | |
21 | + | |
22 | + <?= $form->field($model, 'status')->checkbox() ?> | |
23 | + | |
24 | + <?= $form->field($model, 'sort') ?> | |
25 | + | |
26 | + <?= $form->field($model, 'image_mini_id') ?> | |
27 | + | |
28 | + <div class="form-group"> | |
29 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
30 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
31 | + </div> | |
32 | + | |
33 | + <?php ActiveForm::end(); ?> | |
34 | + | |
35 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | + /** | |
6 | + * @var \yii\web\View $this | |
7 | + * @var \common\models\Objectkb $model | |
8 | + * @var \common\models\ObjectkbLang $modelLangs | |
9 | + * @var \common\models\Slider[] $sliders | |
10 | + */ | |
11 | +$this->title = Yii::t('app', 'Create Objectkb'); | |
12 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Objectkbs'), 'url' => ['index']]; | |
13 | +$this->params['breadcrumbs'][] = $this->title; | |
14 | +?> | |
15 | +<div class="objectkb-create"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + | |
19 | + <?= $this->render('_form', [ | |
20 | + 'model' => $model, | |
21 | + 'modelLangs' => $modelLangs, | |
22 | + 'sliders' => $sliders, | |
23 | + ]) ?> | |
24 | + | |
25 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | +use yii\widgets\Pjax; | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $searchModel common\models\ObjectkbSearch */ | |
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
9 | + | |
10 | +$this->title = Yii::t('app', 'Objectkbs'); | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="objectkb-index"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
17 | + | |
18 | + <p> | |
19 | + <?= Html::a(Yii::t('app', 'Create Objectkb'), ['create'], ['class' => 'btn btn-success']) ?> | |
20 | + </p> | |
21 | +<?php Pjax::begin(); ?> <?= GridView::widget([ | |
22 | + 'dataProvider' => $dataProvider, | |
23 | + 'filterModel' => $searchModel, | |
24 | + 'columns' => [ | |
25 | + ['class' => 'yii\grid\SerialColumn'], | |
26 | + | |
27 | + 'id', | |
28 | + 'slider_id', | |
29 | + 'status:boolean', | |
30 | + 'sort', | |
31 | + 'image_mini_id', | |
32 | + | |
33 | + ['class' => 'yii\grid\ActionColumn'], | |
34 | + ], | |
35 | + ]); ?> | |
36 | +<?php Pjax::end(); ?></div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/** | |
6 | + * @var $this yii\web\View | |
7 | + * @var $model common\models\Objectkb | |
8 | + * @var \common\models\ObjectkbLang $modelLangs | |
9 | + * @var \common\models\Slider[] $sliders | |
10 | + */ | |
11 | + | |
12 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
13 | + 'modelClass' => 'Objectkb', | |
14 | +]) . $model->id; | |
15 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Objectkbs'), 'url' => ['index']]; | |
16 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
17 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | |
18 | +?> | |
19 | +<div class="objectkb-update"> | |
20 | + | |
21 | + <h1><?= Html::encode($this->title) ?></h1> | |
22 | + | |
23 | + <?= $this->render('_form', [ | |
24 | + 'model' => $model, | |
25 | + 'modelLangs' => $modelLangs, | |
26 | + 'sliders' => $sliders, | |
27 | + ]) ?> | |
28 | + | |
29 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Objectkb */ | |
8 | + | |
9 | +$this->title = $model->id; | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Objectkbs'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="objectkb-view"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
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], [ | |
20 | + 'class' => 'btn btn-danger', | |
21 | + 'data' => [ | |
22 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | |
23 | + 'method' => 'post', | |
24 | + ], | |
25 | + ]) ?> | |
26 | + </p> | |
27 | + | |
28 | + <?= DetailView::widget([ | |
29 | + 'model' => $model, | |
30 | + 'attributes' => [ | |
31 | + 'id', | |
32 | + 'slider_id', | |
33 | + 'status:boolean', | |
34 | + 'sort', | |
35 | + 'image_mini_id', | |
36 | + ], | |
37 | + ]) ?> | |
38 | + | |
39 | +</div> | ... | ... |
backend/views/slider/_form.php
1 | 1 | <?php |
2 | 2 | |
3 | - use backend\models\Slider; | |
3 | + use common\models\Slider; | |
4 | 4 | use yii\helpers\Html; |
5 | 5 | use yii\widgets\ActiveForm; |
6 | 6 | |
... | ... | @@ -25,8 +25,11 @@ |
25 | 25 | ->checkbox([ |
26 | 26 | 'class' => 'flat', |
27 | 27 | ]) ?> |
28 | - | |
29 | - <div class="form-group"> | |
28 | + | |
29 | + <?= $form->field($model, 'slider_name')->textInput() ?> | |
30 | + | |
31 | + | |
32 | + <div class="form-group"> | |
30 | 33 | <?= Html::submitButton( |
31 | 34 | $model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), |
32 | 35 | [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ... | ... |
backend/views/slider/index.php
1 | 1 | <?php |
2 | 2 | |
3 | - use artbox\core\models\SliderSearch; | |
3 | + use common\models\SliderSearch; | |
4 | 4 | use yii\helpers\Html; |
5 | 5 | use yii\grid\GridView; |
6 | 6 | |
... | ... | @@ -26,7 +26,8 @@ |
26 | 26 | 'columns' => [ |
27 | 27 | [ 'class' => 'yii\grid\SerialColumn' ], |
28 | 28 | |
29 | - 'id', | |
29 | + 'id:integer', | |
30 | + 'slider_name:text', | |
30 | 31 | 'status:boolean', |
31 | 32 | [ |
32 | 33 | 'attribute' => 'sort', | ... | ... |
No preview for this file type
1 | +<?php | |
2 | + | |
3 | + namespace common\models; | |
4 | + | |
5 | + use yii\db\ActiveRecord; | |
6 | + use artbox\core\behaviors\LanguageBehavior; | |
7 | + use artbox\core\models\Image; | |
8 | + use Yii; | |
9 | + | |
10 | + /** | |
11 | + * Created by PhpStorm. | |
12 | + * User: timur | |
13 | + * Date: 25.01.18 | |
14 | + * Time: 12:46 | |
15 | + */ | |
16 | + class Objectkb extends ActiveRecord | |
17 | + { | |
18 | + /** | |
19 | + * @inheritdoc | |
20 | + */ | |
21 | + public static function tableName() | |
22 | + { | |
23 | + return 'object'; | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public function behaviors() | |
30 | + { | |
31 | + return [ | |
32 | + 'language' => [ | |
33 | + 'class' => LanguageBehavior::className(), | |
34 | + ], | |
35 | + ]; | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * @inheritdoc | |
40 | + */ | |
41 | + public function rules() | |
42 | + { | |
43 | + return [ | |
44 | + [ | |
45 | + [ | |
46 | + 'slider_id', | |
47 | + 'image_mini_id', | |
48 | + ], | |
49 | + 'required', | |
50 | + ], | |
51 | + [ | |
52 | + [ | |
53 | + 'slider_id', | |
54 | + 'sort', | |
55 | + ], | |
56 | + 'integer', | |
57 | + ], | |
58 | + [ | |
59 | + [ 'status' ], | |
60 | + 'boolean', | |
61 | + ], | |
62 | + [ | |
63 | + [ 'slider_id' ], | |
64 | + 'exist', | |
65 | + 'skipOnError' => true, | |
66 | + 'targetClass' => Slider::className(), | |
67 | + 'targetAttribute' => [ 'slider_id' => 'id' ], | |
68 | + ], | |
69 | + [ | |
70 | + [ 'image_mini_id' ], | |
71 | + 'exist', | |
72 | + 'skipOnError' => true, | |
73 | + 'targetClass' => Image::className(), | |
74 | + 'targetAttribute' => [ 'image_mini_id' => 'id' ], | |
75 | + ], | |
76 | + ]; | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * @inheritdoc | |
81 | + */ | |
82 | + public function attributeLabels() | |
83 | + { | |
84 | + return [ | |
85 | + 'id' => Yii::t('core', 'ID'), | |
86 | + 'slider_id' => Yii::t('core', 'Slider ID'), | |
87 | + 'status' => Yii::t('core', 'Status'), | |
88 | + 'sort' => Yii::t('core', 'Sort'), | |
89 | + 'image_mini_id' => Yii::t('core', 'Image Mini'), | |
90 | + ]; | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * @return \yii\db\ActiveQuery | |
95 | + */ | |
96 | + public function getImage() | |
97 | + { | |
98 | + return $this->hasOne(Image::className(), [ 'id' => 'image_mini_id' ]); | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * @return \yii\db\ActiveQuery | |
103 | + */ | |
104 | + public function getSlider() | |
105 | + { | |
106 | + return $this->hasOne(Slider::className(), [ 'id' => 'slider_id' ]) | |
107 | + ->inverseOf('slides'); | |
108 | + } | |
109 | + } | |
0 | 110 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | + | |
3 | + namespace common\models; | |
4 | + | |
5 | + use yii\db\ActiveRecord; | |
6 | + use artbox\core\models\Language; | |
7 | + use artbox\core\models\Alias; | |
8 | + use Yii; | |
9 | + use artbox\core\behaviors\SlugBehavior; | |
10 | + | |
11 | + /** | |
12 | + * User: timur | |
13 | + * Date: 25.01.18 | |
14 | + * Time: 12:58 | |
15 | + */ | |
16 | + class ObjectkbLang extends ActiveRecord | |
17 | + { | |
18 | + | |
19 | + /** | |
20 | + * @return string | |
21 | + */ | |
22 | + public static function tableName() | |
23 | + { | |
24 | + return "object_lang"; | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * @inheritdoc | |
29 | + */ | |
30 | + public function behaviors() | |
31 | + { | |
32 | + return [ | |
33 | + 'slug' => [ | |
34 | + 'class' => SlugBehavior::className(), | |
35 | + 'action' => 'objectkb/view', | |
36 | + 'params' => [ | |
37 | + 'id' => 'object_id', | |
38 | + ], | |
39 | + 'fields' => [ | |
40 | + 'object_name' => 'Object name', | |
41 | + 'object.id' => 'Object id', | |
42 | + 'upper_text' => 'Object upper text', | |
43 | + 'about_object_text' => 'About Object text', | |
44 | + 'object.lang.object_name' => 'some stuf', | |
45 | + ], | |
46 | + ], | |
47 | + ]; | |
48 | + } | |
49 | + | |
50 | + /** | |
51 | + * @return array | |
52 | + */ | |
53 | + public function rules() | |
54 | + { | |
55 | + return [ | |
56 | + [ | |
57 | + [ | |
58 | + 'object_id', | |
59 | + 'language_id', | |
60 | + 'upper_text', | |
61 | + 'about_object_text', | |
62 | + 'object_name', | |
63 | + 'meta_title', | |
64 | + 'meta_description', | |
65 | + 'h1', | |
66 | + ], | |
67 | + 'required', | |
68 | + ], | |
69 | + [ | |
70 | + [ | |
71 | + 'object_id', | |
72 | + 'language_id', | |
73 | + ], | |
74 | + 'integer', | |
75 | + ], | |
76 | + [ | |
77 | + [ | |
78 | + 'aliasValue', | |
79 | + 'upper_text', | |
80 | + 'about_object_text', | |
81 | + 'object_name', | |
82 | + 'meta_title', | |
83 | + 'meta_description', | |
84 | + 'h1', | |
85 | + ], | |
86 | + 'string', | |
87 | + ], | |
88 | + [ | |
89 | + [ 'object_id' ], | |
90 | + 'exist', | |
91 | + 'skipOnError' => true, | |
92 | + 'targetClass' => Objectkb::className(), | |
93 | + 'targetAttribute' => [ 'object_id' => 'id' ], | |
94 | + ], | |
95 | + [ | |
96 | + [ 'language_id' ], | |
97 | + 'exist', | |
98 | + 'skipOnError' => true, | |
99 | + 'targetClass' => Language::className(), | |
100 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
101 | + ], | |
102 | +// [ | |
103 | +// [ 'alias_id' ], | |
104 | +// 'exist', | |
105 | +// 'skipOnError' => true, | |
106 | +// 'targetClass' => Alias::className(), | |
107 | +// 'targetAttribute' => [ 'alias_id' => 'id' ], | |
108 | +// ], | |
109 | + | |
110 | + ]; | |
111 | + } | |
112 | + | |
113 | + /** | |
114 | + * @inheritdoc | |
115 | + */ | |
116 | + public function attributeLabels() | |
117 | + { | |
118 | + return [ | |
119 | + 'object_id' => Yii::t('core', 'Object ID'), | |
120 | + 'language_id' => Yii::t('core', 'Language ID'), | |
121 | + 'alias_id' => Yii::t('core', 'alias ID'), | |
122 | + 'upper_text' => Yii::t('core', 'Upper Text'), | |
123 | + 'about_object_text' => Yii::t('core', 'About object text'), | |
124 | + 'object_name' => Yii::t('core', 'Object name'), | |
125 | + 'meta_title' => Yii::t('core', 'Meta Title'), | |
126 | + 'meta_description' => Yii::t('core', 'Meta Description'), | |
127 | + 'h1' => Yii::t('core', 'H1 tag'), | |
128 | + ]; | |
129 | + } | |
130 | + | |
131 | + /** | |
132 | + * @return \yii\db\ActiveQuery | |
133 | + */ | |
134 | + public function getObject() | |
135 | + { | |
136 | + return $this->hasOne(Objectkb::className(), [ 'id' => 'object_id' ]); | |
137 | + } | |
138 | + | |
139 | + /** | |
140 | + * @return \yii\db\ActiveQuery | |
141 | + */ | |
142 | + public function getLanguage() | |
143 | + { | |
144 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
145 | + } | |
146 | + | |
147 | + /** | |
148 | + * @return \yii\db\ActiveQuery | |
149 | + */ | |
150 | + public function getAlias() | |
151 | + { | |
152 | + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]); | |
153 | + } | |
154 | + | |
155 | + public static function primaryKey() | |
156 | + { | |
157 | + return [ | |
158 | + 'object_id', | |
159 | + 'language_id', | |
160 | + ]; | |
161 | + } | |
162 | + | |
163 | + } | |
0 | 164 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use common\models\Objectkb; | |
9 | + | |
10 | +/** | |
11 | + * ObjectkbSearch represents the model behind the search form about `common\models\Objectkb`. | |
12 | + */ | |
13 | +class ObjectkbSearch extends Objectkb | |
14 | +{ | |
15 | + /** | |
16 | + * @inheritdoc | |
17 | + */ | |
18 | + public function rules() | |
19 | + { | |
20 | + return [ | |
21 | + [['id', 'slider_id', 'sort', 'image_mini_id'], 'integer'], | |
22 | + [['status'], 'boolean'], | |
23 | + ]; | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public function scenarios() | |
30 | + { | |
31 | + // bypass scenarios() implementation in the parent class | |
32 | + return Model::scenarios(); | |
33 | + } | |
34 | + | |
35 | + public function behaviors() | |
36 | + { | |
37 | + return []; | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * Creates data provider instance with search query applied | |
42 | + * | |
43 | + * @param array $params | |
44 | + * | |
45 | + * @return ActiveDataProvider | |
46 | + */ | |
47 | + public function search($params) | |
48 | + { | |
49 | + $query = Objectkb::find(); | |
50 | + | |
51 | + // add conditions that should always apply here | |
52 | + | |
53 | + $dataProvider = new ActiveDataProvider([ | |
54 | + 'query' => $query, | |
55 | + ]); | |
56 | + | |
57 | + $this->load($params); | |
58 | + | |
59 | + if (!$this->validate()) { | |
60 | + // uncomment the following line if you do not want to return any records when validation fails | |
61 | + // $query->where('0=1'); | |
62 | + return $dataProvider; | |
63 | + } | |
64 | + | |
65 | + // grid filtering conditions | |
66 | + $query->andFilterWhere([ | |
67 | + 'id' => $this->id, | |
68 | + 'slider_id' => $this->slider_id, | |
69 | + 'status' => $this->status, | |
70 | + 'sort' => $this->sort, | |
71 | + 'image_mini_id' => $this->image_mini_id, | |
72 | + ]); | |
73 | + | |
74 | + return $dataProvider; | |
75 | + } | |
76 | +} | ... | ... |
common/models/Slider.php
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | /** |
9 | 9 | * This is the model class for table "slider". |
10 | 10 | * |
11 | + * @property string $slider_name | |
11 | 12 | * @property integer $id |
12 | 13 | * @property boolean $status |
13 | 14 | * @property integer $sort |
... | ... | @@ -33,6 +34,15 @@ |
33 | 34 | [ 'sort' ], |
34 | 35 | 'integer', |
35 | 36 | ], |
37 | + [ | |
38 | + ['slider_name'], | |
39 | + 'required', | |
40 | + ], | |
41 | + [ | |
42 | + ['slider_name'], | |
43 | + 'string', | |
44 | + 'max' => 30, | |
45 | + ] | |
36 | 46 | ]; |
37 | 47 | } |
38 | 48 | |
... | ... | @@ -46,15 +56,16 @@ |
46 | 56 | 'status' => Yii::t('core', 'Status'), |
47 | 57 | 'sort' => Yii::t('core', 'Sort'), |
48 | 58 | 'on_home_page' => Yii::t('app', "Show on home page"), |
59 | + 'slider_name' => Yii::t('app', "Slider Name"), | |
49 | 60 | ]; |
50 | 61 | } |
51 | 62 | |
52 | -// /** | |
53 | -// * @return \yii\db\ActiveQuery | |
54 | -// */ | |
55 | -// public function getSlides() | |
56 | -// { | |
57 | -// return $this->hasMany(Slide::className(), [ 'slider_id' => 'id' ]) | |
58 | -// ->inverseOf('slider'); | |
59 | -// } | |
63 | + /** | |
64 | + * @return \yii\db\ActiveQuery | |
65 | + */ | |
66 | + public function getSlides() | |
67 | + { | |
68 | + return $this->hasMany(Slide::className(), [ 'slider_id' => 'id' ]) | |
69 | + ->inverseOf('slider'); | |
70 | + } | |
60 | 71 | } | ... | ... |
common/models/SliderSearch.php
... | ... | @@ -27,6 +27,10 @@ |
27 | 27 | [ 'status' ], |
28 | 28 | 'boolean', |
29 | 29 | ], |
30 | + [ | |
31 | + [ 'slider_name' ], | |
32 | + 'string', | |
33 | + ], | |
30 | 34 | ]; |
31 | 35 | } |
32 | 36 | |
... | ... | @@ -73,6 +77,10 @@ |
73 | 77 | 'status' => $this->status, |
74 | 78 | 'sort' => $this->sort, |
75 | 79 | ] |
80 | + )->andFilterWhere( | |
81 | + [ | |
82 | + 'like', 'slider_name', $this->slider_name, | |
83 | + ] | |
76 | 84 | ); |
77 | 85 | |
78 | 86 | return $dataProvider; | ... | ... |
console/migrations/m180125_122042_add_slider_name_column_to_slider_table.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +/** | |
6 | + * Handles adding slider_name to table `slider`. | |
7 | + */ | |
8 | +class m180125_122042_add_slider_name_column_to_slider_table extends Migration | |
9 | +{ | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public function safeUp() | |
14 | + { | |
15 | + $this->addColumn('slider', 'slider_name', $this->string(30)); | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * @inheritdoc | |
20 | + */ | |
21 | + public function safeDown() | |
22 | + { | |
23 | + $this->dropColumn('slider', 'slider_name'); | |
24 | + } | |
25 | +} | ... | ... |
frontend/controllers/SiteController.php