| Current Path : /var/www/html/dvs/backend/modules/theme/models/ |
| Current File : /var/www/html/dvs/backend/modules/theme/models/ThemeSetting.php |
<?php
namespace backend\modules\theme\models;
use Yii;
/**
* This is the model class for table "theme_setting".
*
* @property int $setting_id
* @property int|null $setting_rule_id
* @property string|null $setting_param_name
* @property string|null $setting_param_value
* @property string|null $setting_param_type
* @property string|null $setting_param_default
*/
class ThemeSetting extends \yii\db\ActiveRecord
{
/**
*
* {@inheritdoc}
*/
public static function tableName()
{
return 'theme_setting';
}
/**
*
* {@inheritdoc}
*/
public function rules()
{
return [
[
[
'setting_rule_id'
],
'integer'
],
[
[
'setting_param_default'
],
'safe'
],
[
[
'setting_param_name',
'setting_param_type'
],
'string',
'max' => 250
],
[
[
'setting_param_value'
],
'string',
'max' => 500
]
];
}
/**
*
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'setting_id' => 'Setting ID',
'setting_rule_id' => 'Setting Rule ID',
'setting_param_name' => 'Setting Param Name',
'setting_param_value' => 'Setting Param Value'
];
}
/**
* Convert theme model to rule_id pair key
*
* @return array
*/
public static function settingArray()
{
$setting = [];
$model = self::find()->all();
array_walk($model, function ($arr) use (&$setting) {
if ($arr->setting_param_type === 'unit') {
$json = json_decode($arr->setting_param_value);
$def = json_decode($arr->setting_param_default);
$val = ! empty($json->value) ? $json->value : $def->value;
$unit = ! empty($json->value) ? $json->unit : $def->unit; // using default unit
$setting[$arr->setting_rule_id][$arr->setting_param_name] = [
'type' => 'unit',
'value' => $val,
'unit' => $unit
];
} else {
$val = ! empty($arr->setting_param_value) ? $arr->setting_param_value : $arr->setting_param_default;
$setting[$arr->setting_rule_id][$arr->setting_param_name] = $val;
}
});
return $setting;
}
}