147 lines
5.0 KiB
PHP
147 lines
5.0 KiB
PHP
<?php
|
|
|
|
require_once 'participoLib/participo.php';
|
|
require_once 'participoLib/dbConnector.php';
|
|
require_once 'participoLib/apiKey.php';
|
|
require_once 'participoLib/shiai.php';
|
|
require_once 'participoLib/event.php';
|
|
require_once 'participoLib/starter.php';
|
|
|
|
class eventPlaner
|
|
{
|
|
// db table column names
|
|
private static $dbTable = [
|
|
'events' => 'wkParticipo_Events',
|
|
'starts' => 'wkParticipo_Starter',
|
|
'user' => 'wkParticipo_Users',
|
|
'shiaiCal' => 'wettkampfkalender',
|
|
'wardship' => 'vormundschaft'
|
|
];
|
|
|
|
private static function getComingStarts($sinceDate = null, $userId = null)
|
|
{
|
|
$userId = $userId ?? $_SESSION['user']['userId'];
|
|
$sinceDate = $sinceDate ?? new DateTime();
|
|
|
|
$params = [
|
|
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT],
|
|
':sinceDate' => ['value' => $sinceDate->format('Y-m-d'), 'data_type' => PDO::PARAM_STR]
|
|
];
|
|
|
|
// shorter variable names for better readability
|
|
$starts = self::$dbTable['starts'];
|
|
$user = self::$dbTable['user'];
|
|
$events = self::$dbTable['events'];
|
|
$shiaiCal = self::$dbTable['shiaiCal'];
|
|
$wardship = self::$dbTable['wardship'];
|
|
|
|
$query =
|
|
'SELECT '
|
|
. '`' . $events . '`.`id` as eventId, '
|
|
. '`' . $events . '`.`date` as eventDate, '
|
|
. '`' . $events . '`.`meldefrist` as deadline, '
|
|
. '`' . $starts . '`.`id` as starterId, '
|
|
. '`' . $user . '`.`id` as userId, '
|
|
. '`' . $user . '`.`name` as userName, '
|
|
. '`' . $user . '`.`vorname` as userFirstname, '
|
|
. '`' . $shiaiCal . '`.`veranstaltung` as eventName '
|
|
. 'FROM `' . $starts . '` '
|
|
. 'LEFT JOIN `' . $user . '` ON `' . $starts . '`.`userId` = `' . $user . '`.`id` '
|
|
. 'LEFT JOIN `' . $events . '` ON `' . $starts . '`.`eventId` = `' . $events . '`.`id` '
|
|
. 'LEFT JOIN `' . $shiaiCal . '` ON `' . $events . '`.`wkId` = `' . $shiaiCal . '`.`lfdeNr` '
|
|
. 'LEFT JOIN `' . $wardship . '` ON `' . $user . '`.`id` = `' . $wardship . '`.`kidId` '
|
|
. 'WHERE `' . $events . '`.`date` >= :sinceDate AND ( `' . $wardship . '`.`userId` = :userId OR `' . $starts . '`.`userId` = :userId ) '
|
|
. 'ORDER BY `' . $events . '`.`date` DESC;';
|
|
|
|
$comingStarts = dbConnector::query($query, $params);
|
|
|
|
return $comingStarts;
|
|
}
|
|
|
|
public static function getComingWkEvents($someOptions = [])
|
|
{
|
|
// wir befinden uns in der Übergangsphase:
|
|
// - als Standard wird das derzeitige Verhalten definiert (ISO-8859-1
|
|
// und die Konvertierung erfolgt ausserhalb)
|
|
// - wenn einmal alle mbConvertEncoding weg sind, kann der Standard auf
|
|
// das gewünschte Verhalten umgestellt werden
|
|
$dbCharset = $someOptions['dbCharset'] ?? 'ISO-8859-1';
|
|
// dbCharset = $someOptions['outCharset'] ?? "UTF-8";// das spätere, gewünschte Verhalten
|
|
$outCharset = $someOptions['outCharset'] ?? 'ISO-8859-1';
|
|
|
|
$query =
|
|
'SELECT ' .
|
|
'wkParticipo_Events.id, ' .
|
|
'wkParticipo_Events.date, ' .
|
|
'wkParticipo_Events.wkId, ' .
|
|
'wkParticipo_Events.meldefrist, ' .
|
|
'wkParticipo_Events.bemerkungen, ' .
|
|
'wkParticipo_Events.kvOptions, ' .
|
|
'wettkampfkalender.Datum, ' .
|
|
'wettkampfkalender.Veranstaltung, ' .
|
|
'wettkampfkalender.Altersklassen, ' .
|
|
'wettkampfkalender.Ort, ' .
|
|
'wettkampfkalender.Ausschreibung, ' .
|
|
'wettkampfkalender.Routenplaner ' .
|
|
'FROM wkParticipo_Events ' .
|
|
'LEFT JOIN wettkampfkalender ' .
|
|
'ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ' .
|
|
'WHERE wkParticipo_Events.date >= CURDATE() ' .
|
|
'ORDER BY wkParticipo_Events.date;';
|
|
$ret = dbConnector::query($query);
|
|
$events = [];
|
|
foreach ($ret as $event) {
|
|
array_push($events, event::fromArray($event));
|
|
}
|
|
return $events;
|
|
}
|
|
|
|
public static function getHtmlEventTable($eventList)
|
|
{
|
|
$ret = '<table>';
|
|
foreach ($eventList as $event) {
|
|
$ret .= $event->htmlTableRow();
|
|
}
|
|
$ret .= '</table>';
|
|
foreach ($eventList as $event) {
|
|
$ret .= $event->htmlModal();
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
// inserting html code
|
|
|
|
/** Generate the htmlCode for the list of upcoming starts of
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function htmlComingStarts()
|
|
{
|
|
$comingStarts = self::getComingStarts();
|
|
$htmlTable = null;
|
|
if ($comingStarts) {
|
|
$htmlTable = '<table>'
|
|
. '<thead><tr><th>Datum</th><th>Veranstaltung</th><th>Starter</th><th></th></tr></thead>'
|
|
. '<tbody>';
|
|
foreach ($comingStarts as $s) {
|
|
$eventDeadline = DateTime::createFromFormat('Y-m-d', $s['deadline']);
|
|
$eventDate = DateTime::createFromFormat('Y-m-d', $s['eventDate']);
|
|
$today = new DateTime();
|
|
$htmlTable .= '<tr>'
|
|
. '<td>' . getHtmlSquareDate($eventDate) . '</td>'
|
|
. '<td>' . $s['eventName'] . '</td>'
|
|
. '<td>' . $s['userName'] . ', ' . $s['userFirstname'] . '</td>'
|
|
. '<td>' . ($eventDeadline >= $today ? Event::getHtmlRemoveStarterForm($s['eventId'], $s['userId']) : '') . '</td>'
|
|
// . '<td>' . $eventDeadline->format('Y-m-d') . ' <= ' . $today->format('Y-m-d') . ': ' . ($eventDeadline <= $today ? 'true' : 'false') . '</td>'
|
|
. '</tr>';
|
|
}
|
|
$htmlTable .= '</tbody></table>';
|
|
echo('<h2 id="comingStarts">Aktuelle Einschreibungen</h2>');
|
|
echo($htmlTable);
|
|
} else {
|
|
echo('<div>Keine Meldungen zu bevorstehenden Events<div>');
|
|
}
|
|
return;
|
|
}
|
|
}
|