guild/common/models/Status.php

81 lines
1.5 KiB
PHP
Raw Normal View History

2018-10-11 11:15:09 +03:00
<?php
namespace common\models;
use Yii;
2018-11-23 16:09:29 +03:00
use yii\helpers\ArrayHelper;
2018-10-11 11:15:09 +03:00
/**
* This is the model class for table "status".
*
* @property int $id
* @property string $name
*
* @property UseStatus[] $useStatuses
* @property UserCard[] $userCards
*/
class Status extends \yii\db\ActiveRecord
{
public $use = [];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'status';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'use'], 'required'],
[['name'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'use' => 'Применение',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUseStatuses()
{
return $this->hasMany(UseStatus::class, ['status_id' => 'id']);
}
2018-11-23 16:09:29 +03:00
public static function getStatusesArray($type)
{
return ArrayHelper::map(
self::find()
->joinWith('useStatuses')
->where(['`use_status`.`use`' => $type])->all(), 'id', 'name');
}
2018-10-11 11:15:09 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getUserCards()
{
return $this->hasMany(UserCard::class, ['status' => 'id']);
}
2024-02-05 23:58:48 +03:00
public static function getByName($name)
{
return Status::find()->where(['name' => $name])->one()->id ?? false;
}
2018-10-11 11:15:09 +03:00
}