Commit a2b52eb4eb60c77b0652e2a2f1fe2ad178911691

Authored by Anastasia
1 parent 1b334a54

artbox-stock

migrations/m170901_100719_shop_add_column.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m170901_100719_shop_add_column extends Migration
  6 +{
  7 + public function safeUp()
  8 + {
  9 + $this->addColumn('shop', 'image_id', $this->integer());
  10 + $this->addForeignKey('shop_image',
  11 + 'shop',
  12 + 'image_id',
  13 + 'ImageManager',
  14 + 'id'
  15 + );
  16 + }
  17 +
  18 + public function safeDown()
  19 + {
  20 + $this->dropColumn('shop', 'image_id');
  21 + $this->dropForeignKey('shop_image', 'shop');
  22 + }
  23 +
  24 +}
... ...
models/Shop.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace artbox\stock\models;
4 4  
  5 + use artbox\core\components\imagemanager\models\ImageManager;
5 6 use artbox\core\models\Language;
6 7 use artbox\core\behaviors\LanguageBehavior;
7 8 use yii\helpers\Json;
... ... @@ -52,6 +53,7 @@
52 53 [
53 54 'city_id',
54 55 'sort',
  56 + 'image_id'
55 57 ],
56 58 'integer',
57 59 ],
... ... @@ -84,6 +86,13 @@
84 86 'targetClass' => City::className(),
85 87 'targetAttribute' => [ 'city_id' => 'id' ],
86 88 ],
  89 + [
  90 + [ 'image_id' ],
  91 + 'exist',
  92 + 'skipOnError' => true,
  93 + 'targetClass' => ImageManager::className(),
  94 + 'targetAttribute' => [ 'image_id' => 'id' ],
  95 + ],
87 96 ];
88 97 }
89 98  
... ... @@ -110,6 +119,10 @@
110 119 {
111 120 return $this->hasOne(City::className(), [ 'id' => 'city_id' ]);
112 121 }
  122 + public function getImage()
  123 + {
  124 + return $this->hasOne(ImageManager::className(), [ 'id' => 'image_id' ]);
  125 + }
113 126  
114 127 public function getCities()
115 128 {
... ...
views/shop/_form.php
... ... @@ -4,6 +4,7 @@
4 4 use yii\widgets\ActiveForm;
5 5 use artbox\core\widgets\LanguageForm;
6 6 use kartik\select2\Select2;
  7 + use artbox\core\components\imagemanager\components\ImageManagerInputWidget;
7 8  
8 9 /* @var $this yii\web\View */
9 10 /* @var $model artbox\stock\models\Shop */
... ... @@ -46,7 +47,18 @@
46 47 'options' => [ 'placeholder' => 'Выберите город ...' ],
47 48 ]
48 49 ); ?>
49   -
  50 + <?= $form->field($model, 'image_id')
  51 + ->widget(
  52 + ImageManagerInputWidget::className(),
  53 + [
  54 + 'aspectRatio' => ( 16 / 9 ),
  55 + //set the aspect ratio
  56 + 'showPreview' => true,
  57 + //false to hide the preview
  58 + 'showDeletePickedImageConfirm' => false,
  59 + //on true show warning before detach image
  60 + ]
  61 + ); ?>
50 62 <?= $form->field($model, 'sort')
51 63 ->textInput() ?>
52 64  
... ...