ScreenTemplate::getFields()   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 app\models;
4
5
use Yii;
6
7
/**
8
 * This is the model class for table "screen_template".
9
 *
10
 * @property int $id
11
 * @property string $name
12
 * @property int $background_id
13
 * @property string $css
14
 * @property Field[] $fields
15
 * @property Screen[] $screens
16
 * @property TemplateBackground $background
17
 */
18
class ScreenTemplate extends \yii\db\ActiveRecord
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public static function tableName()
24
    {
25
        return 'screen_template';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function rules()
32
    {
33
        return [
34
            [['name'], 'required'],
35
            [['background_id'], 'integer'],
36
            [['css'], 'string'],
37
            [['name'], 'string', 'max' => 64],
38
            [['background'], 'safe'],
39
            [['background_id'], 'exist', 'skipOnError' => true, 'targetClass' => TemplateBackground::class, 'targetAttribute' => ['background_id' => 'id']],
40
        ];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function attributeLabels()
47
    {
48
        return [
49
            'id' => Yii::t('app', 'ID'),
50
            'name' => Yii::t('app', 'Name'),
51
            'background_id' => Yii::t('app', 'Background'),
52
            'background' => Yii::t('app', 'Background'),
53
            'css' => Yii::t('app', 'CSS'),
54
        ];
55
    }
56
57
    /**
58
     * After save event
59
     * Set screen last_modified field on changes to force screen reload.
60
     *
61
     * @param bool  $insert            is model inserted
62
     * @param array $changedAttributes
63
     */
64
    public function afterSave($insert, $changedAttributes)
65
    {
66
        parent::afterSave($insert, $changedAttributes);
67
        foreach ($this->screens as $screen) {
68
            $screen->setModified();
69
        }
70
    }
71
72
    /**
73
     * @return \yii\db\ActiveQuery
74
     */
75
    public function getFields()
76
    {
77
        return $this->hasMany(Field::class, ['template_id' => 'id']);
78
    }
79
80
    /**
81
     * @return \yii\db\ActiveQuery
82
     */
83
    public function getScreens()
84
    {
85
        return $this->hasMany(Screen::class, ['template_id' => 'id']);
86
    }
87
88
    /**
89
     * @return \yii\db\ActiveQuery
90
     */
91
    public function getBackground()
92
    {
93
        return $this->hasOne(TemplateBackground::class, ['id' => 'background_id']);
94
    }
95
96
    public function setBackground($backgroundId)
97
    {
98
        $this->background_id = $backgroundId;
99
    }
100
}
101