register starts is now possible in the new materialize version
This commit is contained in:
@@ -1,341 +1,63 @@
|
||||
<?php
|
||||
|
||||
require_once 'participoLib/dbConnector.php';
|
||||
require_once 'participoLib/apiKey.php';
|
||||
|
||||
/**
|
||||
* frame for a shiai
|
||||
*/
|
||||
class Shiai
|
||||
{
|
||||
private $id = null; //< unique id
|
||||
private $date = null; //< date of the shiai
|
||||
private $name = null; //< name of the shiai as string
|
||||
private $ageclasses = null; //< age classes as space separated Uxy in a string
|
||||
private $place = null; //< place of the shiai as string
|
||||
private $announcementUrl = null; //< url to the announcement
|
||||
private $routeUrl = null; //< url to a routing planner
|
||||
private $galleryUrl = null; //< url of the gallery to a gallery of the shiai
|
||||
private $promoImgUrl = null; //< promotional image for the shiai (as url)
|
||||
|
||||
public function __construct($id, $date, $name, $ageclasses, $place, $announcementUrl, $routeUrl, $galleryUrl, $promoImgUrl)
|
||||
{
|
||||
//! @todo input validation and sanitation
|
||||
$this->id = (int) $id;
|
||||
$this->date = DateTime::createFromFormat('Y-m-d', $date);
|
||||
$this->name = $name;
|
||||
$this->ageclasses = $ageclasses;
|
||||
$this->place = $place;
|
||||
$this->announcementUrl = $announcementUrl;
|
||||
$this->routeUrl = $routeUrl;
|
||||
$this->galleryUrl = $galleryUrl;
|
||||
$this->promoImgUrl = $promoImgUrl;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return ($this->name != null ? $this->name : 'Wettkampf ohne Namen');
|
||||
}
|
||||
|
||||
public function getHtmlDate()
|
||||
{
|
||||
return ($this->date != null ? $this->date->format('Y-m-d') : 'fehlendes Datum');
|
||||
}
|
||||
|
||||
public function getAgeClasses()
|
||||
{
|
||||
return ($this->ageclasses != null ? $this->ageclasses : '-');
|
||||
}
|
||||
|
||||
public function getPlace()
|
||||
{
|
||||
return ($this->place != null ? $this->place : '-');
|
||||
}
|
||||
|
||||
public static function fromArray($member)
|
||||
{
|
||||
return new shiai(
|
||||
$member['lfdeNr'] ?? null,
|
||||
$member['Datum'] ?? null,
|
||||
$member['Veranstaltung'] ?? '<fehlender Name>',
|
||||
$member['Altersklassen'] ?? null,
|
||||
$member['Ort'] ?? '<fehlender Ort>',
|
||||
$member['Ausschreibung'] ?? null,
|
||||
$member['Routenplaner'] ?? null,
|
||||
$member['galleryLink'] ?? null,
|
||||
$member['promoPic'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* shiai event as html code for displaying
|
||||
*
|
||||
* @return html formated string
|
||||
*/
|
||||
public function getHtml()
|
||||
{
|
||||
$retHtml = '';
|
||||
$retHtml =
|
||||
'<div>' .
|
||||
'<h3>' . $this->getName() . '</h3>' .
|
||||
'<dl>' .
|
||||
'<dt>Datum:</dt><dd>' . $this->getHtmlDate() . '</dd>' .
|
||||
'<dt>Altersklassen</dt><dd>' . $this->getAgeClasses() . '</dd>' .
|
||||
'<dt>Ort</dt><dd>' . $this->getPlace() . '</dd>' .
|
||||
'</dl>' .
|
||||
'</div>';
|
||||
return $retHtml;
|
||||
}
|
||||
} // end class shiai
|
||||
|
||||
/**
|
||||
* Framework for a event
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
private $id = null; //< unique id of the event in the db
|
||||
private $date = null; //< date for the event (@todo ranges?)
|
||||
private $shiaiId = null; //< unique id of the shiai in the db (if appropriate)
|
||||
private $deadline = null; //< until when one can register for the event
|
||||
private $remarks = null; //< remarks to the event (special rules) or a json object for missing data (e.g. non-shiai events)
|
||||
|
||||
private $shiai = null; //< a place to load the linked shiai to (if loaded)
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param int $id id in the database
|
||||
* @param string $date date of the event as string in the format "YYYY-MM-DD"
|
||||
* @param int $shiaiId id of the linked shiai or null if not appropriate
|
||||
* @param string $deadline deadline for sign ins in the format "YYYY-MM-DD"
|
||||
* @param string $remarks (json formatted) string with meta information
|
||||
* @param Shiai $shiai if the shiai is loaded anyway it can be placed here.
|
||||
*/
|
||||
public function __construct($id, $date, $shiaiId, $deadline, $remarks, $shiai)
|
||||
{
|
||||
//! @todo InputValidation
|
||||
$this->id = (int) $id;
|
||||
$this->date = DateTime::createFromFormat('Y-m-d', $date);
|
||||
$this->shiaiId = (($shiaiId != null) ? ((int)$shiaiId) : (null));
|
||||
$this->deadline = DateTime::createFromFormat('Y-m-d', $deadline);
|
||||
$this->remarks = $remarks;
|
||||
|
||||
$this->shiai = $shiai;
|
||||
}
|
||||
|
||||
/**
|
||||
* Representation of an event as (materializeCss) card
|
||||
*
|
||||
* @return string string with the html code of the event
|
||||
*/
|
||||
public function asHtmlCard()
|
||||
{
|
||||
return
|
||||
'<div class="card blue-grey darken-1">' .
|
||||
'<div class="card-content white-text">' .
|
||||
'<span class="card-title">' . $this->shiai->getName() . '</span>' .
|
||||
'<dl>' .
|
||||
'<dt>Datum</dt>' .
|
||||
'<dd>' . $this->date->format('Y-m-d') . '</dd>' .
|
||||
'<dt>Meldefrist</dt>' .
|
||||
'<dd>' . $this->deadline->format('Y-m-d') . '</dd>' .
|
||||
'<dt>Altersklassen</dt>' .
|
||||
'<dd>' . $this->shiai->getAgeClasses() . '</dd>' .
|
||||
'</div>' .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
public function htmlTableRow()
|
||||
{
|
||||
return
|
||||
'<tr>' .
|
||||
'<td>' . $this->date->format('Y-m-d') . '</td>' .
|
||||
'<td><a href="/pages/desktop/wkParticipo/showWkEvent.php?eventId=' . $this->id . '" >' . $this->shiai->getName() . '</a></td>' .
|
||||
'<td><a class="waves-effect waves-light btn-floating modal-trigger" href="#event-modal-' . $this->id . '"><i class="material-icons">zoom_in
|
||||
</i></a></td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
public function htmlModal()
|
||||
{
|
||||
return
|
||||
'<div id="event-modal-' . $this->id . '" class="modal black-text">' .
|
||||
'<div class="modal-content">' .
|
||||
$this->shiai->getHtml() .
|
||||
'</div>' . // end modal content
|
||||
'<div class="modal-footer">' .
|
||||
'<a href="/pages/desktop/wkParticipo/showWkEvent.php?eventId=' . $this->id . '" class="modal-close waves-effect waves-green btn-flat">Zum Event im Planer</a>' .
|
||||
'<a href="#!" class="modal-close waves-effect waves-green btn-flat">Schließen</a>' .
|
||||
'</div>' .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
public static function fromArray($member)
|
||||
{
|
||||
$shiai = json_decode($member['bemerkungen'], true);
|
||||
|
||||
return new event(
|
||||
$member['id'] ?? null,
|
||||
$member['date'] ?? null,
|
||||
$member['wkId'] ?? null,
|
||||
$member['meldefrist'] ?? null,
|
||||
$member['bemerkungen'] ?? null,
|
||||
shiai::fromArray(($shiai != null) ? $shiai : $member)
|
||||
);
|
||||
}
|
||||
|
||||
/// Einen Starter per userId mit typeId zu einem Event per eventId hinzufügen
|
||||
/// Es erfolgt keine Überprüfung der Meldeberechtigung!
|
||||
public static function addStarter($dbConnection, $starter)
|
||||
{
|
||||
$retMessage = [];
|
||||
|
||||
$query = 'INSERT INTO `wkParticipo_Starter` (eventId, userId, type) values (:eventId, :userId, :typeId);';
|
||||
$params = [
|
||||
':eventId' => ['value' => $starter->getEventId(), 'data_type' => PDO::PARAM_INT],
|
||||
':userId' => ['value' => $starter->getUserId(), 'data_type' => PDO::PARAM_INT],
|
||||
':typeId' => ['value' => $starter->getTypeId(), 'data_type' => PDO::PARAM_INT]
|
||||
];
|
||||
|
||||
return dbConnector::query($query, $params);
|
||||
}
|
||||
} // end class event
|
||||
|
||||
abstract class StartingType
|
||||
{
|
||||
const __default = null;
|
||||
|
||||
const Fighter = 1;
|
||||
const Audience = 2;
|
||||
const NoParticipation = 3;
|
||||
|
||||
/**
|
||||
* convert a variable into a StartingType
|
||||
*
|
||||
* @param [int] $type starting type candidate
|
||||
* @return int representation of the StartingType if successful converted, otherwise null
|
||||
*/
|
||||
public static function toStartingType($type)
|
||||
{
|
||||
return filter_var($type, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1, 'max_range' => 3]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* string representations of the starting type
|
||||
*
|
||||
* @var array array of StartingType=> its string representation
|
||||
*/
|
||||
public static $AsString = [1 => 'Kämpfer', 2 => 'Zuschauer', 3 => 'keine Teilnahme'];
|
||||
}
|
||||
|
||||
class Starter
|
||||
{
|
||||
private $id = null; //< id of the event in the database
|
||||
private $eventId = null; //< dbId of the event one is starting
|
||||
private $typeId = null; //< type(id) of the starter
|
||||
private $userId = null; //< id of the starting user
|
||||
private $rideId = null; //< id of the ride where the starter can car pool
|
||||
private $mass = null; //< mass in kg on the scale
|
||||
private $result = null; //< result of the start (array of places if multi start)
|
||||
|
||||
// Getter for the member
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getEventId()
|
||||
{
|
||||
return $this->eventId;
|
||||
}
|
||||
|
||||
public function getTypeId()
|
||||
{
|
||||
return $this->typeId;
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getRideId()
|
||||
{
|
||||
return $this->rideId;
|
||||
}
|
||||
|
||||
public function getMass()
|
||||
{
|
||||
return $this->mass;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construtor
|
||||
*
|
||||
* @todo Document
|
||||
* @todo Rethink validation: filter_var is supposed to return the converted value in case of success. But the reference didn't say anything about not success...
|
||||
*/
|
||||
public function __construct($id, $eventId, $typeId, $userId, $rideId, $mass, $result)
|
||||
{
|
||||
$this->id = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
||||
$this->eventId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
||||
$this->typeId = StartingType::toStartingType($type);
|
||||
$this->userId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
||||
$this->rideId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
||||
$this->mass = filter_var($mass, FILTER_VALIDATE_FLOAT, ['options' => ['default' => null, 'min_range' => 0.0]]);
|
||||
|
||||
if (is_iterable($result)) {
|
||||
$this->result = [];
|
||||
foreach ($result as $r) {
|
||||
$r = filter_var($r, FILTER_VAR_INT, ['options' => ['default' => null, 'min_range' => 0]]);
|
||||
if ($r) {
|
||||
array_push($this->result, $r);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->$result = filter_var($r, FILTER_VAR_INT, ['options' => ['default' => null, 'min_range' => 0]]);
|
||||
}
|
||||
}
|
||||
|
||||
// create starter from assoc array
|
||||
public static function create($parameter)
|
||||
{
|
||||
$id = $parameter['id'] ?? null; //< id of the event in the database
|
||||
$eventId = $parameter['eventId'] ?? null; //< dbId of the event one is starting
|
||||
$typeId = $parameter['typeId'] ?? null; //< type(id) of the starter
|
||||
$userId = $parameter['userId'] ?? null; //< id of the starting user
|
||||
$rideId = $parameter['rideId'] ?? null; //< id of the ride where the starter can car pool
|
||||
$mass = $parameter['mass'] ?? null; //< mass in kg on the scale
|
||||
$result = $parameter['result'] ?? null; //< result of the start (array of places if multi start)
|
||||
|
||||
return new Starter($id, $eventId, $typeId, $userId, $rideId, $mass, $result);
|
||||
}
|
||||
}
|
||||
require_once 'participoLib/shiai.php';
|
||||
require_once 'participoLib/event.php';
|
||||
require_once 'participoLib/starter.php';
|
||||
|
||||
class eventPlaner
|
||||
{
|
||||
private static $db = null;
|
||||
// db table column names
|
||||
private static $dbTable = [
|
||||
'events' => 'wkParticipo_Events',
|
||||
'starts' => 'wkParticipo_Starter',
|
||||
'user' => 'wkParticipo_Users',
|
||||
'shiaiCal' => 'wettkampfkalender',
|
||||
'wardship' => 'vormundschaft'
|
||||
];
|
||||
|
||||
// set the dbConnection (just setting, no establishing)
|
||||
public static function setDbConnection($dbConnection)
|
||||
private static function getComingStarts($sinceDate = null, $userId = null)
|
||||
{
|
||||
if ($dbConnection instanceof PDO) {
|
||||
self::$db = $dbConnection;
|
||||
} else {
|
||||
self::$db = null;
|
||||
}
|
||||
return;
|
||||
$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 getCommingWkEvents($someOptions = [])
|
||||
public static function getComingWkEvents($someOptions = [])
|
||||
{
|
||||
// wir befinden uns in der Übergangsphase:
|
||||
// - als Standard wird das derzeitige Verhalten definiert (ISO-8859-1
|
||||
@@ -365,7 +87,7 @@ class eventPlaner
|
||||
'ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ' .
|
||||
'WHERE wkParticipo_Events.date >= CURDATE() ' .
|
||||
'ORDER BY wkParticipo_Events.date;';
|
||||
$ret = dbQuery(self::$db, $query);
|
||||
$ret = dbConnector::query($query);
|
||||
$events = [];
|
||||
foreach ($ret as $event) {
|
||||
array_push($events, event::fromArray($event));
|
||||
@@ -385,4 +107,37 @@ class eventPlaner
|
||||
}
|
||||
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']);
|
||||
$today = new DateTime();
|
||||
$htmlTable .= '<tr>'
|
||||
. '<td>' . $s['eventDate'] . '</td>'
|
||||
. '<td>' . $s['eventName'] . '</td>'
|
||||
. '<td>' . $s['userName'] . ', ' . $s['userFirstname'] . '</td>'
|
||||
. '<td>' . ($eventDeadline <= $today ? Event::getHtmlRemoveStarterForm($s['eventId'], $s['userId']) : '') . '</td>'
|
||||
. '</tr>';
|
||||
}
|
||||
$htmlTable .= '</tbody></table>';
|
||||
echo('<h2 id="comingStarts">Aktuelle Einschreibungen</h2>');
|
||||
echo($htmlTable);
|
||||
} else {
|
||||
echo('<div>Keine Meldungen zu bevorstehenden Events<div>');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user