Beobachtungsvorschlaege um Objektbilder und Namen erweitern
This commit is contained in:
@@ -2,6 +2,26 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Catalog values are server-owned; the client only supplies selection filters. */
|
||||
function observationDsoImage(array $row): ?string
|
||||
{
|
||||
$catalogs = [
|
||||
['messier', 'messier', 'm'],
|
||||
['ngc', 'ngc', 'ngc'],
|
||||
['ic', 'ic', 'ic'],
|
||||
];
|
||||
foreach ($catalogs as [$field, $folder, $prefix]) {
|
||||
$number = preg_replace('/\D+/', '', trim((string) ($row[$field] ?? '')));
|
||||
if ($number === '' || !ctype_digit($number)) {
|
||||
continue;
|
||||
}
|
||||
$relative = 'images/dso/' . $folder . '/' . $prefix . $number . '.png';
|
||||
if (is_file(__DIR__ . '/' . $relative)) {
|
||||
return $relative;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function observationCatalog(PDO $pdo, array $types): array
|
||||
{
|
||||
$mapping = [
|
||||
@@ -21,16 +41,30 @@ function observationCatalog(PDO $pdo, array $types): array
|
||||
$objects = [];
|
||||
if ($codes !== []) {
|
||||
$placeholders = implode(',', array_fill(0, count($codes), '?'));
|
||||
$stmt = $pdo->prepare("SELECT id, name, messier, object_type_abrev, ra_deg, dec_deg, major_axis, v_mag
|
||||
$stmt = $pdo->prepare("SELECT id, name, messier, ngc, ic, common_names_german, common_names, object_type_abrev, ra_deg, dec_deg, major_axis, v_mag
|
||||
FROM dso_objects WHERE object_type_abrev IN ($placeholders)
|
||||
AND ra_deg IS NOT NULL AND dec_deg IS NOT NULL");
|
||||
$stmt->execute(array_keys($codes));
|
||||
foreach ($stmt as $row) {
|
||||
$messier = trim((string) ($row['messier'] ?? ''));
|
||||
$messierLabel = preg_replace('/^M\s*/i', 'M', $messier);
|
||||
if ($messierLabel !== '' && !preg_match('/^M/i', $messierLabel)) {
|
||||
$messierLabel = 'M' . $messierLabel;
|
||||
}
|
||||
$commonName = trim((string) ($row['common_names_german'] ?? ''));
|
||||
if ($commonName === '') {
|
||||
$commonName = trim((string) ($row['common_names'] ?? ''));
|
||||
}
|
||||
$displayName = $row['name'];
|
||||
if ($messierLabel !== '') {
|
||||
$displayName .= ' / ' . $messierLabel;
|
||||
}
|
||||
$objects[] = [
|
||||
'id' => 'dso-' . $row['id'],
|
||||
'name' => $row['name'] . ($messier !== '' ? ' · M ' . $messier : ''),
|
||||
'name' => $displayName,
|
||||
'common_name' => $commonName,
|
||||
'group' => $codes[$row['object_type_abrev']],
|
||||
'image' => observationDsoImage($row),
|
||||
'ra_deg' => (float) $row['ra_deg'], 'dec_deg' => (float) $row['dec_deg'],
|
||||
// OpenNGC MajAx is in arcminutes; GUI and Python use arcseconds.
|
||||
'size_arcsec' => $row['major_axis'] !== null && (float) $row['major_axis'] > 0
|
||||
|
||||
Reference in New Issue
Block a user