Commit 8ccb8fe5a079bf2692644064b0bf5697b5b33535
1 parent
36801e2c
-Persones ready
Showing
52 changed files
with
890 additions
and
1 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | + namespace backend\controllers; | |
4 | + | |
5 | + use Yii; | |
6 | + use common\models\Persone; | |
7 | + use common\models\PersoneSearch; | |
8 | + use yii\web\Controller; | |
9 | + use yii\web\NotFoundHttpException; | |
10 | + use yii\filters\VerbFilter; | |
11 | + | |
12 | + /** | |
13 | + * PersoneController implements the CRUD actions for Persone model. | |
14 | + */ | |
15 | + class PersoneController extends Controller | |
16 | + { | |
17 | + /** | |
18 | + * @inheritdoc | |
19 | + */ | |
20 | + public function behaviors() | |
21 | + { | |
22 | + return [ | |
23 | + 'verbs' => [ | |
24 | + 'class' => VerbFilter::className(), | |
25 | + 'actions' => [ | |
26 | + 'delete' => [ 'POST' ], | |
27 | + ], | |
28 | + ], | |
29 | + ]; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * Lists all Persone models. | |
34 | + * | |
35 | + * @return mixed | |
36 | + */ | |
37 | + public function actionIndex() | |
38 | + { | |
39 | + $searchModel = new PersoneSearch(); | |
40 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
41 | + | |
42 | + return $this->render( | |
43 | + 'index', | |
44 | + [ | |
45 | + 'searchModel' => $searchModel, | |
46 | + 'dataProvider' => $dataProvider, | |
47 | + ] | |
48 | + ); | |
49 | + } | |
50 | + | |
51 | + /** | |
52 | + * Displays a single Persone model. | |
53 | + * | |
54 | + * @param integer $id | |
55 | + * | |
56 | + * @return mixed | |
57 | + */ | |
58 | + public function actionView($id) | |
59 | + { | |
60 | + return $this->render( | |
61 | + 'view', | |
62 | + [ | |
63 | + 'model' => $this->findModel($id), | |
64 | + ] | |
65 | + ); | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * Creates a new Persone model. | |
70 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
71 | + * | |
72 | + * @return mixed | |
73 | + */ | |
74 | + public function actionCreate() | |
75 | + { | |
76 | + $model = new Persone(); | |
77 | + $model->generateLangs(); | |
78 | + | |
79 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
80 | + return $this->redirect( | |
81 | + [ | |
82 | + 'view', | |
83 | + 'id' => $model->id, | |
84 | + ] | |
85 | + ); | |
86 | + } | |
87 | + return $this->render( | |
88 | + 'create', | |
89 | + [ | |
90 | + 'model' => $model, | |
91 | + 'modelLangs' => $model->modelLangs, | |
92 | + ] | |
93 | + ); | |
94 | + } | |
95 | + | |
96 | + /** | |
97 | + * Updates an existing Persone model. | |
98 | + * If update is successful, the browser will be redirected to the 'view' page. | |
99 | + * | |
100 | + * @param integer $id | |
101 | + * | |
102 | + * @return mixed | |
103 | + */ | |
104 | + public function actionUpdate($id) | |
105 | + { | |
106 | + $model = $this->findModel($id); | |
107 | + $model->generateLangs(); | |
108 | + | |
109 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
110 | + return $this->redirect( | |
111 | + [ | |
112 | + 'view', | |
113 | + 'id' => $model->id, | |
114 | + ] | |
115 | + ); | |
116 | + } | |
117 | + return $this->render( | |
118 | + 'update', | |
119 | + [ | |
120 | + 'model' => $model, | |
121 | + 'modelLangs' => $model->modelLangs, | |
122 | + ] | |
123 | + ); | |
124 | + } | |
125 | + | |
126 | + /** | |
127 | + * Deletes an existing Persone model. | |
128 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
129 | + * | |
130 | + * @param integer $id | |
131 | + * | |
132 | + * @return mixed | |
133 | + */ | |
134 | + public function actionDelete($id) | |
135 | + { | |
136 | + $this->findModel($id) | |
137 | + ->delete(); | |
138 | + | |
139 | + return $this->redirect([ 'index' ]); | |
140 | + } | |
141 | + | |
142 | + /** | |
143 | + * Finds the Persone model based on its primary key value. | |
144 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
145 | + * | |
146 | + * @param integer $id | |
147 | + * | |
148 | + * @return Persone the loaded model | |
149 | + * @throws NotFoundHttpException if the model cannot be found | |
150 | + */ | |
151 | + protected function findModel($id) | |
152 | + { | |
153 | + if (( $model = Persone::findOne($id) ) !== null) { | |
154 | + return $model; | |
155 | + } else { | |
156 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
157 | + } | |
158 | + } | |
159 | + } | ... | ... |
backend/views/layouts/menu_items.php
1 | +<?php | |
2 | + | |
3 | + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; | |
4 | + use artbox\core\widgets\LanguageForm; | |
5 | + use common\models\Persone; | |
6 | + use common\models\PersoneLang; | |
7 | + use yii\helpers\Html; | |
8 | + use yii\web\View; | |
9 | + use yii\widgets\ActiveForm; | |
10 | + | |
11 | + /** | |
12 | + * @var View $this | |
13 | + * @var Persone $model | |
14 | + * @var ActiveForm $form | |
15 | + * @var PersoneLang $modelLangs | |
16 | + */ | |
17 | + | |
18 | +?> | |
19 | + | |
20 | +<div class="persone-form"> | |
21 | + | |
22 | + <?php $form = ActiveForm::begin(); ?> | |
23 | + | |
24 | + <?= LanguageForm::widget( | |
25 | + [ | |
26 | + 'modelLangs' => $modelLangs, | |
27 | + 'formView' => '@backend/views/persone/_form_language', | |
28 | + 'form' => $form, | |
29 | + ] | |
30 | + ) ?> | |
31 | + | |
32 | + <?= $form->field($model, 'image_id') | |
33 | + ->widget( | |
34 | + ImageManagerInputWidget::className(), | |
35 | + [ | |
36 | + 'showPreview' => true, | |
37 | + 'showDeletePickedImageConfirm' => false, | |
38 | + ] | |
39 | + );?> | |
40 | + | |
41 | + <div class="form-group"> | |
42 | + <?= Html::submitButton( | |
43 | + $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), | |
44 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
45 | + ) ?> | |
46 | + </div> | |
47 | + | |
48 | + <?php ActiveForm::end(); ?> | |
49 | + | |
50 | +</div> | ... | ... |
1 | +<?php | |
2 | + use artbox\core\helpers\SlugifyDecorator; | |
3 | + use artbox\core\models\Language; | |
4 | + use common\models\PersoneLang; | |
5 | + use dosamigos\tinymce\TinyMce; | |
6 | + use yii\web\View; | |
7 | + use yii\widgets\ActiveForm; | |
8 | + | |
9 | + /** | |
10 | + * @var PersoneLang $model_lang | |
11 | + * @var Language $language | |
12 | + * @var ActiveForm $form | |
13 | + * @var View $this | |
14 | + */ | |
15 | +?> | |
16 | +<?php | |
17 | + $attributeField = $form->field($model_lang, '[' . $language->id . ']title') | |
18 | + ->textInput([ 'maxlength' => true ]); | |
19 | + echo $attributeField; | |
20 | +?> | |
21 | + | |
22 | +<?= SlugifyDecorator::decorate( | |
23 | + $form->field($model_lang, '[' . $language->id . ']aliasValue'), | |
24 | + [ '/alias/slugify' ], | |
25 | + $attributeField, | |
26 | + false, | |
27 | + $language->id | |
28 | +) | |
29 | + ->textInput([ 'maxlength' => true ]); ?> | |
30 | + | |
31 | +<?php | |
32 | + echo $form->field($model_lang, '[' . $language->id . ']text') | |
33 | + ->widget( | |
34 | + TinyMce::className(), | |
35 | + [ | |
36 | + 'options' => [ 'rows' => 30 ], | |
37 | + 'language' => 'ru', | |
38 | + 'clientOptions' => [ | |
39 | + 'file_browser_callback' => new yii\web\JsExpression( | |
40 | + "function(field_name, url, type, win) { | |
41 | +window.open('" . yii\helpers\Url::to( | |
42 | + [ | |
43 | + 'imagemanager/manager', | |
44 | + 'view-mode' => 'iframe', | |
45 | + 'select-type' => 'tinymce', | |
46 | + ] | |
47 | + ) . "&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no'); | |
48 | +}" | |
49 | + ), | |
50 | + 'plugins' => [ | |
51 | + "advlist autolink lists link charmap print preview anchor", | |
52 | + "searchreplace visualblocks code fullscreen", | |
53 | + "insertdatetime media table contextmenu paste image", | |
54 | + ], | |
55 | + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code", | |
56 | + ], | |
57 | + ] | |
58 | + ); | |
59 | +?> | |
0 | 60 | \ 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\PersoneSearch */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="persone-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, 'image_id') ?> | |
21 | + | |
22 | + <div class="form-group"> | |
23 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
24 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
25 | + </div> | |
26 | + | |
27 | + <?php ActiveForm::end(); ?> | |
28 | + | |
29 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use common\models\Persone; | |
4 | + use common\models\PersoneLang; | |
5 | + use yii\web\View; | |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | + | |
8 | + /** | |
9 | + * @var View $this | |
10 | + * @var Persone $model | |
11 | + * @var PersoneLang[] $modelLangs | |
12 | + */ | |
13 | + | |
14 | + $this->title = Yii::t('app', 'Create Persone'); | |
15 | + $this->params[ 'breadcrumbs' ][] = [ | |
16 | + 'label' => Yii::t('app', 'Persones'), | |
17 | + 'url' => [ 'index' ], | |
18 | + ]; | |
19 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
20 | +?> | |
21 | +<div class="persone-create"> | |
22 | + | |
23 | + <?php Panel::begin([ | |
24 | + 'header' => $this->title | |
25 | + ])?> | |
26 | + | |
27 | + <?= $this->render( | |
28 | + '_form', | |
29 | + [ | |
30 | + 'model' => $model, | |
31 | + 'modelLangs' => $modelLangs, | |
32 | + ] | |
33 | + ) ?> | |
34 | + | |
35 | + <?php Panel::end()?> | |
36 | + | |
37 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use common\models\Persone; | |
4 | + use common\models\PersoneSearch; | |
5 | + use yii\data\ActiveDataProvider; | |
6 | + use yii\helpers\Html; | |
7 | + use yii\grid\GridView; | |
8 | + use yii\web\View; | |
9 | + use yiister\gentelella\widgets\Panel; | |
10 | + | |
11 | + /** | |
12 | + * @var View $this | |
13 | + * @var ActiveDataProvider $dataProvider | |
14 | + * @var PersoneSearch $searchModel | |
15 | + */ | |
16 | + | |
17 | + $this->title = Yii::t('app', 'Persones'); | |
18 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
19 | +?> | |
20 | +<div class="persone-index"> | |
21 | + | |
22 | + <?php Panel::begin( | |
23 | + [ | |
24 | + 'header' => $this->title, | |
25 | + ] | |
26 | + ) ?> | |
27 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
28 | + | |
29 | + <p> | |
30 | + <?= Html::a(Yii::t('app', 'Create Persone'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | |
31 | + </p> | |
32 | + <?= GridView::widget( | |
33 | + [ | |
34 | + 'dataProvider' => $dataProvider, | |
35 | + 'filterModel' => $searchModel, | |
36 | + 'columns' => [ | |
37 | + [ 'class' => 'yii\grid\SerialColumn' ], | |
38 | + | |
39 | + 'lang.title', | |
40 | + [ | |
41 | + 'attribute' => 'image_id', | |
42 | + 'value' => function (Persone $model) { | |
43 | + if (!empty($model->image)) { | |
44 | + return Html::img( | |
45 | + $model->image->getUrl(), | |
46 | + [ | |
47 | + 'width' => '500px', | |
48 | + ] | |
49 | + ); | |
50 | + } else { | |
51 | + return ''; | |
52 | + } | |
53 | + }, | |
54 | + 'format' => 'html', | |
55 | + ], | |
56 | + | |
57 | + [ 'class' => 'yii\grid\ActionColumn' ], | |
58 | + ], | |
59 | + ] | |
60 | + ); ?> | |
61 | + <?php Panel::end() ?> | |
62 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use common\models\Persone; | |
4 | + use common\models\PersoneLang; | |
5 | + use yii\web\View; | |
6 | + use yiister\gentelella\widgets\Panel; | |
7 | + | |
8 | + /** | |
9 | + * @var View $this | |
10 | + * @var Persone $model | |
11 | + * @var PersoneLang[] $modelLangs | |
12 | + */ | |
13 | + | |
14 | + $this->title = Yii::t( | |
15 | + 'app', | |
16 | + 'Update {modelClass}: ', | |
17 | + [ | |
18 | + 'modelClass' => 'Persone', | |
19 | + ] | |
20 | + ) . $model->id; | |
21 | + $this->params[ 'breadcrumbs' ][] = [ | |
22 | + 'label' => Yii::t('app', 'Persones'), | |
23 | + 'url' => [ 'index' ], | |
24 | + ]; | |
25 | + $this->params[ 'breadcrumbs' ][] = [ | |
26 | + 'label' => $model->id, | |
27 | + 'url' => [ | |
28 | + 'view', | |
29 | + 'id' => $model->id, | |
30 | + ], | |
31 | + ]; | |
32 | + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); | |
33 | +?> | |
34 | +<div class="persone-update"> | |
35 | + | |
36 | + <?php Panel::begin( | |
37 | + [ | |
38 | + 'header' => $this->title, | |
39 | + ] | |
40 | + ) ?> | |
41 | + | |
42 | + <?= $this->render( | |
43 | + '_form', | |
44 | + [ | |
45 | + 'model' => $model, | |
46 | + 'modelLangs' => $modelLangs, | |
47 | + ] | |
48 | + ) ?> | |
49 | + | |
50 | + <?php Panel::end() ?> | |
51 | + | |
52 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + use common\models\Persone; | |
4 | + use yii\helpers\Html; | |
5 | + use yii\web\View; | |
6 | + use yii\widgets\DetailView; | |
7 | + use yiister\gentelella\widgets\Panel; | |
8 | + | |
9 | + /** | |
10 | + * @var View $this | |
11 | + * @var Persone $model | |
12 | + */ | |
13 | + | |
14 | + $this->title = $model->id; | |
15 | + $this->params[ 'breadcrumbs' ][] = [ | |
16 | + 'label' => Yii::t('app', 'Persones'), | |
17 | + 'url' => [ 'index' ], | |
18 | + ]; | |
19 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
20 | +?> | |
21 | +<div class="persone-view"> | |
22 | + | |
23 | + <?php Panel::begin( | |
24 | + [ | |
25 | + 'header' => $this->title, | |
26 | + ] | |
27 | + ) ?> | |
28 | + | |
29 | + <p> | |
30 | + <?= Html::a( | |
31 | + Yii::t('app', 'Update'), | |
32 | + [ | |
33 | + 'update', | |
34 | + 'id' => $model->id, | |
35 | + ], | |
36 | + [ 'class' => 'btn btn-primary' ] | |
37 | + ) ?> | |
38 | + <?= Html::a( | |
39 | + Yii::t('app', 'Delete'), | |
40 | + [ | |
41 | + 'delete', | |
42 | + 'id' => $model->id, | |
43 | + ], | |
44 | + [ | |
45 | + 'class' => 'btn btn-danger', | |
46 | + 'data' => [ | |
47 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | |
48 | + 'method' => 'post', | |
49 | + ], | |
50 | + ] | |
51 | + ) ?> | |
52 | + </p> | |
53 | + | |
54 | + <?= DetailView::widget( | |
55 | + [ | |
56 | + 'model' => $model, | |
57 | + 'attributes' => [ | |
58 | + 'id', | |
59 | + 'image_id', | |
60 | + ], | |
61 | + ] | |
62 | + ) ?> | |
63 | + | |
64 | + <?php Panel::end() ?> | |
65 | + | |
66 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | + namespace common\models; | |
4 | + | |
5 | + use artbox\core\behaviors\LanguageBehavior; | |
6 | + use artbox\core\models\Image; | |
7 | + use artbox\core\models\Language; | |
8 | + use yii\db\ActiveQuery; | |
9 | + use yii\db\ActiveRecord; | |
10 | + use yii\web\Request; | |
11 | + use Yii; | |
12 | + | |
13 | + /** | |
14 | + * This is the model class for table "persone". | |
15 | + * | |
16 | + * @property integer $id | |
17 | + * @property integer $image_id | |
18 | + * @property PersoneLang[] $personeLangs | |
19 | + * @property Language[] $languages | |
20 | + * @property Image $image | |
21 | + * * From language behavior * | |
22 | + * @property PersoneLang $lang | |
23 | + * @property PersoneLang[] $langs | |
24 | + * @property PersoneLang $objectLang | |
25 | + * @property string $ownerKey | |
26 | + * @property string $langKey | |
27 | + * @property PersoneLang[] $modelLangs | |
28 | + * @property bool $transactionStatus | |
29 | + * @method string getOwnerKey() | |
30 | + * @method void setOwnerKey( string $value ) | |
31 | + * @method string getLangKey() | |
32 | + * @method void setLangKey( string $value ) | |
33 | + * @method ActiveQuery getLangs() | |
34 | + * @method ActiveQuery getLang( integer $language_id ) | |
35 | + * @method PersoneLang[] generateLangs() | |
36 | + * @method void loadLangs( Request $request ) | |
37 | + * @method bool linkLangs() | |
38 | + * @method bool saveLangs() | |
39 | + * @method bool getTransactionStatus() | |
40 | + * @method bool loadWithLangs( Request $request ) | |
41 | + * @method bool saveWithLangs() | |
42 | + * * End language behavior * | |
43 | + * @see LanguageBehavior | |
44 | + */ | |
45 | + class Persone extends ActiveRecord | |
46 | + { | |
47 | + /** | |
48 | + * @inheritdoc | |
49 | + */ | |
50 | + public static function tableName() | |
51 | + { | |
52 | + return 'persone'; | |
53 | + } | |
54 | + | |
55 | + public function behaviors() | |
56 | + { | |
57 | + return [ | |
58 | + 'language' => [ | |
59 | + 'class' => LanguageBehavior::className(), | |
60 | + ], | |
61 | + ]; | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * @inheritdoc | |
66 | + */ | |
67 | + public function rules() | |
68 | + { | |
69 | + return [ | |
70 | + [ | |
71 | + [ 'image_id' ], | |
72 | + 'integer', | |
73 | + ], | |
74 | + ]; | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * @inheritdoc | |
79 | + */ | |
80 | + public function attributeLabels() | |
81 | + { | |
82 | + return [ | |
83 | + 'id' => Yii::t('app', 'ID'), | |
84 | + 'image_id' => Yii::t('app', 'Image ID'), | |
85 | + ]; | |
86 | + } | |
87 | + | |
88 | + /** | |
89 | + * @return \yii\db\ActiveQuery | |
90 | + */ | |
91 | + public function getImage() | |
92 | + { | |
93 | + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); | |
94 | + } | |
95 | + | |
96 | + /** | |
97 | + * @return \yii\db\ActiveQuery | |
98 | + */ | |
99 | + public function getPersoneLangs() | |
100 | + { | |
101 | + return $this->hasMany(PersoneLang::className(), [ 'persone_id' => 'id' ]); | |
102 | + } | |
103 | + | |
104 | + /** | |
105 | + * @return \yii\db\ActiveQuery | |
106 | + */ | |
107 | + public function getLanguages() | |
108 | + { | |
109 | + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ]) | |
110 | + ->viaTable('persone_lang', [ 'persone_id' => 'id' ]); | |
111 | + } | |
112 | + } | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use artbox\core\behaviors\SlugBehavior; | |
6 | +use artbox\core\models\Language; | |
7 | +use Yii; | |
8 | +use yii\db\ActiveRecord; | |
9 | + | |
10 | +/** | |
11 | + * This is the model class for table "persone_lang". | |
12 | + * | |
13 | + * @property integer $persone_id | |
14 | + * @property integer $language_id | |
15 | + * @property integer $alias_id | |
16 | + * @property string $title | |
17 | + * @property string $text | |
18 | + * | |
19 | + * @property Language $language | |
20 | + * @property Persone $persone | |
21 | + */ | |
22 | +class PersoneLang extends ActiveRecord | |
23 | +{ | |
24 | + /** | |
25 | + * @inheritdoc | |
26 | + */ | |
27 | + public static function tableName() | |
28 | + { | |
29 | + return 'persone_lang'; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * @inheritdoc | |
34 | + */ | |
35 | + public static function primaryKey() | |
36 | + { | |
37 | + return [ | |
38 | + 'persone_id', | |
39 | + 'language_id', | |
40 | + ]; | |
41 | + } | |
42 | + | |
43 | + /** | |
44 | + * @inheritdoc | |
45 | + */ | |
46 | + public function behaviors() | |
47 | + { | |
48 | + return [ | |
49 | + 'slug' => [ | |
50 | + 'class' => SlugBehavior::className(), | |
51 | + 'action' => 'persone/view', | |
52 | + 'params' => [ | |
53 | + 'id' => 'persone_id', | |
54 | + ], | |
55 | + 'fields' => [ | |
56 | + ], | |
57 | + ], | |
58 | + ]; | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * @inheritdoc | |
63 | + */ | |
64 | + public function rules() | |
65 | + { | |
66 | + return [ | |
67 | + [['persone_id', 'language_id', 'alias_id'], 'integer'], | |
68 | + [['text'], 'string'], | |
69 | + [['title'], 'string', 'max' => 255], | |
70 | + [['persone_id', 'language_id'], 'unique', 'targetAttribute' => ['persone_id', 'language_id'], 'message' => 'The combination of Persone ID and Language ID has already been taken.'], | |
71 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
72 | + [['persone_id'], 'exist', 'skipOnError' => true, 'targetClass' => Persone::className(), 'targetAttribute' => ['persone_id' => 'id']], | |
73 | + ]; | |
74 | + } | |
75 | + | |
76 | + /** | |
77 | + * @inheritdoc | |
78 | + */ | |
79 | + public function attributeLabels() | |
80 | + { | |
81 | + return [ | |
82 | + 'persone_id' => Yii::t('app', 'Persone ID'), | |
83 | + 'language_id' => Yii::t('app', 'Language ID'), | |
84 | + 'alias_id' => Yii::t('app', 'Alias ID'), | |
85 | + 'title' => Yii::t('app', 'Title'), | |
86 | + 'text' => Yii::t('app', 'Text'), | |
87 | + ]; | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * @return \yii\db\ActiveQuery | |
92 | + */ | |
93 | + public function getLanguage() | |
94 | + { | |
95 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * @return \yii\db\ActiveQuery | |
100 | + */ | |
101 | + public function getPersone() | |
102 | + { | |
103 | + return $this->hasOne(Persone::className(), ['id' => 'persone_id']); | |
104 | + } | |
105 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use yii\base\Model; | |
6 | +use yii\data\ActiveDataProvider; | |
7 | + | |
8 | +/** | |
9 | + * PersoneSearch represents the model behind the search form about `common\models\Persone`. | |
10 | + */ | |
11 | +class PersoneSearch extends Persone | |
12 | +{ | |
13 | + /** | |
14 | + * @inheritdoc | |
15 | + */ | |
16 | + public function rules() | |
17 | + { | |
18 | + return [ | |
19 | + [['id', 'image_id'], 'integer'], | |
20 | + ]; | |
21 | + } | |
22 | + | |
23 | + /** | |
24 | + * @inheritdoc | |
25 | + */ | |
26 | + public function scenarios() | |
27 | + { | |
28 | + // bypass scenarios() implementation in the parent class | |
29 | + return Model::scenarios(); | |
30 | + } | |
31 | + | |
32 | + public function behaviors() | |
33 | + { | |
34 | + return []; | |
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 = Persone::find(); | |
47 | + | |
48 | + // add conditions that should always apply here | |
49 | + | |
50 | + $dataProvider = new ActiveDataProvider([ | |
51 | + 'query' => $query, | |
52 | + ]); | |
53 | + | |
54 | + $this->load($params); | |
55 | + | |
56 | + if (!$this->validate()) { | |
57 | + // uncomment the following line if you do not want to return any records when validation fails | |
58 | + // $query->where('0=1'); | |
59 | + return $dataProvider; | |
60 | + } | |
61 | + | |
62 | + // grid filtering conditions | |
63 | + $query->andFilterWhere([ | |
64 | + 'id' => $this->id, | |
65 | + 'image_id' => $this->image_id, | |
66 | + ]); | |
67 | + | |
68 | + return $dataProvider; | |
69 | + } | |
70 | +} | ... | ... |
console/migrations/m170928_095137_add_column_to_image_table.php
100644 → 100755
console/migrations/m170928_141247_create_persone_table.php
0 → 100755
1 | +<?php | |
2 | + | |
3 | + use yii\db\Migration; | |
4 | + | |
5 | + /** | |
6 | + * Handles the creation of table `persone`. | |
7 | + */ | |
8 | + class m170928_141247_create_persone_table extends Migration | |
9 | + { | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public function up() | |
14 | + { | |
15 | + $this->createTable( | |
16 | + 'persone', | |
17 | + [ | |
18 | + 'id' => $this->primaryKey(), | |
19 | + 'image_id' => $this->integer(), | |
20 | + ] | |
21 | + ); | |
22 | + } | |
23 | + | |
24 | + /** | |
25 | + * @inheritdoc | |
26 | + */ | |
27 | + public function down() | |
28 | + { | |
29 | + $this->dropTable('persone'); | |
30 | + } | |
31 | + } | ... | ... |
console/migrations/m170928_141633_create_persone_lang_table.php
0 → 100755
1 | +<?php | |
2 | + | |
3 | + use yii\db\Migration; | |
4 | + | |
5 | + /** | |
6 | + * Handles the creation of table `persone_lang`. | |
7 | + */ | |
8 | + class m170928_141633_create_persone_lang_table extends Migration | |
9 | + { | |
10 | + /** | |
11 | + * @inheritdoc | |
12 | + */ | |
13 | + public function up() | |
14 | + { | |
15 | + $this->createTable( | |
16 | + 'persone_lang', | |
17 | + [ | |
18 | + 'persone_id' => $this->integer(), | |
19 | + 'language_id' => $this->integer(), | |
20 | + 'alias_id' => $this->integer(), | |
21 | + 'title' => $this->string(), | |
22 | + 'text' => $this->text(), | |
23 | + ] | |
24 | + ); | |
25 | + | |
26 | + $this->createIndex( | |
27 | + 'persone_ix', | |
28 | + 'persone_lang', | |
29 | + [ | |
30 | + 'persone_id', | |
31 | + 'language_id', | |
32 | + ], | |
33 | + true | |
34 | + ); | |
35 | + | |
36 | + $this->addForeignKey('persone_fk', 'persone_lang', 'persone_id', 'persone', 'id', 'CASCADE', 'CASCADE'); | |
37 | + | |
38 | + $this->addForeignKey('lang_fk', 'persone_lang', 'language_id', 'language', 'id', 'CASCADE', 'CASCADE'); | |
39 | + | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * @inheritdoc | |
44 | + */ | |
45 | + public function down() | |
46 | + { | |
47 | + $this->dropForeignKey('lang_fk', 'persone_lang'); | |
48 | + | |
49 | + $this->dropForeignKey('persone_fk', 'persone_lang'); | |
50 | + | |
51 | + $this->dropTable('persone_lang'); | |
52 | + } | |
53 | + } | ... | ... |