dito
This commit is contained in:
@@ -60,6 +60,7 @@ const TBL_SONNEDATUM = 'sonnedatum';
|
|||||||
const TBL_BEOS = 'beos';
|
const TBL_BEOS = 'beos';
|
||||||
const TBL_SOFIANMELD = 'sofianmeld';
|
const TBL_SOFIANMELD = 'sofianmeld';
|
||||||
const TBL_FDATES = 'fdates';
|
const TBL_FDATES = 'fdates';
|
||||||
|
const TBL_SONNEANMELD = 'sonneanmeld';
|
||||||
|
|
||||||
const URL_KALENDER = 'https://sternwarte-welzheim.de/kalender/';
|
const URL_KALENDER = 'https://sternwarte-welzheim.de/kalender/';
|
||||||
const URL_BEO_FORM = 'beoform/beoFormular.php?id=';
|
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]);
|
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
|
// expects $date as YYYYMMDD numeric string
|
||||||
$dateNum = (int)preg_replace('/[^0-9]/', '', (string)$date);
|
$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
|
public static function getByName(string $name): array
|
||||||
{
|
{
|
||||||
return DB::all("SELECT * FROM " . TBL_ANMELD . " WHERE name=? OR vorname=?", [$name, $name]);
|
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);
|
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);
|
$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);
|
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);
|
$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;
|
return isset($r['lastdate']) ? (int)$r['lastdate'] : null;
|
||||||
}
|
}
|
||||||
public static function getNew(string $special, string $date)
|
public static function getNew(string $special, string $date)
|
||||||
@@ -396,19 +402,20 @@ class RepoTermine
|
|||||||
{
|
{
|
||||||
return DB::one("SELECT * FROM " . TBL_FDATUM . " WHERE id=?", [$id]);
|
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]);
|
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;
|
return $r ? (int)$r['id'] : null;
|
||||||
}
|
}
|
||||||
public static function timeByDate(string $date, string $typ = ''): string
|
public static function timeByDate(string $date, string $typ = ''): string
|
||||||
{
|
{
|
||||||
if ($typ === 'sonnen') return '11 Uhr';
|
if ($typ === 'sonnen') return '11 Uhr';
|
||||||
$r = self::getByDate($date);
|
$r = self::getByDate($date, $typ);
|
||||||
return $r['uhrzeit'] ?? '';
|
return $r['uhrzeit'] ?? '';
|
||||||
}
|
}
|
||||||
public static function decCountByDate(string $date, int $anzahl): int
|
public static function decCountByDate(string $date, int $anzahl): int
|
||||||
@@ -715,6 +722,7 @@ class Commands
|
|||||||
// ---- Dispatcher ----
|
// ---- Dispatcher ----
|
||||||
try {
|
try {
|
||||||
ensureAuth();
|
ensureAuth();
|
||||||
|
$typ = $input['typ'] ?? 'regular';
|
||||||
|
|
||||||
switch ($cmd) {
|
switch ($cmd) {
|
||||||
case 'PING':
|
case 'PING':
|
||||||
@@ -729,7 +737,14 @@ try {
|
|||||||
if (isset($input['id'])) {
|
if (isset($input['id'])) {
|
||||||
$digits = preg_replace('/[^0-9]/', '', (string)$input['id']);
|
$digits = preg_replace('/[^0-9]/', '', (string)$input['id']);
|
||||||
if (strlen($digits) >= 8) {
|
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 {
|
} else {
|
||||||
respond(RepoAnmeld::getByFid((int)$input['id']));
|
respond(RepoAnmeld::getByFid((int)$input['id']));
|
||||||
}
|
}
|
||||||
@@ -745,7 +760,7 @@ try {
|
|||||||
if ($special !== 'alllater') respond([]);
|
if ($special !== 'alllater') respond([]);
|
||||||
respond(RepoSoFue::getAfterDate($date));
|
respond(RepoSoFue::getAfterDate($date));
|
||||||
case 'GET_TEILN_ID':
|
case 'GET_TEILN_ID':
|
||||||
$r = RepoAnmeld::getById((int)$input['id']);
|
$r = RepoAnmeld::getById((int)$input['id'], $typ);
|
||||||
respond($r ? [$r] : []);
|
respond($r ? [$r] : []);
|
||||||
case 'GET_TEILN_NAME':
|
case 'GET_TEILN_NAME':
|
||||||
respond(RepoAnmeld::getByName($input['name']));
|
respond(RepoAnmeld::getByName($input['name']));
|
||||||
@@ -753,24 +768,24 @@ try {
|
|||||||
$grp = RepoFdates::groupByDate($input['date']);
|
$grp = RepoFdates::groupByDate($input['date']);
|
||||||
respond(['grp' => $grp]);
|
respond(['grp' => $grp]);
|
||||||
case 'GET_ONEANMELD':
|
case 'GET_ONEANMELD':
|
||||||
$r = RepoAnmeld::getById((int)$input['id']);
|
$r = RepoAnmeld::getById((int)$input['id'], $typ);
|
||||||
respond($r ?: ['error' => 'Not found']);
|
respond($r ?: ['error' => 'Not found']);
|
||||||
case 'GET_COUNTS':
|
case 'GET_COUNTS':
|
||||||
if (isset($input['fdate'])) {
|
if (isset($input['fdate'])) {
|
||||||
respond(RepoAnmeld::countByDate($input['fdate']));
|
respond(RepoAnmeld::countByDate($input['fdate'], $typ));
|
||||||
}
|
}
|
||||||
if (isset($input['date'])) {
|
if (isset($input['date'])) {
|
||||||
respond(RepoAnmeld::countByDate($input['date']));
|
respond(RepoAnmeld::countByDate($input['date'], $typ));
|
||||||
}
|
}
|
||||||
if (isset($input['fid'])) {
|
if (isset($input['fid'])) {
|
||||||
respond(RepoAnmeld::countByFid((int)$input['fid']));
|
respond(RepoAnmeld::countByFid((int)$input['fid'], $typ));
|
||||||
}
|
}
|
||||||
if (isset($input['id'])) {
|
if (isset($input['id'])) {
|
||||||
respond(RepoAnmeld::countByFid((int)$input['id']));
|
respond(RepoAnmeld::countByFid((int)$input['id'], $typ));
|
||||||
}
|
}
|
||||||
respondError('Missing identifier for GET_COUNTS');
|
respondError('Missing identifier for GET_COUNTS');
|
||||||
case 'GET_COUNTS_DATE':
|
case 'GET_COUNTS_DATE':
|
||||||
respond(['count' => RepoAnmeld::countByDate($input['date'])]);
|
respond(['count' => RepoAnmeld::countByDate($input['date'], $typ)]);
|
||||||
case 'INSERT_TLN':
|
case 'INSERT_TLN':
|
||||||
if (!isset($input['name'], $input['email'], $input['anzahl'], $input['fid'])) respondError('Missing fields');
|
if (!isset($input['name'], $input['email'], $input['anzahl'], $input['fid'])) respondError('Missing fields');
|
||||||
if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) respondError('Invalid email');
|
if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) respondError('Invalid email');
|
||||||
@@ -822,17 +837,16 @@ try {
|
|||||||
case 'GET_DATES':
|
case 'GET_DATES':
|
||||||
$amount = isset($input['anzahl']) ? (int)$input['anzahl'] : 50;
|
$amount = isset($input['anzahl']) ? (int)$input['anzahl'] : 50;
|
||||||
$from = $input['date'] ?? date('Ymd');
|
$from = $input['date'] ?? date('Ymd');
|
||||||
$typ = $input['typ'] ?? 'regular';
|
|
||||||
respond(RepoTermine::getNextDates($amount, $from, $typ));
|
respond(RepoTermine::getNextDates($amount, $from, $typ));
|
||||||
case 'GET_ONETERMIN':
|
case 'GET_ONETERMIN':
|
||||||
$r = RepoTermine::getById((int)$input['id']);
|
$r = RepoTermine::getById((int)$input['id']);
|
||||||
respond($r ?: ['error' => 'Not found']);
|
respond($r ?: ['error' => 'Not found']);
|
||||||
case 'GET_FID':
|
case 'GET_FID':
|
||||||
respond(['fid' => RepoTermine::fidByDate($input['datum'])]);
|
respond(['fid' => RepoTermine::fidByDate($input['datum'], $typ)]);
|
||||||
case 'GET_TIME':
|
case 'GET_TIME':
|
||||||
respond(['time' => RepoTermine::timeByDate($input['date'], $input['typ'] ?? '')]);
|
respond(['time' => RepoTermine::timeByDate($input['date'], $input['typ'] ?? '')]);
|
||||||
case 'GET_LASTANMELDUNG':
|
case 'GET_LASTANMELDUNG':
|
||||||
$val = RepoAnmeld::lastAnmeldungAfter($input['date'] ?? date('Ymd'));
|
$val = RepoAnmeld::lastAnmeldungAfter($input['date'] ?? date('Ymd'), $typ);
|
||||||
respond($val);
|
respond($val);
|
||||||
case 'UPDATECOUNT':
|
case 'UPDATECOUNT':
|
||||||
if (!isset($input['date'], $input['anzahl'])) respondError('Missing fields');
|
if (!isset($input['date'], $input['anzahl'])) respondError('Missing fields');
|
||||||
|
|||||||
Reference in New Issue
Block a user