This commit is contained in:
rxf
2025-11-17 21:32:11 +01:00
parent ca5bc00187
commit 45eeb5a9c9

View File

@@ -60,6 +60,7 @@ const TBL_SONNEDATUM = 'sonnedatum';
const TBL_BEOS = 'beos';
const TBL_SOFIANMELD = 'sofianmeld';
const TBL_FDATES = 'fdates';
const TBL_SONNEANMELD = 'sonneanmeld';
const URL_KALENDER = 'https://sternwarte-welzheim.de/kalender/';
const URL_BEO_FORM = 'beoform/beoFormular.php?id=';
@@ -192,35 +193,40 @@ class RepoAnmeld
{
return DB::all("SELECT * FROM " . TBL_ANMELD . " WHERE fid=? ORDER BY angemeldet DESC", [$fid]);
}
public static function getByDate(string $date): array
public static function getByDate(string $date, string $typ): array
{
$table = ($typ === 'regular') ? TBL_ANMELD : TBL_SONNEANMELD;
// expects $date as YYYYMMDD numeric string
$dateNum = (int)preg_replace('/[^0-9]/', '', (string)$date);
return DB::all("SELECT * FROM " . TBL_ANMELD . " WHERE fdatum=? ORDER BY angemeldet DESC", [$dateNum]);
return DB::all("SELECT * FROM " . $table . " WHERE fdatum=? ORDER BY angemeldet DESC", [$dateNum]);
}
public static function getById(int $id): ?array
public static function getById(int $id, string $typ = ''): ?array
{
return DB::one("SELECT * FROM " . TBL_ANMELD . " WHERE id=?", [$id]);
$table = ($typ === 'sonnen') ? TBL_SONNEANMELD : TBL_ANMELD;
return DB::one("SELECT * FROM " . $table . " WHERE id=?", [$id]);
}
public static function getByName(string $name): array
{
return DB::all("SELECT * FROM " . TBL_ANMELD . " WHERE name=? OR vorname=?", [$name, $name]);
}
public static function countByFid(int $fid): int
public static function countByFid(int $fid, string $typ): int
{
$r = DB::one("SELECT SUM(anzahl) c FROM " . TBL_ANMELD . " WHERE fid=?", [$fid]);
$table = ($typ == 'regular') ? TBL_ANMELD : TBL_SONNEANMELD;
$r = DB::one("SELECT SUM(anzahl) c FROM " . $table . " WHERE fid=?", [$fid]);
return (int)($r['c'] ?? 0);
}
public static function countByDate(string $date): int
public static function countByDate(string $date, string $typ): int
{
$dateNum = (int)preg_replace('/[^0-9]/', '', (string)$date);
$r = DB::one("SELECT SUM(anzahl) c FROM " . TBL_ANMELD . " WHERE fdatum=?", [$dateNum]);
$table = ($typ == 'regular') ? TBL_ANMELD : TBL_SONNEANMELD;
$r = DB::one("SELECT SUM(anzahl) c FROM " . $table . " WHERE fdatum=?", [$dateNum]);
return (int)($r['c'] ?? 0);
}
public static function lastAnmeldungAfter(string $date): ?int
public static function lastAnmeldungAfter(string $date, string $typ): ?int
{
$table = ($typ == 'regular') ? TBL_ANMELD : TBL_SONNEANMELD;
$dateNum = (int)preg_replace('/[^0-9]/', '', (string)$date);
$r = DB::one("SELECT MAX(fdatum) lastdate FROM " . TBL_ANMELD . " WHERE fdatum>=? AND anzahl!=0", [$dateNum]);
$r = DB::one("SELECT MAX(fdatum) lastdate FROM " . $table . " WHERE fdatum>=? AND anzahl!=0", [$dateNum]);
return isset($r['lastdate']) ? (int)$r['lastdate'] : null;
}
public static function getNew(string $special, string $date)
@@ -396,19 +402,20 @@ class RepoTermine
{
return DB::one("SELECT * FROM " . TBL_FDATUM . " WHERE id=?", [$id]);
}
public static function getByDate(string $date): ?array
public static function getByDate(string $date, string $typ): ?array
{
$table = ($typ == 'regular') ? TBL_FDATUM : TBL_SONNEDATUM;
return DB::one("SELECT * FROM " . TBL_FDATUM . " WHERE datum=?", [$date]);
}
public static function fidByDate(string $date): ?int
public static function fidByDate(string $date, string $typ): ?int
{
$r = self::getByDate($date);
$r = self::getByDate($date, $typ);
return $r ? (int)$r['id'] : null;
}
public static function timeByDate(string $date, string $typ = ''): string
{
if ($typ === 'sonnen') return '11 Uhr';
$r = self::getByDate($date);
$r = self::getByDate($date, $typ);
return $r['uhrzeit'] ?? '';
}
public static function decCountByDate(string $date, int $anzahl): int
@@ -715,6 +722,7 @@ class Commands
// ---- Dispatcher ----
try {
ensureAuth();
$typ = $input['typ'] ?? 'regular';
switch ($cmd) {
case 'PING':
@@ -729,7 +737,14 @@ try {
if (isset($input['id'])) {
$digits = preg_replace('/[^0-9]/', '', (string)$input['id']);
if (strlen($digits) >= 8) {
respond(RepoAnmeld::getByDate($digits));
// For sonnen type, use the appropriate table/repository
if ($typ === 'sonnen') {
// For Sonnenführungen, we need to get registrations by date from anmeldungen table
// The anmeldungen table stores all types, so we just query by date
respond(RepoAnmeld::getByDate($digits, $typ));
} else {
respond(RepoAnmeld::getByDate($digits, $typ));
}
} else {
respond(RepoAnmeld::getByFid((int)$input['id']));
}
@@ -745,7 +760,7 @@ try {
if ($special !== 'alllater') respond([]);
respond(RepoSoFue::getAfterDate($date));
case 'GET_TEILN_ID':
$r = RepoAnmeld::getById((int)$input['id']);
$r = RepoAnmeld::getById((int)$input['id'], $typ);
respond($r ? [$r] : []);
case 'GET_TEILN_NAME':
respond(RepoAnmeld::getByName($input['name']));
@@ -753,24 +768,24 @@ try {
$grp = RepoFdates::groupByDate($input['date']);
respond(['grp' => $grp]);
case 'GET_ONEANMELD':
$r = RepoAnmeld::getById((int)$input['id']);
$r = RepoAnmeld::getById((int)$input['id'], $typ);
respond($r ?: ['error' => 'Not found']);
case 'GET_COUNTS':
if (isset($input['fdate'])) {
respond(RepoAnmeld::countByDate($input['fdate']));
respond(RepoAnmeld::countByDate($input['fdate'], $typ));
}
if (isset($input['date'])) {
respond(RepoAnmeld::countByDate($input['date']));
respond(RepoAnmeld::countByDate($input['date'], $typ));
}
if (isset($input['fid'])) {
respond(RepoAnmeld::countByFid((int)$input['fid']));
respond(RepoAnmeld::countByFid((int)$input['fid'], $typ));
}
if (isset($input['id'])) {
respond(RepoAnmeld::countByFid((int)$input['id']));
respond(RepoAnmeld::countByFid((int)$input['id'], $typ));
}
respondError('Missing identifier for GET_COUNTS');
case 'GET_COUNTS_DATE':
respond(['count' => RepoAnmeld::countByDate($input['date'])]);
respond(['count' => RepoAnmeld::countByDate($input['date'], $typ)]);
case 'INSERT_TLN':
if (!isset($input['name'], $input['email'], $input['anzahl'], $input['fid'])) respondError('Missing fields');
if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) respondError('Invalid email');
@@ -822,17 +837,16 @@ try {
case 'GET_DATES':
$amount = isset($input['anzahl']) ? (int)$input['anzahl'] : 50;
$from = $input['date'] ?? date('Ymd');
$typ = $input['typ'] ?? 'regular';
respond(RepoTermine::getNextDates($amount, $from, $typ));
case 'GET_ONETERMIN':
$r = RepoTermine::getById((int)$input['id']);
respond($r ?: ['error' => 'Not found']);
case 'GET_FID':
respond(['fid' => RepoTermine::fidByDate($input['datum'])]);
respond(['fid' => RepoTermine::fidByDate($input['datum'], $typ)]);
case 'GET_TIME':
respond(['time' => RepoTermine::timeByDate($input['date'], $input['typ'] ?? '')]);
case 'GET_LASTANMELDUNG':
$val = RepoAnmeld::lastAnmeldungAfter($input['date'] ?? date('Ymd'));
$val = RepoAnmeld::lastAnmeldungAfter($input['date'] ?? date('Ymd'), $typ);
respond($val);
case 'UPDATECOUNT':
if (!isset($input['date'], $input['anzahl'])) respondError('Missing fields');