register starts is now possible in the new materialize version
This commit is contained in:
209
homepage/participo/lib/participoLib/event.php
Normal file
209
homepage/participo/lib/participoLib/event.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
public static function loadFromDb(int $id)
|
||||
{
|
||||
$query = 'SELECT * FROM `cwsvjudo`.`wkParticipo_Events` WHERE `id` = :id;';
|
||||
$params = [':id' => ['value' => $id, 'data_type' => PDO::PARAM_INT]];
|
||||
$response = dbConnector::query($query, $params);
|
||||
|
||||
// ids are considered unique. so every other count then 1 is treated as error to prevent unprivileged access
|
||||
if (count($response) != 1) {
|
||||
return null;
|
||||
}
|
||||
return Event::fromDbArray($response[0]);
|
||||
}
|
||||
|
||||
/** 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->getHtmlName() . '</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->getHtmlName() . '</a></td>' .
|
||||
'<td>' . $this->shiai->getAgeClasses() . '</td>' .
|
||||
'<td><a class="waves-effect waves-light btn modal-trigger" href="#event-modal-' . $this->id . '"><i class="material-icons">zoom_in</i></a></td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
public function htmlModal()
|
||||
{
|
||||
$modal =
|
||||
'<div id="event-modal-' . $this->id . '" class="modal black-text">'
|
||||
. '<div class="modal-content">'
|
||||
. $this->shiai->getHtml()
|
||||
. $this->getHtmlStarterList();
|
||||
$kids = participo::getKids();
|
||||
$modal .= '<div class="row">';
|
||||
foreach ($kids as $k) {
|
||||
$modal .= $this->getHtmlAddStarterForm($k);
|
||||
}
|
||||
$modal .= '</div>';
|
||||
$modal .=
|
||||
'</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>' . // end modal-footer
|
||||
'</div>';
|
||||
echo($modal);
|
||||
}
|
||||
|
||||
public function getHtmlStarterList()
|
||||
{
|
||||
$listOfStarter = $this->getStarter();
|
||||
|
||||
if (!isset($listOfStarter) || count($listOfStarter) == 0) {
|
||||
return '';
|
||||
}
|
||||
$starterList .= 'Bereits eingetragen: <div class="row">';
|
||||
foreach ($listOfStarter as $s) {
|
||||
$u = $s->getUser();
|
||||
$starterList .= '<div class="col s6 m3">' . $u->getName() . ', ' . $u->getFirstname() . $this->getHtmlRemoveStarterForm($s->getEventId(), $s->getUserId()) . '</div>';
|
||||
}
|
||||
$starterList .= '</div>';
|
||||
return $starterList;
|
||||
}
|
||||
|
||||
/** Returns the currents users starter to this event
|
||||
*
|
||||
* @todo docu
|
||||
*/
|
||||
private function getStarter()
|
||||
{
|
||||
$userId = $_SESSION['user']['userId'] ?? null;
|
||||
|
||||
$query = 'SELECT `wkParticipo_Starter`.`id` as `starterId` FROM `wkParticipo_Starter` '
|
||||
. 'LEFT JOIN `vormundschaft` ON `vormundschaft`.`kidId` = `wkParticipo_Starter`.`userId` '
|
||||
. ' WHERE `wkParticipo_Starter`.`eventId` = :eventId AND `vormundschaft`.`userId` = :userId;';
|
||||
$params = [
|
||||
':eventId' => ['value' => $this->id, 'data_type' => PDO::PARAM_INT],
|
||||
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]
|
||||
];
|
||||
$response = dbConnector::query($query, $params);
|
||||
|
||||
$starter = [];
|
||||
foreach ($response as $r) {
|
||||
$starter[] = Starter::loadFromDb($r['starterId']);
|
||||
}
|
||||
return $starter;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// @todo docu
|
||||
public static function getHtmlRemoveStarterForm($eventId, $userId, $class = null)
|
||||
{
|
||||
$form =
|
||||
'<form ' . (isset($class) ? ('class="' . $class . '"') : '') . ' action="api.starter.remove.php" method="post">'
|
||||
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . urlencode(getCurPagesUrl()) . '" >'
|
||||
. '<input type="hidden" name="eventId" id="eventId" value="' . $eventId . '">'
|
||||
. '<input type="hidden" name="userId" id="userId" value="' . $userId . '">'
|
||||
. '<button class="btn red" type="submit" name="submit">austragen</button>'
|
||||
. '</form>';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function getHtmlAddStarterForm($user)
|
||||
{
|
||||
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
|
||||
$form =
|
||||
'<form class="card col s6 m4" action="api.starter.add.php" method="post">'
|
||||
. '<input type="hidden" name="eventId" id="eventId" value="' . $this->id . '">'
|
||||
. '<input type="hidden" name="userId" id="userId" value="' . $user->getId() . '">'
|
||||
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . urlencode(getCurPagesUrl()) . '" >'
|
||||
. '<div class="input-field">'
|
||||
. '<select id="selectTypeForm" name="type">'
|
||||
. '<option value="1" selected="">als Starter</option>'
|
||||
. '<option value="2">als Zuschauer</option>'
|
||||
. '<option value="3">keine Teilnahme</option>'
|
||||
. '</select>'
|
||||
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
|
||||
. '</div>'
|
||||
. '<button class="btn" type="submit" name="submit">einschreiben</button>'
|
||||
. '</form>';
|
||||
|
||||
return $form;
|
||||
}
|
||||
} // end class event
|
||||
Reference in New Issue
Block a user