From 7f4032232a67fbb5060166e9112104aeb24f3fae Mon Sep 17 00:00:00 2001 From: Anastasia Date: Wed, 23 May 2018 14:33:49 +0300 Subject: [PATCH] - add image to services --- backend/controllers/ServiceController.php | 5 ++++- common/models/Service.php | 8 +++++++- console/migrations/m180523_112936_alter_table_service.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 console/migrations/m180523_112936_alter_table_service.php diff --git a/backend/controllers/ServiceController.php b/backend/controllers/ServiceController.php index 165bd17..bd103b9 100644 --- a/backend/controllers/ServiceController.php +++ b/backend/controllers/ServiceController.php @@ -165,7 +165,10 @@ ], ], 'fields' => [ - + [ + 'name' => 'image_id', + 'type' => Form::IMAGE + ], [ 'name' => 'parent_id', 'type' => Form::RELATION, diff --git a/common/models/Service.php b/common/models/Service.php index 9aaa1ee..2d04e62 100644 --- a/common/models/Service.php +++ b/common/models/Service.php @@ -2,6 +2,7 @@ namespace common\models; +use artbox\core\models\Image; use artbox\core\models\traits\AliasableTrait; use backend\behaviors\LevelBehavior; use Yii; @@ -82,7 +83,7 @@ class Service extends ActiveRecord { return [ [['parent_id', 'sort', 'level', 'created_at', 'updated_at'], 'default', 'value' => null], - [['sort', 'level', 'created_at', 'updated_at'], 'integer'], + [['sort', 'level', 'created_at', 'updated_at', 'image_id'], 'integer'], [['status'], 'boolean'], ]; } @@ -100,6 +101,7 @@ class Service extends ActiveRecord 'level' => Yii::t('app', 'Level'), 'created_at' => Yii::t('app', 'Created At'), 'updated_at' => Yii::t('app', 'Updated At'), + 'image_id' => Yii::t('app', 'Image'), ]; } @@ -135,4 +137,8 @@ class Service extends ActiveRecord ] ); } + + public function getImage(){ + return $this->hasOne(Image::className(), ['id' => 'image_id']); + } } diff --git a/console/migrations/m180523_112936_alter_table_service.php b/console/migrations/m180523_112936_alter_table_service.php new file mode 100644 index 0000000..417c890 --- /dev/null +++ b/console/migrations/m180523_112936_alter_table_service.php @@ -0,0 +1,40 @@ +addColumn('service', 'image_id', $this->integer()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('service', 'image_id'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m180523_112936_alter_table_service cannot be reverted.\n"; + + return false; + } + */ +} -- libgit2 0.21.4