District::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace zacksleo\yii2\cms\models;
4
5
use Yii;
6
7
/**
8
 * This is the model class for table "{{%district}}".
9
 *
10
 * @property integer $id
11
 * @property string $name
12
 * @property integer $parent_id
13
 * @property string $initial
14
 * @property string $initials
15
 * @property string $pinyin
16
 * @property string $extra
17
 * @property string $suffix
18
 * @property string $code
19
 * @property string $area_code
20
 * @property integer $order
21
 * @property array[Hospital] hospitals
22
 */
23
class District extends \yii\db\ActiveRecord
24
{
25
    const BEIJING_ID = 1;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public static function tableName()
31
    {
32
        return '{{%district}}';
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function rules()
39
    {
40
        return [
41
            [['parent_id', 'order'], 'integer'],
42
            [['name'], 'string', 'max' => 270],
43
            [['initial'], 'string', 'max' => 3],
44
            [['initials', 'code', 'area_code'], 'string', 'max' => 30],
45
            [['pinyin'], 'string', 'max' => 600],
46
            [['extra'], 'string', 'max' => 60],
47
            [['suffix'], 'string', 'max' => 15],
48
        ];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function attributeLabels()
55
    {
56
        return [
57
            'id' => 'ID',
58
            'name' => 'Name',
59
            'parent_id' => 'Parent ID',
60
            'initial' => 'Initial',
61
            'initials' => 'Initials',
62
            'pinyin' => 'Pinyin',
63
            'extra' => 'Extra',
64
            'suffix' => 'Suffix',
65
            'code' => 'Code',
66
            'area_code' => 'Area Code',
67
            'order' => 'Order',
68
        ];
69
    }
70
71
    public function fields()
72
    {
73
        $fields = [];
74
        $fields['province'] = function () {
75
            return $this->name;
76
        };
77
        return $fields;
78
    }
79
80
    /**
81
     * @return \yii\db\ActiveQuery
82
     */
83
    public function getChildren()
84
    {
85
        return $this->hasMany(District::className(), ['parent_id' => 'id']);
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
86
    }
87
88
    /**
89
     * @return \yii\db\ActiveQuery
90
     */
91
    public function getParent()
92
    {
93
        return $this->hasOne(District::className(), ['id' => 'parent_id']);
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
94
    }
95
}
96