Erlaube feste Verdrahtung plus Patchkabel fuer Outlet/Patchpanel

closes #26
This commit is contained in:
2026-02-19 11:00:48 +01:00
parent b973d2857b
commit dbe977f62c
4 changed files with 142 additions and 17 deletions

View File

@@ -46,7 +46,7 @@ $endpointOptions = [
'patchpanel' => [],
];
$occupiedByType = [
$occupiedStatsByType = [
'device' => [],
'module' => [],
'outlet' => [],
@@ -62,18 +62,24 @@ $occupiedRows = $sql->get(
foreach ((array)$occupiedRows as $row) {
$typeA = $normalizePortType((string)($row['port_a_type'] ?? ''));
$idA = (int)($row['port_a_id'] ?? 0);
if ($idA > 0 && isset($occupiedByType[$typeA])) {
$occupiedByType[$typeA][$idA] = true;
if ($idA > 0 && isset($occupiedStatsByType[$typeA])) {
if (!isset($occupiedStatsByType[$typeA][$idA])) {
$occupiedStatsByType[$typeA][$idA] = ['total' => 0];
}
$occupiedStatsByType[$typeA][$idA]['total']++;
}
$typeB = $normalizePortType((string)($row['port_b_type'] ?? ''));
$idB = (int)($row['port_b_id'] ?? 0);
if ($idB > 0 && isset($occupiedByType[$typeB])) {
$occupiedByType[$typeB][$idB] = true;
if ($idB > 0 && isset($occupiedStatsByType[$typeB])) {
if (!isset($occupiedStatsByType[$typeB][$idB])) {
$occupiedStatsByType[$typeB][$idB] = ['total' => 0];
}
$occupiedStatsByType[$typeB][$idB]['total']++;
}
}
$isEndpointAllowed = static function (string $type, int $id) use ($occupiedByType, $portAType, $portAId, $portBType, $portBId): bool {
$isEndpointAllowed = static function (string $type, int $id) use ($occupiedStatsByType, $portAType, $portAId, $portBType, $portBId): bool {
if ($id <= 0) {
return false;
}
@@ -83,7 +89,10 @@ $isEndpointAllowed = static function (string $type, int $id) use ($occupiedByTyp
if ($type === $portBType && $id === $portBId) {
return true;
}
return empty($occupiedByType[$type][$id]);
$stats = $occupiedStatsByType[$type][$id] ?? ['total' => 0];
$maxConnections = in_array($type, ['outlet', 'patchpanel'], true) ? 2 : 1;
return (int)($stats['total'] ?? 0) < $maxConnections;
};
// Auto-heal: ensure each outlet has at least one selectable port.