portal.mkgtu.ru/common/models/settings/ApplicationsSettings.php

80 lines
1.2 KiB
PHP
Raw Normal View History

2024-03-28 09:51:45 +03:00
<?php
namespace common\models\settings;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
class ApplicationsSettings extends ActiveRecord
{
public static function tableName()
{
return '{{%applications_settings}}';
}
public function rules()
{
return [
[
['name', 'type'],
'string',
],
[
[
'description',
'value'
],
'string',
'max' => 1000
],
[
['value'],
'string',
],
];
}
public function attributeLabels()
{
return ['value' => $this->description];
}
public static function getValueByName(string $name): string
{
if (ApplicationsSettings::getDb()->getTableSchema(ApplicationsSettings::tableName()) === null) {
return '';
}
$setting = ApplicationsSettings::findOne(['name' => $name]);
if ($setting) {
return $setting->value;
}
return '';
}
}