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
|
|
View Code Duplication |
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::className(), '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::className(), ['template_id' => 'id']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return \yii\db\ActiveQuery |
82
|
|
|
*/ |
83
|
|
|
public function getScreens() |
84
|
|
|
{ |
85
|
|
|
return $this->hasMany(Screen::className(), ['template_id' => 'id']); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return \yii\db\ActiveQuery |
90
|
|
|
*/ |
91
|
|
|
public function getBackground() |
92
|
|
|
{ |
93
|
|
|
return $this->hasOne(TemplateBackground::className(), ['id' => 'background_id']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setBackground($backgroundId) |
97
|
|
|
{ |
98
|
|
|
$this->background_id = $backgroundId; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.