<?php

namespace app\models;

use Yii;

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

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['item_id', 'image_path', 'sort_order'], 'required'],
            [['item_id', 'sort_order'], 'integer'],
            [['image_path'], 'string', 'max' => 500],
            [['item_id'], 'exist', 'skipOnError' => true, 'targetClass' => Items::className(), 'targetAttribute' => ['item_id' => 'id']],
            [['image_path'], 'safe'],
            [['image_path'], 'file', 'maxFiles' => 10, 'extensions'=>'jpg, png, jpeg'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'item_id' => Yii::t('app', 'Item ID'),
            'image_path' => Yii::t('app', 'Images'),
            'sort_order' => Yii::t('app', 'Sort Order'),
        ];
    }

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