Spots.php 2.17 KB
<?php

namespace common\models;

use Yii;
use common\models;

/**
 * This is the model class for table "{{%spots}}".
 *
 * @property integer $id
 * @property string $difficulty_level
 * @property string $coordinates_x
 * @property string $coordinates_y
 * @property integer $address
 * @property integer $email
 * @property string $description
 * @property string $gallery
 * @property string $how_to_get
 * @property string $name
 * @property string $schools_id
 * @property string $forecast_id
 * @property string $forecast_code
 */
class Spots extends GalleryRecord
{
    public $file_three;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%spots}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['gallery', 'how_to_get','address', 'email','description'], 'string'],
            [['name'], 'required'],
            [['file_three'], 'file'],
            [['difficulty_level', 'coordinates_x', 'coordinates_y', 'name','schools_id','forecast_id','forecast_code'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'difficulty_level' => 'Difficulty Level',
            'coordinates_x' => 'Coordinates X',
            'coordinates_y' => 'Coordinates Y',
            'address' => 'Address',
            'email' => 'Email',
            'description' => 'Description',
            'gallery' => 'Gallery',
            'how_to_get' => 'How To Get',
            'name' => 'Name',
            'forecast_id'=> 'ID прогноза',
            'forecast_code'=> 'Код прогноза'
        ];
    }


    function isActive($array)
    {
        $array = explode(',' , $array);
        if(in_array($this->id, $array)){
            return "checked";
        } else{
            return "";
        }
    }

    public function behaviors()
    {
        return [
            'slug' => [
                'class' => 'common\behaviors\Slug',
                'in_attribute' => 'name',
                'out_attribute' => 'translit',
                'translit' => true
            ]
        ];
    }
}