1 | <?php |
||
23 | class Screen extends \yii\db\ActiveRecord |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public static function tableName() |
||
29 | { |
||
30 | return 'screen'; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public function rules() |
||
37 | { |
||
38 | return [ |
||
39 | [['name', 'template_id'], 'required'], |
||
40 | [['duration', 'template_id'], 'integer'], |
||
41 | [['last_changes', 'template'], 'safe'], |
||
42 | [['name'], 'string', 'max' => 64], |
||
43 | [['description'], 'string', 'max' => 1024], |
||
44 | [['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => ScreenTemplate::className(), 'targetAttribute' => ['template_id' => 'id']], |
||
45 | ]; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function attributeLabels() |
||
52 | { |
||
53 | return [ |
||
54 | 'id' => Yii::t('app', 'ID'), |
||
55 | 'name' => Yii::t('app', 'Name'), |
||
56 | 'description' => Yii::t('app', 'Description'), |
||
57 | 'template_id' => Yii::t('app', 'Template'), |
||
58 | 'duration' => Yii::t('app', 'Duration'), |
||
59 | 'last_changes' => Yii::t('app', 'Last Changes'), |
||
60 | ]; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Loop through parent flows to build a flows tree. |
||
65 | * |
||
66 | * @return array flows with all parents |
||
67 | */ |
||
68 | public function allFlows() |
||
69 | { |
||
70 | $ret = []; |
||
71 | |||
72 | // Initialize main loop |
||
73 | $newFlows = $this->flows; |
||
74 | while (count($newFlows)) { |
||
75 | // Append latest loop parents |
||
76 | $ret = array_merge($ret, $newFlows); |
||
77 | |||
78 | $parents = []; |
||
79 | foreach ($newFlows as $flow) { |
||
80 | if ($flow->parent_id != null) { |
||
81 | $f = $flow->parent; |
||
82 | if ($f) { |
||
83 | $parents[] = $f; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | // Prepare next loop, will merge if necessary later |
||
88 | $newFlows = $parents; |
||
89 | } |
||
90 | |||
91 | return $ret; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Update last_modified field to force screen reload. |
||
96 | */ |
||
97 | public function setModified() |
||
102 | |||
103 | /** |
||
104 | * @return \yii\db\ActiveQuery |
||
105 | */ |
||
106 | public function getDeviceHasScreens() |
||
110 | |||
111 | /** |
||
112 | * @return \yii\db\ActiveQuery |
||
113 | */ |
||
114 | public function getDevices() |
||
118 | |||
119 | /** |
||
120 | * @return \yii\db\ActiveQuery |
||
121 | */ |
||
122 | public function getTemplate() |
||
126 | |||
127 | /** |
||
128 | * @return \yii\db\ActiveQuery |
||
129 | */ |
||
130 | public function getScreenHasFlows() |
||
134 | |||
135 | /** |
||
136 | * @return \yii\db\ActiveQuery |
||
137 | */ |
||
138 | public function getFlows() |
||
142 | } |
||
143 |