<?php

namespace common\modules\school\models;

use Yii;

use common\modules\school\models\Lessons;

/**
 * This is the model class for table "testings_questions_image".
 *
 * @property integer $id
 * @property integer $question_id
 * @property string $filename
 */
class LessonImage extends \common\components\ActiveRecordModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'school_lessons_image';
    }

    public function name()
    {
        return 'Документы для уроков';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['lesson_id', 'filename', 'title'], 'required'],
            [['lesson_id'], 'integer'],
            [['filename'], 'string', 'max' => 50],
            [['title'], 'string', 'max' => 150],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'lesson_id' => 'Урок',
            'filename' => 'Документ',
            'title' => 'Название',
        ];
    }

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

    public function getLesson()
    {
        return $this->hasOne(Lessons::className(), ['id' => 'lesson_id']);
    }

    public function getUrl()
    {
        return Yii::$app->params['frontUrl'] . Lessons::IMAGES_FOLDER . $this->filename;
    }
}
