diff --git a/migrations/m170901_100719_shop_add_column.php b/migrations/m170901_100719_shop_add_column.php new file mode 100644 index 0000000..7355bc9 --- /dev/null +++ b/migrations/m170901_100719_shop_add_column.php @@ -0,0 +1,24 @@ +addColumn('shop', 'image_id', $this->integer()); + $this->addForeignKey('shop_image', + 'shop', + 'image_id', + 'ImageManager', + 'id' + ); + } + + public function safeDown() + { + $this->dropColumn('shop', 'image_id'); + $this->dropForeignKey('shop_image', 'shop'); + } + +} diff --git a/models/Shop.php b/models/Shop.php index befcb05..3575b89 100644 --- a/models/Shop.php +++ b/models/Shop.php @@ -2,6 +2,7 @@ namespace artbox\stock\models; + use artbox\core\components\imagemanager\models\ImageManager; use artbox\core\models\Language; use artbox\core\behaviors\LanguageBehavior; use yii\helpers\Json; @@ -52,6 +53,7 @@ [ 'city_id', 'sort', + 'image_id' ], 'integer', ], @@ -84,6 +86,13 @@ 'targetClass' => City::className(), 'targetAttribute' => [ 'city_id' => 'id' ], ], + [ + [ 'image_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => ImageManager::className(), + 'targetAttribute' => [ 'image_id' => 'id' ], + ], ]; } @@ -110,6 +119,10 @@ { return $this->hasOne(City::className(), [ 'id' => 'city_id' ]); } + public function getImage() + { + return $this->hasOne(ImageManager::className(), [ 'id' => 'image_id' ]); + } public function getCities() { diff --git a/views/shop/_form.php b/views/shop/_form.php index 9e59d9b..7930be0 100644 --- a/views/shop/_form.php +++ b/views/shop/_form.php @@ -4,6 +4,7 @@ use yii\widgets\ActiveForm; use artbox\core\widgets\LanguageForm; use kartik\select2\Select2; + use artbox\core\components\imagemanager\components\ImageManagerInputWidget; /* @var $this yii\web\View */ /* @var $model artbox\stock\models\Shop */ @@ -46,7 +47,18 @@ 'options' => [ 'placeholder' => 'Выберите город ...' ], ] ); ?> - + field($model, 'image_id') + ->widget( + ImageManagerInputWidget::className(), + [ + 'aspectRatio' => ( 16 / 9 ), + //set the aspect ratio + 'showPreview' => true, + //false to hide the preview + 'showDeletePickedImageConfirm' => false, + //on true show warning before detach image + ] + ); ?> field($model, 'sort') ->textInput() ?> -- libgit2 0.21.4