<?php

namespace common\modules\analyticsSchool\models;

use Yii;
use yii\web\UploadedFile;

/**
 * This is the model class for table "analytics_school_course".
 *
 * @property integer $id
 * @property string $name
 * @property string $description
 * @property string $image
 */
class AnalyticsSchoolCourse extends \common\components\ActiveRecordModel
{
    public $uploadedImage;
    const SAVE_FOLDER = '/uploads/courses';

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

    /**
     * @return string
     */
    public function name(){
        return 'Курсы';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['description', 'image'], 'string'],
            [['uploadedImage'], 'file', 'extensions' => ['jpg', 'jpeg', 'png']],
            [['name'], 'string', 'max' => 255],
        ];
    }

    public function beforeSave($insert){
        if (!parent::beforeSave($insert))
            return false;

        $this->uploadedImage = UploadedFile::getInstance($this, 'uploadedImage');
        if ($this->validate('uploadedImage')) {

        }
    }

    public function getPath()
    {
        return Yii::getAlias('@frontend/web').self::SAVE_FOLDER;
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Название курса',
            'description' => 'Описание',
            'image' => 'Изображение',
            'uploadedImage' => 'Изображение',
        ];
    }

    /**
     * @return array
     */
    public function behaviors(){
        return [];
    }
}
