changed variable dialog
This commit is contained in:
1 parent
137014a0b8
commit
662763d5a4
6 files changed
+866
-693
No files matched your search
+37
-7
@@ -239,7 +239,8 @@ class NextFloor extends IPSModuleStrict
|
||||
'state_revision' => $stateRevision,
|
||||
'building_revision' => $this->ReadAttributeInteger('BuildingRevision'),
|
||||
'variables' => $objects['variables'],
|
||||
'areas' => $objects['areas']
|
||||
'areas' => $objects['areas'],
|
||||
'objects' => $objects['objects']
|
||||
];
|
||||
}
|
||||
|
||||
@@ -254,24 +255,40 @@ class NextFloor extends IPSModuleStrict
|
||||
if ($stateRevision !== $knownRevision) {
|
||||
$result['variables'] = $objects['variables'];
|
||||
$result['areas'] = $objects['areas'];
|
||||
$result['objects'] = $objects['objects'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** Returns every selectable variable and every category that can serve as a room area. */
|
||||
/** Export real object nodes, not paths reconstructed from variable names. */
|
||||
private function objectTree(): array
|
||||
{
|
||||
$variables = [];
|
||||
$areas = [];
|
||||
$nodes = [];
|
||||
foreach (IPS_GetChildrenIDs(0) as $child) {
|
||||
$this->collectObjects($child, [], null, $variables, $areas);
|
||||
$this->collectObjects($child, [], null, $variables, $areas, $nodes);
|
||||
}
|
||||
$byVariable = [];
|
||||
foreach ($variables as $variable) {
|
||||
$byVariable[$variable['attributes']['symcon_id']] = $variable['entity_id'];
|
||||
}
|
||||
// A link stays at its original position in the tree and selects its target variable.
|
||||
foreach ($nodes as &$node) {
|
||||
if ($node['object_type'] === 6) {
|
||||
$target = (int) IPS_GetLink($node['object_id'])['TargetID'];
|
||||
if (isset($byVariable[$target])) {
|
||||
$node['entity_id'] = $byVariable[$target];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($node);
|
||||
usort($variables, static fn(array $a, array $b): int => strnatcasecmp($a['path'], $b['path']));
|
||||
usort($areas, static fn(array $a, array $b): int => strnatcasecmp($a['name'], $b['name']));
|
||||
return ['variables' => $variables, 'areas' => $areas];
|
||||
return ['variables' => $variables, 'areas' => $areas, 'objects' => $nodes];
|
||||
}
|
||||
|
||||
private function collectObjects(int $objectID, array $parents, ?int $nearestCategory, array &$variables, array &$areas): void
|
||||
private function collectObjects(int $objectID, array $parents, ?int $nearestCategory, array &$variables, array &$areas, array &$nodes): void
|
||||
{
|
||||
if (!IPS_ObjectExists($objectID)) {
|
||||
return;
|
||||
@@ -280,15 +297,28 @@ class NextFloor extends IPSModuleStrict
|
||||
$name = IPS_GetName($objectID);
|
||||
$path = [...$parents, $name];
|
||||
$type = (int) $object['ObjectType'];
|
||||
$node = [
|
||||
'object_id' => $objectID,
|
||||
'parent_id' => (int) $object['ParentID'],
|
||||
'name' => $name,
|
||||
'path' => implode(' / ', $path),
|
||||
'object_type' => $type,
|
||||
'position' => (int) $object['ObjectPosition'],
|
||||
'hidden' => (bool) $object['ObjectIsHidden'],
|
||||
'icon' => (string) $object['ObjectIcon']
|
||||
];
|
||||
if ($type === 0) { // OBJECTTYPE_CATEGORY
|
||||
$nearestCategory = $objectID;
|
||||
$areas[] = ['area_id' => 'symcon-category-' . $objectID, 'name' => implode(' / ', $path)];
|
||||
}
|
||||
if ($type === 2) { // OBJECTTYPE_VARIABLE
|
||||
$variables[] = $this->describeVariable($objectID, $name, implode(' / ', $path), $nearestCategory);
|
||||
$variable = $this->describeVariable($objectID, $name, implode(' / ', $path), $nearestCategory);
|
||||
$variables[] = $variable;
|
||||
$node['entity_id'] = $variable['entity_id'];
|
||||
}
|
||||
$nodes[] = $node;
|
||||
foreach (IPS_GetChildrenIDs($objectID) as $child) {
|
||||
$this->collectObjects($child, $path, $nearestCategory, $variables, $areas);
|
||||
$this->collectObjects($child, $path, $nearestCategory, $variables, $areas, $nodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user