Favoriten überarbeitet

This commit is contained in:
2026-04-11 18:44:25 +02:00
parent 624c4e918e
commit 769ebc3ba8
5 changed files with 377 additions and 41 deletions
+84
View File
@@ -33,6 +33,8 @@ const DEFAULT_LOCATION_LONGITUDE = 11.189;
const DEFAULT_LOCATION_ELEVATION = 640.0;
const DEFAULT_LOCATION_TIMEZONE = 'Europe/Berlin';
const DEFAULT_SATELLITE_ID = 61;
const DEFAULT_MINORPLANET_NUMBER = 1;
const DEFAULT_COMET_SEARCH = 'Halley';
function sendRegistrationNotification(string $username, string $email, ?string $displayName): void
{
@@ -77,6 +79,39 @@ function textLength(string $value): int
return strlen($value);
}
function findDefaultMinorplanetId(PDO $pdo): ?int
{
$stmt = $pdo->prepare("
SELECT `id`
FROM `minorplanets_mpc`
WHERE `mp_number` = :mp_number
LIMIT 1
");
$stmt->execute([
':mp_number' => DEFAULT_MINORPLANET_NUMBER,
]);
$id = $stmt->fetchColumn();
return $id !== false ? (int) $id : null;
}
function findDefaultCometId(PDO $pdo): ?int
{
$stmt = $pdo->prepare("
SELECT `id`
FROM `comets_mpc`
WHERE `designation_and_name` LIKE :search
ORDER BY `designation_and_name` ASC, `id` ASC
LIMIT 1
");
$stmt->execute([
':search' => '%' . DEFAULT_COMET_SEARCH . '%',
]);
$id = $stmt->fetchColumn();
return $id !== false ? (int) $id : null;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$email = trim($_POST['email'] ?? '');
@@ -131,6 +166,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($errors)) {
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$defaultMinorplanetId = findDefaultMinorplanetId($pdo);
$defaultCometId = findDefaultCometId($pdo);
if ($defaultMinorplanetId === null) {
$errors[] = 'Der Standard-Kleinplanet Ceres wurde in der Datenbank nicht gefunden.';
}
if ($defaultCometId === null) {
$errors[] = 'Der Standard-Komet Halley wurde in der Datenbank nicht gefunden.';
}
}
if (empty($errors)) {
$pdo->beginTransaction();
try {
@@ -215,6 +263,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
':satellite_id' => DEFAULT_SATELLITE_ID,
]);
$stmtInsertMinorplanet = $pdo->prepare("
INSERT INTO `app_user_minorplanets` (
`user_id`,
`minorplanet_id`,
`is_favorite`,
`created_at`
) VALUES (
:user_id,
:minorplanet_id,
1,
NOW()
)
");
$stmtInsertMinorplanet->execute([
':user_id' => $userId,
':minorplanet_id' => $defaultMinorplanetId,
]);
$stmtInsertComet = $pdo->prepare("
INSERT INTO `app_user_comets` (
`user_id`,
`comet_id`,
`is_favorite`,
`created_at`
) VALUES (
:user_id,
:comet_id,
1,
NOW()
)
");
$stmtInsertComet->execute([
':user_id' => $userId,
':comet_id' => $defaultCometId,
]);
$pdo->commit();
} catch (Throwable $e) {
if ($pdo->inTransaction()) {