Skip to content

Commit 2e582d0

Browse files
committed
Scenes refactoring
Scenes code clean-up and refactoring
1 parent f50ae31 commit 2e582d0

File tree

8 files changed

+1233
-1297
lines changed

8 files changed

+1233
-1297
lines changed

modules/scenes/scenes.class.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,40 +1019,44 @@ function delete_elm_states($id)
10191019
}
10201020

10211021

1022-
function loadWidgetTypes() {
1023-
include DIR_MODULES . 'scenes/widget_types.inc.php';
1022+
function loadWidgetTypes()
1023+
{
1024+
if (!isset($this->widget_types['text'])) {
1025+
include DIR_MODULES . 'scenes/widget_types.inc.php';
1026+
}
10241027
}
10251028

1026-
function getWidgetData($element_id) {
1029+
function getWidgetData($element_id)
1030+
{
10271031

10281032
$widgetData = array();
10291033

1030-
$element = SQLSelectOne("SELECT * FROM elements WHERE ID=".(int)$element_id);
1034+
$element = SQLSelectOne("SELECT * FROM elements WHERE ID=" . (int)$element_id);
10311035
if (!$element['ID']) return '';
10321036

10331037
$data = json_decode($element['WIZARD_DATA'], true);
10341038
if (isset($this->widget_types[$data['WIDGET_TYPE']])) {
10351039
$widget_type = $this->widget_types[$data['WIDGET_TYPE']];
10361040
$widgetData['TYPE'] = $data['WIDGET_TYPE'];
10371041
$widgetData['TYPE_DETAILS'] = $widget_type;
1038-
if (preg_match('/file:(.+)/',$widget_type['TEMPLATE'],$m)) {
1039-
$filename = DIR_TEMPLATES.'scenes/widgets/'.$m[1];
1042+
if (preg_match('/file:(.+)/', $widget_type['TEMPLATE'], $m)) {
1043+
$filename = DIR_TEMPLATES . 'scenes/widgets/' . $m[1];
10401044
if (file_exists($filename)) {
10411045
$template = LoadFile($filename);
10421046
} else {
1043-
$template = 'File not found: '.$filename;
1047+
$template = 'File not found: ' . $filename;
10441048
}
10451049
} else {
10461050
$template = $widget_type['TEMPLATE'];
10471051
}
10481052
$data['element_id'] = $element_id;
1049-
foreach($data as $k=>$v) {
1050-
$template = str_replace('%'.$k.'%',$v,$template);
1053+
foreach ($data as $k => $v) {
1054+
$template = str_replace('%' . $k . '%', $v, $template);
10511055
}
10521056
$html = $template;
10531057

10541058
} else {
1055-
$html = 'Incorrect widget type: '.$data['WIDGET_TYPE'];
1059+
$html = 'Incorrect widget type: ' . $data['WIDGET_TYPE'];
10561060
}
10571061

10581062
$widgetData['HTML'] = $html;
@@ -1193,6 +1197,7 @@ function checkState($id)
11931197
function getDynamicElements($qry = '1')
11941198
{
11951199

1200+
$this->loadWidgetTypes();
11961201
$elements = SQLSelect("SELECT elements.* FROM elements, scenes WHERE elements.SCENE_ID=scenes.ID AND $qry ORDER BY PRIORITY DESC, TITLE");
11971202

11981203
$totale = count($elements);
@@ -1303,7 +1308,6 @@ function getDynamicElements($qry = '1')
13031308
}
13041309

13051310

1306-
13071311
}
13081312
return $res2;
13091313

@@ -1640,11 +1644,9 @@ function getStyles($type = '')
16401644
function getWatchedProperties($scenes)
16411645
{
16421646

1643-
//DebMes("Getting watched properties for ".serialize($scenes));
16441647
$this->loadWidgetTypes();
16451648

16461649
$qry = '1';
1647-
16481650
if (!isset($scenes['all'])) {
16491651
$qry .= " AND (0 ";
16501652
foreach ($scenes as $k => $v) {
@@ -1656,8 +1658,6 @@ function getWatchedProperties($scenes)
16561658
$qry .= ")";
16571659
}
16581660

1659-
//DebMes("qry: ".$qry);
1660-
16611661
$states = array();
16621662
$elements = $this->getDynamicElements($qry);
16631663
$total = count($elements);

0 commit comments

Comments
 (0)