| Current Path : /var/www/html/ebook/backend/models/frontendcontenttemplate/ |
| Current File : /var/www/html/ebook/backend/models/frontendcontenttemplate/FrontendContentTemplate.php |
<?php
namespace backend\models\frontendcontenttemplate;
use Yii;
/**
* This is the model class for table "frontend_content_template".
*
* @property int $frontend_content_template_id
* @property string $template_title
* @property string $template_description
* @property string $template_html
* @property int $template_status
* @property string $created_date
* @property string $updated_date
* @property int $created_by
* @property int $updated_by
*/
class FrontendContentTemplate extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public $uploadImage;
public $imglocation = 'uploads/components';
public static function tableName()
{
return 'frontend_content_template';
}
public static $component = [
'text' => 'Text',
'photo' => 'Photo',
'audio' => 'Audio',
'video' => 'Video',
'youtube' => 'Youtube',
'vimeo' => 'Vimeo',
'googlemap' => 'Google Map',
'nonExisting' => 'Non Exist',
];
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['template_html'], 'string'],
[['template_status', 'created_by', 'updated_by'], 'integer'],
[['created_date', 'updated_date','template_component','template_categories','template_image'], 'safe'],
[['template_title', 'template_description'], 'string', 'max' => 250],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'frontend_content_template_id' => Yii::t('app', 'Frontend Content Template ID'),
'template_title' => Yii::t('app', 'Title'),
'template_description' => Yii::t('app', 'Description'),
'template_html' => Yii::t('app', 'Html'),
'template_status' => Yii::t('app', 'Status'),
'created_date' => Yii::t('app', 'Created Date'),
'updated_date' => Yii::t('app', 'Updated Date'),
'created_by' => Yii::t('app', 'Created By'),
'updated_by' => Yii::t('app', 'Updated By'),
];
}
public function upload()
{
if ($this->validate()) {
/* if directory empty create it */
if (!file_exists($this->imglocation . '/')) {
mkdir($this->imglocation . '/', 0777, true);
}
/* save thumb */
if (!empty($this->uploadImage)) {
$filename = $this->imglocation . '/' . $this->uploadImage->baseName . date('dmyhi') . '.' . $this->uploadImage->extension;
$this->uploadImage->saveAs($filename);
$this->template_image = $filename;
}
return true;
} else {
return false;
}
}
}