Skip to content

Commit

Permalink
Add new function getImageMobile to get path_mobile from database. add…
Browse files Browse the repository at this point in the history
… new property/rules for path_mobile & imageMobile
  • Loading branch information
sleemy1997 committed Apr 17, 2018
1 parent 006350c commit f5fa709
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions models/WidgetCarouselItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
* @property integer $carousel_id
* @property string $base_url
* @property string $path
* @property string $path_mobile
* @property string $type
* @property string $image
* @property string $imageUrl
* @property string $imageMobile
* @property string $url
* @property integer $status
* @property integer $order
Expand All @@ -35,6 +37,7 @@ class WidgetCarouselItem extends TranslatableModel
* @var array|null
*/
public $image;
public $imageMobile;

public static $translateModelForeignKey = 'widget_carousel_item_id';

Expand Down Expand Up @@ -76,6 +79,13 @@ public function behaviors()
'baseUrlAttribute' => null,
'typeAttribute' => 'type'
],
[
'class' => UploadBehavior::className(),
'attribute' => 'imageMobile',
'pathAttribute' => 'path_mobile',
'baseUrlAttribute' => null,
'typeAttribute' => 'type'
],
'cacheInvalidate' => [
'class' => CacheInvalidateBehavior::className(),
'keys' => [
Expand All @@ -97,11 +107,11 @@ public function rules()
{
return [
[['carousel_id'], 'required'],
[['image'], 'required'],
[['image',], 'required'],
[['carousel_id', 'status', 'order'], 'integer'],
[['url', 'base_url', 'path'], 'string', 'max' => 1024],
[['url', 'base_url', 'path','path_mobile'], 'string', 'max' => 1024],
[['type'], 'string', 'max' => 45],
['image', 'safe']
[['image','imageMobile'], 'safe']
];
}

Expand All @@ -114,12 +124,15 @@ public function attributeLabels()
'id' => Yii::t('i18ncontent', 'ID'),
'carousel_id' => Yii::t('i18ncontent', 'Carousel ID'),
'image' => Yii::t('i18ncontent', 'Image'),
'imageMobile' => Yii::t('i18ncontent', 'Mobile Image'),
'base_url' => Yii::t('i18ncontent', 'Base URL'),
'path' => Yii::t('i18ncontent', 'Path'),
'path_mobile' => Yii::t('i18ncontent', 'path_mobile'),
'type' => Yii::t('i18ncontent', 'File Type'),
'url' => Yii::t('i18ncontent', 'Url'),
'status' => Yii::t('i18ncontent', 'Status'),
'order' => Yii::t('i18ncontent', 'Order')

];
}

Expand Down Expand Up @@ -157,4 +170,15 @@ public function getImageUrl()
return Yii::getAlias('@storageUrl') . '/source/' . ltrim($this->path, '/');
}

/**
* @return null|string
*/
public function getImageMobileUrl()
{
if($this->path_mobile && strlen($this->path_mobile) > 0) {
return Yii::getAlias('@storageUrl') . '/source/' . ltrim($this->path_mobile, '/');
}
return null;
}

}

0 comments on commit f5fa709

Please sign in to comment.