[]]; $constellationDataError = null; try { $dbConfig = require __DIR__ . '/../planetenvorhersage/db.php'; $dsn = sprintf( 'mysql:host=%s;dbname=%s;charset=%s', $dbConfig['host'], $dbConfig['dbname'], $dbConfig['charset'] ?? 'utf8mb4' ); $pdo = new PDO($dsn, $dbConfig['user'], $dbConfig['pass'], [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); $constellations = []; $ensureConstellation = static function (string $id) use (&$constellations): void { if (!isset($constellations[$id])) { $constellations[$id] = [ 'id' => $id, 'lines' => [], 'label_positions' => [], 'common_name' => [ 'german' => null, 'native' => null, 'byname' => null, 'context' => null, ], ]; } }; $nameStmt = $pdo->query( "SELECT constellation_id, german_name, native_name, byname, context_text FROM constellation_names ORDER BY constellation_id" ); foreach ($nameStmt as $row) { $id = (string) $row['constellation_id']; $ensureConstellation($id); $constellations[$id]['common_name'] = [ 'german' => $row['german_name'] !== null ? (string) $row['german_name'] : null, 'native' => $row['native_name'] !== null ? (string) $row['native_name'] : null, 'byname' => $row['byname'] !== null ? (string) $row['byname'] : null, 'context' => $row['context_text'] !== null ? (string) $row['context_text'] : null, ]; } $labelStmt = $pdo->query( "SELECT constellation_id, position_index, ra_hours, dec_degrees FROM constellation_label_positions ORDER BY constellation_id, position_index" ); foreach ($labelStmt as $row) { $id = (string) $row['constellation_id']; $ensureConstellation($id); $constellations[$id]['label_positions'][] = [ (float) $row['ra_hours'], (float) $row['dec_degrees'], ]; } $lineStmt = $pdo->query( "SELECT cl.constellation_id, cl.line_index, clp.point_index, clp.hip_number FROM constellation_lines cl INNER JOIN constellation_line_points clp ON clp.line_id = cl.id ORDER BY cl.constellation_id, cl.line_index, clp.point_index" ); foreach ($lineStmt as $row) { $id = (string) $row['constellation_id']; $lineIndex = (int) $row['line_index']; $ensureConstellation($id); $constellations[$id]['lines'][$lineIndex] ??= []; $constellations[$id]['lines'][$lineIndex][] = (int) $row['hip_number']; } foreach ($constellations as &$constellation) { if ($constellation['lines']) { ksort($constellation['lines']); $constellation['lines'] = array_values($constellation['lines']); } } unset($constellation); uasort( $constellations, static fn(array $a, array $b): int => strcmp($a['id'], $b['id']) ); $constellationData['constellations'] = array_values($constellations); } catch (Throwable $e) { $constellationDataError = $e->getMessage(); } $constellationDataJson = json_encode( $constellationData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); $constellationDataErrorJson = json_encode( $constellationDataError, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); ?>