<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "slider".
 *
 * @property integer $slider_id
 * @property integer $speed
 * @property integer $duration
 * @property string $title
 * @property integer $status
 * @property integer $width
 * @property integer $height
 *
 * @property SliderImage[] $sliderImage
 */
class Slider extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'slider';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['speed', 'duration', 'status', 'width', 'height'], 'integer'],
            [['title'], 'string', 'max' => 200],
            [['width', 'height', 'title'], 'required'],
            ['title', 'unique', 'targetClass' => '\common\models\Slider', 'message' =>  Yii::t('app','message',[
                'field' => 'Title'
            ])],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'slider_id' => Yii::t('app', 'slider_id'),
            'speed' => Yii::t('app', 'speed'),
            'duration' => Yii::t('app', 'duration'),
            'title' => Yii::t('app', 'title'),
            'status' => Yii::t('app', 'status'),
            'width' => Yii::t('app', 'width'),
            'height' => Yii::t('app', 'height'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSliderImage()
    {
        return $this->hasMany(SliderImage::className(), ['slider_id' => 'slider_id'])->where([SliderImage::tableName().'.status'=>1]);
    }
    
}
