guild/common/models/Skill.php

68 lines
1.2 KiB
PHP
Raw Normal View History

2018-10-12 14:52:08 +03:00
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "skill".
*
* @property int $id
* @property string $name
2021-06-08 17:05:54 +03:00
* @property integer $category_id
2018-10-12 14:52:08 +03:00
*
* @property CardSkill[] $cardSkills
*/
class Skill extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'skill';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name'], 'required'],
2021-06-08 17:05:54 +03:00
[['category_id'], 'integer'],
2018-10-12 14:52:08 +03:00
[['name'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCardSkills()
{
return $this->hasMany(CardSkill::className(), ['skill_id' => 'id']);
}
2021-06-08 17:05:54 +03:00
public function getCategory()
{
return $this->hasOne(SkillCategory::class, ['id' => 'category_id']);
}
2021-06-09 18:06:13 +03:00
public static function getNameById($id)
{
$model = self::find()->where(['id' => $id])->one();
return $model ? $model->name : null;
}
2018-10-12 14:52:08 +03:00
}