Your IP : 216.73.216.79


Current Path : /var/www/html/ekursus/backend/models/
Upload File :
Current File : /var/www/html/ekursus/backend/models/BanciHighlight.php

<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "banci_highlight".
 *
 * @property int $highlight_id
 * @property string $highlight_title
 * @property string $highlight_image
 * @property string $highlight_image_en
 * @property string $highlight_description
 * @property string $created_at
 * @property string $updated_at
 * @property string $created_by
 * @property string $updated_by
 */
class BanciHighlight extends \common\models\Dermaga
{

    public $imgpath;

    public $imgpath_en;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'banci_highlight';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['highlight_title','highlight_status'], 'required'],
            [['created_at', 'updated_at','imgpath','imgpath_en'], 'safe'],
            [['highlight_title'], 'string', 'max' => 700],
            [['imgpath','imgpath_en'],'file','skipOnEmpty' => false, 'extensions' => 'png, jpg','maxSize'=>'2097152','on'=>'create'],
            [['imgpath','imgpath_en'],'file','skipOnEmpty' => true, 'extensions' => 'png, jpg','maxSize'=>'2097152','on' =>'update'],
            [['highlight_description', 'created_by', 'updated_by'], 'string', 'max' => 3000],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'highlight_id' => Yii::t('app', 'ID'),
            'highlight_title' => Yii::t('app', 'Tajuk'),
            'highlight_image' => Yii::t('app', 'Gambar'),
            'highlight_image_en' => Yii::t('app', 'Gambar En'),
            'highlight_description' => Yii::t('app', 'Penerangan'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'created_by' => Yii::t('app', 'Created By'),
            'updated_by' => Yii::t('app', 'Updated By'),
        ];
    }

    public function upload()
    {   
        /* if directory empty create it */
        if (!file_exists('uploads/highlight/')) {
            mkdir('uploads/highlight/', 0777, true);
        }

        if (!file_exists('uploads/highlight/thumbnail/')) {
            mkdir('uploads/highlight/thumbnail/', 0777, true);
        }

        if ($this->validate()) {
            
            if(!empty($this->imgpath)){
                    $filename = 'uploads/highlight/' . $this->imgpath->baseName . date('dmyhi') . '.' . $this->imgpath->extension;
                    $this->imgpath->saveAs($filename);
                    $this->highlight_image = $filename;              
            }

            if(!empty($this->imgpath_en)){
                    $filename = 'uploads/highlight/' . $this->imgpath_en->baseName . date('dmyhi') . '.' . $this->imgpath_en->extension;
                    $this->imgpath_en->saveAs($filename);
                    $this->highlight_image_en = $filename;
            }

            return true;
        } else {
            // echo '<pre>'; var_dump($this->imgpath_en); echo '</pre>';die();
            echo '<pre>'; var_dump($this->errors); echo '</pre>';die();
            return false;
        }
    }
}