Region.php 2.18 KB
<?php

namespace common\modules\location\models;

use Yii;
use thread\app\base\models\ActiveRecord;
use thread\modules\location\Location as MainModule;


/**
 * Class Region
 *
 * @property integer id
 * @property integer position
 * @property integer created_at
 * @property integer updated_at
 * @property boolean published
 * @property boolean deleted
 * @property \yii\db\ActiveQuery $lang
 *
 * @author Alla Kuzmenko
 * @package common\modules\location\models
 */
class Region extends ActiveRecord
{

    const moduleName = 'location';

    /**
     * @return null|object|string
     */
    public static function getDb()
    {
        return MainModule::getDb();
    }

    /**
     * @return string
     */
    public static function tableName()
    {
        return '{{%location_region}}';
    }

    /**
     * @return array
     */
    public function rules()
    {
        return [
            [['created_at', 'updated_at', 'position'], 'integer'],
            [['published', 'deleted'], 'in', 'range' => array_keys(static::statusKeyRange())],
        ];
    }

    /**
     * @return array
     */
    public function scenarios()
    {
        return [
            'published' => ['published'],
            'deleted' => ['deleted'],
            'position' => ['position'],
            'backend' => [
                'position',
                'published',
                'deleted'
            ]
        ];
    }

    /**
     * @return array
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'position' => Yii::t('app', 'Position'),
            'created_at' => Yii::t('app', 'Create time'),
            'updated_at' => Yii::t('app', 'Update time'),
            'published' => Yii::t('app', 'Published'),
            'deleted' => Yii::t('app', 'Deleted'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLang()
    {
        return $this->hasOne(RegionLang::class, ['rid' => 'id']);
    }

    /**
     * @return Module|null the module instance, `null` if the module does not exist.
     */
    public static function getModule()
    {
        return Yii::$app->getModule(self::moduleName);
    }
}