Erlaube feste Verdrahtung plus Patchkabel fuer Outlet/Patchpanel
closes #26
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user