| Current Path : /var/www/html/chatbot/backend/models/ |
| Current File : /var/www/html/chatbot/backend/models/BanciMediaGallery.php |
<?php
namespace backend\models;
use Yii;
use asinfotrack\yii2\audittrail\behaviors\AuditTrailBehavior;
/**
* This is the model class for table "banci_media_gallery".
*
* @property int $media_gallery_id
* @property string $media_gallery_title
* @property string $media_gallery_file_url
* @property int $media_gallery_file_type 1-Image,2-Video
* @property int $media_gallery_article_id
* @property string $created_at
* @property int $created_by
* @property string $updated_at
* @property int $updated_by
*/
class BanciMediaGallery extends \common\models\Dermaga
{
/* type of media */
public static $mediaType = ['1'=>'Gambar','2'=>'Video'];
public $uploadImage;
public $uploadArr = [];
public $thumbpath;
public $thumbup;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'banci_media_gallery';
}
public function behaviors()
{
return [
'audittrail'=>[
'class'=>AuditTrailBehavior::className(),
// some of the optional configurations
'ignoredAttributes'=>['created_at','updated_at'],
'consoleUserId'=>1,
'attributeOutput'=>[
'desktop_id'=>function ($value) {
$model = Desktop::findOne($value);
return sprintf('%s %s', $model->manufacturer, $model->device_name);
},
'last_checked'=>'datetime',
],
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['media_gallery_file_type', 'media_gallery_article_id', 'created_by', 'updated_by'], 'integer'],
[['created_at', 'updated_at','media_gallery_thumb_image','media_gallery_description_en','media_gallery_description','media_gallery_file_url','media_gallery_file_status','media_gallery_category'], 'safe'],
[['media_gallery_title','media_gallery_title_en'], 'string', 'max' => 200],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'media_gallery_id' => Yii::t('app', 'Media Gallery ID'),
'media_gallery_title' => Yii::t('app', 'Tajuk'),
'media_gallery_file_url' => Yii::t('app', 'Pautan'),
'media_gallery_file_type' => Yii::t('app', 'Jenis'),
'media_gallery_article_id' => Yii::t('app', 'Artikel Id'),
'created_at' => Yii::t('app', 'Created At'),
'created_by' => Yii::t('app', 'Created By'),
'updated_at' => Yii::t('app', 'Updated At'),
'updated_by' => Yii::t('app', 'Updated By'),
];
}
public function upload($aid)
{
if ($this->validate()) {
/* if directory empty create it */
if (!file_exists('uploads/galeryfoto_'. $aid . '/')) {
mkdir('uploads/galeryfoto_'. $aid . '/', 0777, true);
}
if (!file_exists('uploads/galeryfoto_'. $aid . '/thumbnail')) {
mkdir('uploads/galeryfoto_'. $aid . '/thumbnail', 0777, true);
}
/* save thumb */
if(!empty($this->thumbup)){
$thumbfilename = 'uploads/galeryfoto_'. $aid . '/thumbnail/' . $this->thumbup->baseName . date('dmyhi') . '.' . $this->thumbup->extension;
$this->thumbup->saveAs($thumbfilename);
$this->thumbpath = $thumbfilename;
}
if(!empty($this->uploadImage)){
foreach ($this->uploadImage as $file) {
$filename = 'uploads/galeryfoto_'. $aid . '/' . $file->baseName . date('dmyhi') . '.' . $file->extension;
$file->saveAs($filename);
$this->uploadArr[] = $filename;
/* rewrite url path for uniquenes */
// $this->media_gallery_file_url = $this->media_gallery_file_url->baseName . date('dmyhi') . '.' . $this->media_gallery_file_url->extension;
}
}
return true;
} else {
return false;
}
}
public function getArticle(){
return $this->hasOne(BanciArticle::className(),['banci_article_id'=>'media_gallery_article_id']);
}
}