Options.php 1.88 KB
<?php

namespace frontend\models;

use Yii;

/**
 * This is the model class for table "option".
 *
 * @property integer $option_id
 * @property string $option_key
 * @property integer $option_parent
 * @property integer $option_translatable
 * @property string $option_format
 *
 * @property OptionValues[] $optionValues
 * @property Options $optionParent
 * @property Options[] $options
 */
class Options extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName ()
    {
        return 'option';
    }

    /**
     * @inheritdoc
     */
    public function rules ()
    {
        return [
            [['option_key'], 'required'], [['option_parent', 'option_translatable'], 'integer'], [['option_key', 'option_format'], 'string', 'max' => 200]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels ()
    {
        return [
            'option_id' => Yii::t ('app', 'Option ID'), 'option_key' => Yii::t ('app', 'Option Key'), 'option_parent' => Yii::t ('app', 'Option Parent'), 'option_translatable' => Yii::t ('app', 'Option Translatable'), 'option_format' => Yii::t ('app', 'Option Format'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOptionLang ()
    {
        return $this->hasMany (OptionLang::className (), ['option_id' => 'option_id']);
    }

    public function getValue ()
    {
        return $this->hasOne(OptionLang::className(), ['option_id' => 'option_id'])->where(['option_lang.language_id' => '0']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOptionParent()
    {
        return $this->hasOne(Options::className(), ['option_id' => 'option_parent']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOptions()
    {
        return $this->hasMany(Options::className(), ['option_parent' => 'option_id']);
    }
}