<?php

namespace common\models;

use common\modules\language\models\Language;
use Yii;

/**
 * This is the model class for table "seo_dynamic_lang".
 *
 * @property integer $seo_dynamic_id
 * @property integer $language_id
 * @property string $name
 * @property string $title
 * @property string $h1
 * @property string $key
 * @property string $meta
 * @property string $description
 * @property string $seo_text
 *
 * @property Language $language
 * @property SeoDynamic $seoDynamic
 */
class SeoDynamicLang extends \yii\db\ActiveRecord
{
    
    public static function primaryKey()
    {
        return [
            'seo_dynamic_id',
            'language_id',
        ];
    }
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'seo_dynamic_lang';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'description', 'seo_text'], 'string'],
            [['name', 'h1', 'key', 'meta'], 'string', 'max' => 255],
            [['seo_dynamic_id', 'language_id'], 'unique', 'targetAttribute' => ['seo_dynamic_id', 'language_id'], 'message' => 'The combination of Seo Dynamic ID and Language ID has already been taken.'],
            [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']],
            [['seo_dynamic_id'], 'exist', 'skipOnError' => true, 'targetClass' => SeoDynamic::className(), 'targetAttribute' => ['seo_dynamic_id' => 'seo_dynamic_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'),
            'language_id' => Yii::t('app', 'language_id'),
            'name' => Yii::t('app', 'name'),
            'title' => Yii::t('app', 'title'),
            'h1' => Yii::t('app', 'h1'),
            'key' => Yii::t('app', 'key'),
            'meta' => Yii::t('app', 'meta'),
            'description' => Yii::t('app', 'description'),
            'seo_text' => Yii::t('app', 'seo_text'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLanguage()
    {
        return $this->hasOne(Language::className(), ['language_id' => 'language_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSeoDynamic()
    {
        return $this->hasOne(SeoDynamic::className(), ['seo_dynamic_id' => 'seo_dynamic_id']);
    }
}
