@@ -75,25 +75,16 @@ $otherConnections = $sql->get(
|
||||
);
|
||||
|
||||
$endpointUsage = [];
|
||||
$trackUsage = static function (string $endpointType, int $endpointId, string $otherType) use (&$endpointUsage): void {
|
||||
$trackUsage = static function (string $endpointType, int $endpointId) use (&$endpointUsage): void {
|
||||
if ($endpointId <= 0) {
|
||||
return;
|
||||
}
|
||||
if (!isset($endpointUsage[$endpointType][$endpointId])) {
|
||||
$endpointUsage[$endpointType][$endpointId] = [
|
||||
'total' => 0,
|
||||
'patchpanel' => 0,
|
||||
'other' => 0,
|
||||
];
|
||||
}
|
||||
$endpointUsage[$endpointType][$endpointId]['total']++;
|
||||
if ($endpointType === 'outlet') {
|
||||
if ($otherType === 'patchpanel') {
|
||||
$endpointUsage[$endpointType][$endpointId]['patchpanel']++;
|
||||
} else {
|
||||
$endpointUsage[$endpointType][$endpointId]['other']++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach ((array)$otherConnections as $row) {
|
||||
@@ -102,43 +93,29 @@ foreach ((array)$otherConnections as $row) {
|
||||
$idA = (int)($row['port_a_id'] ?? 0);
|
||||
$idB = (int)($row['port_b_id'] ?? 0);
|
||||
|
||||
$trackUsage($typeA, $idA, $typeB);
|
||||
$trackUsage($typeB, $idB, $typeA);
|
||||
$trackUsage($typeA, $idA);
|
||||
$trackUsage($typeB, $idB);
|
||||
}
|
||||
|
||||
$validateEndpointUsage = static function (string $endpointType, int $endpointId, string $otherType, string $label) use ($endpointUsage): ?string {
|
||||
$validateEndpointUsage = static function (string $endpointType, int $endpointId, string $label) use ($endpointUsage): ?string {
|
||||
if ($endpointId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stats = $endpointUsage[$endpointType][$endpointId] ?? ['total' => 0, 'patchpanel' => 0, 'other' => 0];
|
||||
$stats = $endpointUsage[$endpointType][$endpointId] ?? ['total' => 0];
|
||||
if ((int)$stats['total'] <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($endpointType !== 'outlet') {
|
||||
return $label . " ist bereits in Verwendung";
|
||||
}
|
||||
|
||||
if ($otherType === 'patchpanel') {
|
||||
if ((int)$stats['patchpanel'] > 0) {
|
||||
return $label . " hat bereits eine Patchpanel-Verbindung";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((int)$stats['other'] > 0) {
|
||||
return $label . " hat bereits eine Endgeraete-Verbindung";
|
||||
}
|
||||
return null;
|
||||
return $label . " ist bereits in Verwendung";
|
||||
};
|
||||
|
||||
$errorA = $validateEndpointUsage($portAType, $portAId, $portBType, 'Port an Endpunkt A');
|
||||
$errorA = $validateEndpointUsage($portAType, $portAId, 'Port an Endpunkt A');
|
||||
if ($errorA !== null) {
|
||||
$errors[] = $errorA;
|
||||
}
|
||||
|
||||
$errorB = $validateEndpointUsage($portBType, $portBId, $portAType, 'Port an Endpunkt B');
|
||||
$errorB = $validateEndpointUsage($portBType, $portBId, 'Port an Endpunkt B');
|
||||
if ($errorB !== null) {
|
||||
$errors[] = $errorB;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user