SystemParamModel::tableName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace yiicod\systemparams\models;
4
5
use yii\db\ActiveRecord;
6
7
/**
8
 * This is the model class for table "SystemConfig".
9
 *
10
 * The followings are the available columns in table 'SystemConfig':
11
 *
12
 * @property int $id
13
 * @property string $description
14
 * @property string $param_key
15
 * @property string $validator
16
 * @property string $param_value
17
 */
18
class SystemParamModel extends ActiveRecord
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public static function tableName()
24
    {
25
        return 'system_param';
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function rules()
32
    {
33
        return [
34
            [['param_key'], 'required'],
35
            [['param_key', 'param_value'], 'string', 'max' => 100],
36
            ['param_value', 'email', 'skipOnEmpty' => true, 'when' => function ($model) {
37
                return 'email' == $model->validator;
38
            }],
39
            ['param_value', 'integer', 'when' => function ($model) {
40
                return 'integer' == $model->validator;
41
            }],
42
            ['param_value', 'url', 'skipOnEmpty' => true, 'when' => function ($model) {
43
                return 'url' == $model->validator;
44
            }],
45
            ['param_value', 'string', 'skipOnEmpty' => true, 'when' => function ($model) {
46
                return 'string' == $model->validator;
47
            }],
48
            ['param_value', 'boolean', 'when' => function ($model) {
49
                return 'boolean' == $model->validator;
50
            }],
51
            [['description'], 'string', 'max' => 255],
52
            [['validator'], 'string', 'max' => 50],
53
        ];
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function attributeLabels()
60
    {
61
        return [
62
            'id' => 'ID',
63
            'param_key' => 'Param Key',
64
            'param_value' => 'Param Value',
65
            'description' => 'Description',
66
            'validator' => 'Validator',
67
        ];
68
    }
69
70
    /**
71
     * Get attributes map
72
     *
73
     * @return array
74
     */
75
    public static function attributesMap()
76
    {
77
        return [
78
            'fieldParamKey' => 'param_key',
79
            'fieldParamValue' => 'param_value',
80
            'fieldValidator' => 'validator',
81
            'fieldDescription' => 'description',
82
        ];
83
    }
84
}
85