Skip to content

Commit

Permalink
Scenes refactoring
Browse files Browse the repository at this point in the history
Scenes code clean-up and refactoring
  • Loading branch information
sergejey committed Feb 4, 2023
1 parent f50ae31 commit 2e582d0
Show file tree
Hide file tree
Showing 8 changed files with 1,233 additions and 1,297 deletions.
30 changes: 15 additions & 15 deletions modules/scenes/scenes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,40 +1019,44 @@ function delete_elm_states($id)
}


function loadWidgetTypes() {
include DIR_MODULES . 'scenes/widget_types.inc.php';
function loadWidgetTypes()
{
if (!isset($this->widget_types['text'])) {
include DIR_MODULES . 'scenes/widget_types.inc.php';
}
}

function getWidgetData($element_id) {
function getWidgetData($element_id)
{

$widgetData = array();

$element = SQLSelectOne("SELECT * FROM elements WHERE ID=".(int)$element_id);
$element = SQLSelectOne("SELECT * FROM elements WHERE ID=" . (int)$element_id);
if (!$element['ID']) return '';

$data = json_decode($element['WIZARD_DATA'], true);
if (isset($this->widget_types[$data['WIDGET_TYPE']])) {
$widget_type = $this->widget_types[$data['WIDGET_TYPE']];
$widgetData['TYPE'] = $data['WIDGET_TYPE'];
$widgetData['TYPE_DETAILS'] = $widget_type;
if (preg_match('/file:(.+)/',$widget_type['TEMPLATE'],$m)) {
$filename = DIR_TEMPLATES.'scenes/widgets/'.$m[1];
if (preg_match('/file:(.+)/', $widget_type['TEMPLATE'], $m)) {
$filename = DIR_TEMPLATES . 'scenes/widgets/' . $m[1];
if (file_exists($filename)) {
$template = LoadFile($filename);
} else {
$template = 'File not found: '.$filename;
$template = 'File not found: ' . $filename;
}
} else {
$template = $widget_type['TEMPLATE'];
}
$data['element_id'] = $element_id;
foreach($data as $k=>$v) {
$template = str_replace('%'.$k.'%',$v,$template);
foreach ($data as $k => $v) {
$template = str_replace('%' . $k . '%', $v, $template);
}
$html = $template;

} else {
$html = 'Incorrect widget type: '.$data['WIDGET_TYPE'];
$html = 'Incorrect widget type: ' . $data['WIDGET_TYPE'];
}

$widgetData['HTML'] = $html;
Expand Down Expand Up @@ -1193,6 +1197,7 @@ function checkState($id)
function getDynamicElements($qry = '1')
{

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

$totale = count($elements);
Expand Down Expand Up @@ -1303,7 +1308,6 @@ function getDynamicElements($qry = '1')
}



}
return $res2;

Expand Down Expand Up @@ -1640,11 +1644,9 @@ function getStyles($type = '')
function getWatchedProperties($scenes)
{

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

$qry = '1';

if (!isset($scenes['all'])) {
$qry .= " AND (0 ";
foreach ($scenes as $k => $v) {
Expand All @@ -1656,8 +1658,6 @@ function getWatchedProperties($scenes)
$qry .= ")";
}

//DebMes("qry: ".$qry);

$states = array();
$elements = $this->getDynamicElements($qry);
$total = count($elements);
Expand Down
Loading

0 comments on commit 2e582d0

Please sign in to comment.