98 lines
2.1 KiB
PHP
98 lines
2.1 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 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()
|
|||
|
{
|
|||
|
return 'product';
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* {@inheritdoc}
|
|||
|
*/
|
|||
|
public function rules()
|
|||
|
{
|
|||
|
return [
|
|||
|
[['title', 'article', 'company_id'], 'required'],
|
|||
|
[['company_id', 'type', 'price', 'status'], 'integer'],
|
|||
|
[['title', 'article'], 'string', 'max' => 255],
|
|||
|
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* {@inheritdoc}
|
|||
|
*/
|
|||
|
public function attributeLabels()
|
|||
|
{
|
|||
|
return [
|
|||
|
'id' => 'ID',
|
|||
|
'title' => 'Название',
|
|||
|
'article' => 'Артикул',
|
|||
|
'company_id' => 'Компания',
|
|||
|
'type' => 'Тип',
|
|||
|
'price' => 'Цена',
|
|||
|
'status' => 'Статус',
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Gets query for [[Company]].
|
|||
|
*
|
|||
|
* @return \yii\db\ActiveQuery
|
|||
|
*/
|
|||
|
public function getCompany()
|
|||
|
{
|
|||
|
return $this->hasOne(Company::class, ['id' => 'company_id']);
|
|||
|
}
|
|||
|
}
|