banki.test/models/Parameter.php

76 lines
1.4 KiB
PHP

<?php
namespace app\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "parameters".
*
* @property int $id
* @property string $title
* @property int $type
*/
class Parameter extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'parameters';
}
public function getIcon()
{
return $this->hasOne(Image::class, [ 'id' => 'icon' ]);
}
public function getIconGray()
{
return $this->hasOne(Image::class, [ 'id' => 'icon_gray' ]);
}
public function fields()
{
$fields = parent::fields();
$fields['icon'] = function (Parameter $parameter) {
return $parameter->relatedRecords['icon'];
};
$fields['icon_gray'] = function (Parameter $parameter) {
return $parameter->relatedRecords['iconGray'];
};
return $fields;
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'type'], 'required'],
[['type'], 'integer'],
[['title'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Title',
'type' => 'Type (either 1 or 2)',
'icon' => 'Icon',
'icon_gray' => 'Gray icon',
];
}
}