<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "item_variations".
 *
 * @property int $id
 * @property int $item_id
 * @property string $arabic_desription
 * @property string $english_description
 * @property float $price
 *
 * @property Items $item
 */
class ItemVariations extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'item_variations';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['item_id'], 'required'],
            [['arabic_description'], 'required', 'when' => function ($model){
                return false;
            }, 'whenClient' => "function (attribute, value) {
                return $('#arabic_description1');
            }"],
            [['english_description'], 'required', 'when' => function ($model){
                return false;
            }, 'whenClient' => "function (attribute, value) {
                return $('#english_description1');
            }"],

            [['arabic_details'], 'required', 'when' => function ($model){
                return false;
            }, 'whenClient' => "function (attribute, value) {
                return $('#arabic_details1');
            }"],
            [['english_details'], 'required', 'when' => function ($model){
                return false;
            }, 'whenClient' => "function (attribute, value) {
                return $('#english_details1');
            }"],

            [['price'], 'required', 'when' => function ($model){
                return false;
            }, 'whenClient' => "function (attribute, value) {
                return $('#price1');
            }"],
            [['item_id'], 'integer'],
            [['price'], 'number'],
            [['arabic_description', 'english_description'], 'string', 'max' => 50],
            [['item_id'], 'exist', 'skipOnError' => true, 'targetClass' => Items::className(), 'targetAttribute' => ['item_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'item_id' => Yii::t('app', 'Item ID'),
            'arabic_description' => Yii::t('app', 'Arabic Description'),
            'english_description' => Yii::t('app', 'English Description'),
            'arabic_details' => Yii::t('app', 'Arabic Details'),
            'english_details' => Yii::t('app', 'English Details'),
            'price' => Yii::t('app', 'Price'),
        ];
    }

    /**
     * Gets query for [[Item]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getItem()
    {
        return $this->hasOne(Items::className(), ['id' => 'item_id']);
    }
}
