personal_area_php/common/models/Product.php

108 lines
2.5 KiB
PHP
Raw Normal View History

2024-04-24 18:02:58 +03:00
<?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
2024-05-24 15:27:07 +03:00
* @property int $product_category_id
2024-04-24 18:02:58 +03:00
*
* @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}
*/
2024-05-24 15:27:07 +03:00
public static function tableName(): string
2024-04-24 18:02:58 +03:00
{
return 'product';
}
/**
* {@inheritdoc}
*/
2024-05-24 15:27:07 +03:00
public function rules(): array
2024-04-24 18:02:58 +03:00
{
return [
2024-05-24 15:27:07 +03:00
[['title', 'article', 'company_id', 'product_category_id'], 'required'],
[['company_id', 'type', 'price', 'status', 'product_category_id'], 'integer'],
2024-04-24 18:02:58 +03:00
[['title', 'article'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
2024-05-24 15:27:07 +03:00
public function attributeLabels(): array
2024-04-24 18:02:58 +03:00
{
return [
'id' => 'ID',
'title' => 'Название',
'article' => 'Артикул',
'company_id' => 'Компания',
'type' => 'Тип',
'price' => 'Цена',
'status' => 'Статус',
2024-05-24 15:27:07 +03:00
'product_category_id' => 'Категория',
2024-04-24 18:02:58 +03:00
];
}
/**
* Gets query for [[Company]].
*
* @return \yii\db\ActiveQuery
*/
2024-05-24 15:27:07 +03:00
public function getCompany(): \yii\db\ActiveQuery
2024-04-24 18:02:58 +03:00
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
2024-05-24 15:27:07 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getProductCategory(): \yii\db\ActiveQuery
{
return $this->hasOne(ProductCategory::class, ['id' => 'product_category_id']);
}
2024-04-24 18:02:58 +03:00
}