108 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						||
 | 
						||
namespace common\models;
 | 
						||
 | 
						||
use Yii;
 | 
						||
use function Symfony\Component\String\s;
 | 
						||
 | 
						||
/**
 | 
						||
 * This is the model class for table "product".
 | 
						||
 *
 | 
						||
 * @property int $id
 | 
						||
 * @property string $title
 | 
						||
 * @property string $article
 | 
						||
 * @property int $company_id
 | 
						||
 * @property int|null $type
 | 
						||
 * @property int|null $price
 | 
						||
 * @property int|null $status
 | 
						||
 * @property int $product_category_id
 | 
						||
 *
 | 
						||
 * @property Company $company
 | 
						||
 */
 | 
						||
class Product extends \yii\db\ActiveRecord
 | 
						||
{
 | 
						||
    const STATUS_ACTIVE = 1;
 | 
						||
    const STATUS_INACTIVE = 0;
 | 
						||
 | 
						||
    const TYPE_PIECE = 1;
 | 
						||
    const TYPE_WEIGHT = 2;
 | 
						||
 | 
						||
    /**
 | 
						||
     * @return string[]
 | 
						||
     */
 | 
						||
    public static function getType(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            self::TYPE_PIECE => 'шт.',
 | 
						||
            self::TYPE_WEIGHT => 'кг.',
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * @return string[]
 | 
						||
     */
 | 
						||
    public static function getStatus(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            self::STATUS_ACTIVE => 'Активна',
 | 
						||
            self::STATUS_INACTIVE => 'Не активна',
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * {@inheritdoc}
 | 
						||
     */
 | 
						||
    public static function tableName(): string
 | 
						||
    {
 | 
						||
        return 'product';
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * {@inheritdoc}
 | 
						||
     */
 | 
						||
    public function rules(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            [['title', 'article', 'company_id', 'product_category_id'], 'required'],
 | 
						||
            [['company_id', 'type', 'price', 'status', 'product_category_id'], 'integer'],
 | 
						||
            [['title', 'article'], 'string', 'max' => 255],
 | 
						||
            [['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * {@inheritdoc}
 | 
						||
     */
 | 
						||
    public function attributeLabels(): array
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            'id' => 'ID',
 | 
						||
            'title' => 'Название',
 | 
						||
            'article' => 'Артикул',
 | 
						||
            'company_id' => 'Компания',
 | 
						||
            'type' => 'Тип',
 | 
						||
            'price' => 'Цена',
 | 
						||
            'status' => 'Статус',
 | 
						||
            'product_category_id' => 'Категория',
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * Gets query for [[Company]].
 | 
						||
     *
 | 
						||
     * @return \yii\db\ActiveQuery
 | 
						||
     */
 | 
						||
    public function getCompany(): \yii\db\ActiveQuery
 | 
						||
    {
 | 
						||
        return $this->hasOne(Company::class, ['id' => 'company_id']);
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * @return \yii\db\ActiveQuery
 | 
						||
     */
 | 
						||
    public function getProductCategory(): \yii\db\ActiveQuery
 | 
						||
    {
 | 
						||
        return $this->hasOne(ProductCategory::class, ['id' => 'product_category_id']);
 | 
						||
    }
 | 
						||
}
 |