Bugfix: hidden select menu in starting type selection replaced by radio buttons
This commit is contained in:
49
homepage/participo/event.php
Normal file
49
homepage/participo/event.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . './lib/');
|
||||
|
||||
require_once 'participoLib/event.php';
|
||||
// require_once 'participoLib/starter.php';
|
||||
// require_once 'participoLib/planer.php';
|
||||
|
||||
// Configs
|
||||
require_once 'config/participo.php';
|
||||
require_once $config['basePath'] . '/config/cwsvJudo.config.php';
|
||||
|
||||
participo::init($cwsvJudoConfig);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<!-- shared imports (common css, MaterializeCss) -->
|
||||
<?php readfile('shared/imports.php'); ?>
|
||||
|
||||
<!-- inits for the materializeCss -->
|
||||
<script src="events.js"></script>
|
||||
|
||||
<title><?php echo($meta['title']); ?></title>
|
||||
<meta name="description"
|
||||
content="<?php echo($meta['description']); ?>" />
|
||||
|
||||
<link rel="icon" href="<?echo($config['ressourceUrl']);?>/graphiken/icons/cwsv.ico" />
|
||||
<link rel="apple-touch-icon" href="<?echo($config['baseUrl']);?>/apple-touch-icon.png">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<!-- The sidenav -->
|
||||
<?php require './events.sidenav.inc.php'; ?>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<?php participo::eventPage()->html(); ?>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,33 +1,32 @@
|
||||
<?php
|
||||
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . './lib/');
|
||||
|
||||
require_once("participoLib/participo.php");
|
||||
require_once("participoLib/planer.php");
|
||||
require_once 'participoLib/participo.php';
|
||||
require_once 'participoLib/planer.php';
|
||||
|
||||
require_once("config/participo.php");
|
||||
require_once 'config/participo.php';
|
||||
|
||||
require_once("./local/dbConf.php");
|
||||
require_once("./local/cwsvJudo.php");
|
||||
require_once './local/dbConf.php';
|
||||
require_once './local/cwsvJudo.php';
|
||||
|
||||
require_once("./lib/db.php");
|
||||
require_once("./lib/api.php");
|
||||
require_once './lib/db.php';
|
||||
require_once './lib/api.php';
|
||||
|
||||
require_once($config['basePath']."/config/cwsvJudo.config.php");
|
||||
require_once $config['basePath'] . '/config/cwsvJudo.config.php';
|
||||
|
||||
dbConnector::connect(
|
||||
$cwsvJudoConfig["db"]["host"],
|
||||
$cwsvJudoConfig["db"]["name"],
|
||||
$cwsvJudoConfig["db"]["user"],
|
||||
$cwsvJudoConfig["db"]["password"]
|
||||
);
|
||||
dbConnector::connect(
|
||||
$cwsvJudoConfig['db']['host'],
|
||||
$cwsvJudoConfig['db']['name'],
|
||||
$cwsvJudoConfig['db']['user'],
|
||||
$cwsvJudoConfig['db']['password']
|
||||
);
|
||||
|
||||
participo::authentificate();
|
||||
participo::authentificate();
|
||||
|
||||
$userData = getUserData(dbConnector::getDbConnection(), $_SESSION['user']['userId']);
|
||||
$userData = getUserData(dbConnector::getDbConnection(), $_SESSION['user']['userId']);
|
||||
|
||||
$meta = array(
|
||||
'title' => "Event Planer",
|
||||
'description' => "Planung von (Nicht-)Teilnahmen an Wettkämpfen und anderen Veranstaltungen"
|
||||
);
|
||||
?>
|
||||
$meta = [
|
||||
'title' => 'Event Planer',
|
||||
'description' => 'Planung von (Nicht-)Teilnahmen an Wettkämpfen und anderen Veranstaltungen'
|
||||
];
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
<div>
|
||||
<nav class="indigo darken-4">
|
||||
<div class="nav-wrapper">
|
||||
<div class="col s12">
|
||||
<a href="http://cwsvjudo.bplaced.net/participo" class="breadcrumb">cwsvJudo-Apps</a>
|
||||
<a href="http://cwsvjudo.bplaced.net/participo/events" class="breadcrumb">
|
||||
<?php echo($meta['title']); ?>
|
||||
</a>
|
||||
<a class="right top-nav sidenav-trigger waves-effect waves-light hide-on-large-only" href="#"
|
||||
data-target="nav-mobile">
|
||||
<i class="material-icons">menu</i>
|
||||
</a>
|
||||
</div>
|
||||
<a href="http://cwsvjudo.bplaced.net/participo" class="breadcrumb">cwsvJudo-Apps</a>
|
||||
<a href="http://cwsvjudo.bplaced.net/participo/events" class="breadcrumb">
|
||||
<?php echo($meta['title']); ?>
|
||||
</a>
|
||||
<a class="right top-nav sidenav-trigger waves-effect waves-light hide-on-large-only" href="#"
|
||||
data-target="nav-mobile">
|
||||
<i class="material-icons">menu</i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a class="right top-nav sidenav-trigger waves-effect waves-light hide-on-large-only" href="#"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
function createDb($dbConnection){
|
||||
<<<SQL
|
||||
CREATE TABLE `cwsvjudo`.`anwesenheit` (
|
||||
|
||||
@@ -90,10 +90,32 @@ class Event
|
||||
return $this->shiai;
|
||||
}
|
||||
|
||||
public static function loadFromDb(int $id)
|
||||
/** load the Event by id from the db
|
||||
*
|
||||
* - Frontend function: sanitizes the input and calls the backend function
|
||||
*
|
||||
* @param integer>0 $id id of the Event to load from the data base
|
||||
* @return Event Event from the db with this id, null in case the Event couldn't be loaded
|
||||
*/
|
||||
public static function loadFromDb($id)
|
||||
{
|
||||
$id = filterId($id);
|
||||
if ($id) {
|
||||
return self::loadFromDbById($id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads an event from the db by id
|
||||
*
|
||||
* - Backend function, input is supposed to be sanitized
|
||||
*
|
||||
* @param integer>0 $id sanitized id of the event to load
|
||||
* @return Event Event from the db with this id, null in case the Event couldn't be loaded
|
||||
*/
|
||||
private static function loadFromDbById(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);
|
||||
@@ -105,6 +127,16 @@ class Event
|
||||
return self::fromDbArray($response[0]);
|
||||
}
|
||||
|
||||
public function htmlDate($format = 'Y-m-d')
|
||||
{
|
||||
return $this->date->format($format);
|
||||
}
|
||||
|
||||
public function htmlDeadLine($format = 'Y-m-d')
|
||||
{
|
||||
return $this->deadline->format($format);
|
||||
}
|
||||
|
||||
/** Representation of an event as (materializeCss) card
|
||||
*
|
||||
* @return string string with the html code of the event
|
||||
@@ -118,9 +150,9 @@ class Event
|
||||
'<span class="card-title">' . $shiai->getHtmlName() . '</span>' .
|
||||
'<dl>' .
|
||||
'<dt>Datum</dt>' .
|
||||
'<dd>' . $this->date->format('Y-m-d') . '</dd>' .
|
||||
'<dd>' . $this->htmlDate() . '</dd>' .
|
||||
'<dt>Einschreibefrist</dt>' .
|
||||
'<dd>' . $this->deadline->format('Y-m-d') . '</dd>' .
|
||||
'<dd>' . $this->htmlDeadLine() . '</dd>' .
|
||||
'<dt>Altersklassen</dt>' .
|
||||
'<dd>' . $this->shiai()->getHtmlDescriptiveAgeClasses() . '</dd>' .
|
||||
'</dl>' .
|
||||
@@ -128,12 +160,23 @@ class Event
|
||||
'</div>';
|
||||
}
|
||||
|
||||
public function getHtmlEventDetails()
|
||||
{
|
||||
$html .= '<dl>';
|
||||
$html .= '<dt>Datum</dt><dd>' . $this->event()->htmlDate() . '</dd>';
|
||||
$html .= '<dt>Deadline zum Einschreiben:</dt><dd>' . $this->event()->htmlDeadline() . '</dd>';
|
||||
$html .= '</dl>';
|
||||
$html .= $this->event()->shiai()->getHtml();
|
||||
$html .= $this->event()->getHtmlStarterStatistic();
|
||||
$html .= $this->event()->getHtmlStarterList();
|
||||
}
|
||||
|
||||
public function htmlTableRow()
|
||||
{
|
||||
$shiai = $this->shiai();
|
||||
return
|
||||
'<tr>' .
|
||||
'<td>' . $this->date->format('Y-m-d') . '</td>' .
|
||||
'<td>' . $this->htmlDate() . '</td>' .
|
||||
'<td><a href="/participo/events#' . $this->id . '" >' . $shiai->getHtmlName() . '</a></td>' .
|
||||
'<td>' . $shiai->getHtmlDescriptiveAgeClasses() . '</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>' .
|
||||
@@ -146,10 +189,13 @@ class Event
|
||||
'<div id="event-modal-' . $this->id . '" class="modal black-text">'
|
||||
. '<div class="modal-content">'
|
||||
. $this->shiai->getHtml()
|
||||
. '<hr />'
|
||||
. $this->getHtmlStarterStatistic()
|
||||
. $this->getHtmlStarterList();
|
||||
. '<hr />'
|
||||
. $this->getHtmlStarterList()
|
||||
. '<hr />';
|
||||
$modal .= '<div class="row">';
|
||||
$modal .= '<div class="s12">Deadline zum Eintragen: ' . $this->deadline->format('Y-m-d') . '</div>';
|
||||
$modal .= '<div class="s12">Deadline zum Eintragen: ' . $this->htmlDeadLine() . '</div>';
|
||||
|
||||
$today = new DateTime();
|
||||
if (
|
||||
@@ -160,13 +206,6 @@ class Event
|
||||
foreach ($kids as $k) {
|
||||
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl' => '/participo/events#' . $this->id]);
|
||||
}
|
||||
|
||||
// foreach ($this->shiai()->ageGroups() as $ageClass => $starterList) {
|
||||
// // $modal .= '<h3>' . $ageClass ?? 'keiner Altersklasse zugeordnet' . '</h3>';
|
||||
// foreach ($starterList as $starter) {
|
||||
// $modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl' => '/participo/events#' . $this->id]);
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
$modal .= '<div>Es ist leider zu spät noch jemanden einzutragen!</div>';
|
||||
}
|
||||
@@ -175,7 +214,7 @@ class Event
|
||||
$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="/pages/desktop/wkParticipo/showWkEvent.php?eventId=' . $this->id . '" class="modal-close waves-effect waves-green btn-flat">Zum Event im alten Planer</a>' .
|
||||
'<a href="#!" class="modal-close waves-effect waves-green btn-flat">Schließen</a>' .
|
||||
'</div>' . // end modal-footer
|
||||
'</div>';
|
||||
@@ -206,7 +245,7 @@ class Event
|
||||
*
|
||||
* @todo docu
|
||||
*/
|
||||
private function getStarter()
|
||||
public function getStarter()
|
||||
{
|
||||
$userId = $_SESSION['user']['userId'] ?? null;
|
||||
|
||||
@@ -221,7 +260,7 @@ class Event
|
||||
|
||||
$starter = [];
|
||||
foreach ($response as $r) {
|
||||
$starter[] = Starter::loadFromDb($r['starterId']);
|
||||
$starter[$r['starterId']] = Starter::loadFromDb($r['starterId']);
|
||||
}
|
||||
return $starter;
|
||||
}
|
||||
@@ -250,16 +289,21 @@ class Event
|
||||
|
||||
public function getHtmlStarterStatistic()
|
||||
{
|
||||
$isEmpty = true;
|
||||
$retHtml = '<dl>';
|
||||
foreach ([StartingType::Fighter, StartingType::NoParticipation, StartingType::Audience] as $type) {
|
||||
$count = $this->getStarterCount($type);
|
||||
if ($count > 0) {
|
||||
$isEmpty = false;
|
||||
$retHtml .= '<dt>' . StartingType::$AsString[$type] . '</dt><dd>' . $count . '</dd>';
|
||||
}
|
||||
}
|
||||
$retHtml .= '<dt>Mitfahrgelegenheiten</dt><dd>' . $this->getSeatCount() . '</dd>';
|
||||
if ($this->getSeatCount() > 0) {
|
||||
$isEmpty = false;
|
||||
$retHtml .= '<dt>Mitfahrgelegenheiten</dt><dd>' . $this->getSeatCount() . '</dd>';
|
||||
}
|
||||
$retHtml .= '</dl>';
|
||||
return $retHtml;
|
||||
return $isEmpty ? '' : $retHtml;
|
||||
}
|
||||
|
||||
public static function fromDbArray($member)
|
||||
@@ -305,7 +349,7 @@ class Event
|
||||
{
|
||||
$defaults = [
|
||||
'formClass' => 's12 m6 xl3',
|
||||
'inputClass' => 'input-field col s12',
|
||||
'inputClass' => 'col s12',
|
||||
'buttonClass' => 'btn'
|
||||
];
|
||||
|
||||
@@ -322,14 +366,29 @@ class Event
|
||||
. '<input type="hidden" name="userId" id="userId" value="' . $user->getId() . '">'
|
||||
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . $returnToUrl . '" >'
|
||||
. '<div class="' . $options['inputClass'] . '">'
|
||||
. '<label for="' . $selectId . '">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
|
||||
. '<select id="' . $selectId . '" name="type">'
|
||||
. '<option value="1" selected="">als Starter</option>'
|
||||
. '<option value="2">als Zuschauer</option>'
|
||||
. '<option value="3">keine Teilnahme</option>'
|
||||
. '</select>'
|
||||
. '<fieldset id="' . $selectId . '>'
|
||||
. '<label for="' . $selectId . '">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
|
||||
. '<p>'
|
||||
. '<label for="' . $selectId . '-asStarter">'
|
||||
. '<input name="type" type="radio" id="' . $selectId . '-asStarter" value="1" />'
|
||||
. '<span>als Starter</span>'
|
||||
. '</label>'
|
||||
. '</p>'
|
||||
. '<p>'
|
||||
. '<label for="' . $selectId . '-asWatcher">'
|
||||
. '<input name="type" type="radio" id="' . $selectId . '-asWatcher" value="2" />'
|
||||
. '<span>als Zuschauer</span>'
|
||||
. '</label>'
|
||||
. '</p>'
|
||||
. '<p>'
|
||||
. '<label for="' . $selectId . '-asNone">'
|
||||
. '<input name="type" type="radio" id="' . $selectId . '-asNone" value="3" checked />'
|
||||
. '<span>keine Teilnahme</span>'
|
||||
. '</label>'
|
||||
. '</p>'
|
||||
. '<input class="' . $options['buttonClass'] . '" type="submit" name="submit" value="eintragen" />'
|
||||
. '</fieldset>'
|
||||
. '</div>'
|
||||
. '<input class="' . $options['buttonClass'] . '" type="submit" name="submit" value="eintragen">'
|
||||
. '</form>';
|
||||
|
||||
return $form;
|
||||
|
||||
96
homepage/participo/lib/participoLib/eventPage.php
Normal file
96
homepage/participo/lib/participoLib/eventPage.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
class EventPage
|
||||
{
|
||||
public function __construct($eventId = null)
|
||||
{
|
||||
$this->eventId = filterId($eventId);
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$params = participo::parseParams(
|
||||
['eventId' => function ($param) {return filterId($param); }]
|
||||
);
|
||||
$this->eventId = $params['eventId'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function getHtmlNotFound()
|
||||
{
|
||||
return '<div>Der Event "' . $this->id . '" existiert leider nicht!</div>'
|
||||
. '<h2>Anstehende Termine</h2>'
|
||||
. eventPlaner::getHtmlEventTable(
|
||||
eventPlaner::getComingWkEvents()
|
||||
);
|
||||
}
|
||||
|
||||
public function getHtml()
|
||||
{
|
||||
if (!$this->event()) {
|
||||
return $this->getHtmlNotFound();
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
$html .=
|
||||
'<div>'
|
||||
. '<dl>'
|
||||
. '<dt>Termine</dt>'
|
||||
. '<dd>
|
||||
<dl>'
|
||||
. '<dt>Datum</dt><dd>' . $this->event()->htmlDate() . '</dd>'
|
||||
. '<dt>Deadline zum Einschreiben:</dt><dd>' . $this->event()->htmlDeadline() . '</dd>'
|
||||
. '</dl>';
|
||||
// Not all Events have a shiai linked to them
|
||||
if ($this->event()->shiai()) {
|
||||
$html .=
|
||||
'<dt>Wettkampfdetails</dt><dd>' . $this->event()->shiai()->getHtmlDetails() . '</dd>';
|
||||
}
|
||||
$html .=
|
||||
'<dt>Einschreibungen</dt><dd>' . $this->event()->getHtmlStarterStatistic() . '</dd>'
|
||||
. '<dt>Eigene, gemeldete Starter</dt><dd>' . $this->event()->getHtmlStarterList() . '</dd>'
|
||||
. '</dl>'
|
||||
. '</div>';
|
||||
|
||||
$html .=
|
||||
'<div>';
|
||||
foreach ($this->event()->shiai()->ageGroups() as $ageClass => $starterList) {
|
||||
$html .=
|
||||
'<dl>' .
|
||||
'<dt>' . (!empty($ageClass) ? $ageClass : 'keiner Altersklasse zugeordnet') . '</dt>'
|
||||
. '<dd>
|
||||
<ul>';
|
||||
foreach ($starterList as $starter) {
|
||||
if (!array_key_exists($starter->getId(), $this->event()->getStarter())) {
|
||||
$html .=
|
||||
'<li>' . $starter->getName() . ', ' . $starter->getFirstname() . ' - ' . $starter->yearOfBirth() . '
|
||||
</li>';
|
||||
}
|
||||
}
|
||||
$html .= '
|
||||
</dd>
|
||||
</ul>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function html()
|
||||
{
|
||||
echo($this->getHtml());
|
||||
}
|
||||
|
||||
private function event(bool $forceLoading = false)
|
||||
{
|
||||
if (!$this->event || $forceLoading) {
|
||||
$this->event = Event::loadFromDb($this->eventId);
|
||||
}
|
||||
return $this->event;
|
||||
}
|
||||
|
||||
private $eventId = null;
|
||||
private $event = null;
|
||||
}
|
||||
@@ -2,12 +2,29 @@
|
||||
|
||||
require_once 'participoLib/dbConnector.php';
|
||||
require_once 'participoLib/user.php';
|
||||
require_once 'participoLib/event.php';
|
||||
require_once 'participoLib/eventPage.php';
|
||||
require_once 'participoLib/starter.php';
|
||||
require_once 'participoLib/planer.php';
|
||||
|
||||
/**
|
||||
* FrameWork for the participoApp
|
||||
*/
|
||||
class participo
|
||||
{
|
||||
/** a page describing an event */
|
||||
private static $eventPage = null;
|
||||
|
||||
/** getter for the eventPage, creates a new one if not already created */
|
||||
public static function eventPage()
|
||||
{
|
||||
if (!self::$eventPage) {
|
||||
self::$eventPage = new EventPage();
|
||||
}
|
||||
self::$eventPage->init();
|
||||
return self::$eventPage;
|
||||
}
|
||||
|
||||
private static $db = null;
|
||||
private static $message = ['error' => null, 'success' => null, 'notice' => null];
|
||||
|
||||
@@ -131,6 +148,64 @@ class participo
|
||||
}
|
||||
}
|
||||
|
||||
/** Initialize the participoApp
|
||||
*
|
||||
* - validate the login
|
||||
* - init the db connection
|
||||
*
|
||||
* @param [type] $config
|
||||
* @return void
|
||||
*/
|
||||
public static function init($config)
|
||||
{
|
||||
self::authentificate();
|
||||
self::initDb(
|
||||
$config['db']['host'],
|
||||
$config['db']['name'],
|
||||
$config['db']['user'],
|
||||
$config['db']['password']
|
||||
);
|
||||
}
|
||||
|
||||
private static function initDb($host, $name, $user, $password)
|
||||
{
|
||||
dbConnector::connect($host, $name, $user, $password);
|
||||
}
|
||||
|
||||
/** Framework to parse parameters get/post requests
|
||||
*
|
||||
* - Each param given in to this function is looked up in the request and put through the parsing function.
|
||||
* - Params in the request that aren't in given a parsing function aren't parsed and hence not returned.
|
||||
*
|
||||
* @param [array(paramName => parseFunction)] $params array of the name of the param and a sanitizer/parsing/input function
|
||||
* @return array(parsedParam=>paramValue) Associative array of the name of the param and its parsed value
|
||||
*/
|
||||
public static function parseParams($params)
|
||||
{
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$request = explode('/', substr(@$_SERVER['PATH_INFO'], 1));
|
||||
|
||||
$parsedParams = [];
|
||||
foreach ($params as $paramName => $parseFunction) {
|
||||
$parsedParams[$paramName] = null;
|
||||
switch ($method) {
|
||||
// case 'PUT':
|
||||
// do_something_with_put($request);
|
||||
// break;
|
||||
case 'POST':
|
||||
$parsedParams[$paramName] = $parseFunction($_POST[$paramName]);
|
||||
break;
|
||||
case 'GET':
|
||||
$parsedParams[$paramName] = $parseFunction($_GET[$paramName]);
|
||||
break;
|
||||
default:
|
||||
// handle_error($request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $parsedParams;
|
||||
}
|
||||
|
||||
public static function getMessages()
|
||||
{
|
||||
return self::$message;
|
||||
@@ -209,8 +284,13 @@ class participo
|
||||
|
||||
$query =
|
||||
'SELECT * FROM `wkParticipo_Users` '
|
||||
. 'INNER JOIN `vormundschaft` ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` '
|
||||
. 'WHERE `vormundschaft`.`userId` = :userId;';
|
||||
. 'INNER JOIN `vormundschaft` '
|
||||
. 'ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` '
|
||||
. 'INNER JOIN `wkParticipo_user<=>userAttributes` '
|
||||
. 'ON `wkParticipo_Users`.`id` = `wkParticipo_user<=>userAttributes`.`userId`'
|
||||
. 'WHERE `vormundschaft`.`userId` = :userId '
|
||||
. 'AND `vormundschaft`.`userId` = :userId '
|
||||
. 'AND `wkParticipo_user<=>userAttributes`.`attributeId` = 4;';
|
||||
$params = [':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]];
|
||||
|
||||
$response = dbConnector::query($query, $params);
|
||||
|
||||
@@ -58,6 +58,16 @@ class Shiai
|
||||
return ($this->place != null ? $this->place : '-');
|
||||
}
|
||||
|
||||
public function getAnnouncementUrl()
|
||||
{
|
||||
return $this->announcementUrl;
|
||||
}
|
||||
|
||||
public function getRouteUrl()
|
||||
{
|
||||
return $this->routeUrl;
|
||||
}
|
||||
|
||||
public static function loadFromDb(int $id)
|
||||
{
|
||||
$id = filterId($id);
|
||||
@@ -97,16 +107,28 @@ class Shiai
|
||||
$retHtml = '';
|
||||
$retHtml =
|
||||
'<div>' .
|
||||
'<h3>' . $this->getHtmlName() . '</h3>' .
|
||||
'<h3><a href="' . $this->announcementUrl . '">' . $this->getHtmlName() . '</a></h3>' .
|
||||
'<dl>' .
|
||||
'<dt>Datum</dt><dd>' . $this->getHtmlDate() . '</dd>' .
|
||||
'<dt>Altersklassen</dt><dd>' . $this->getHtmlDescriptiveAgeClasses() . '</dd>' .
|
||||
'<dt>Ort</dt><dd>' . $this->getPlace() . '</dd>' .
|
||||
'<dt>Ort</dt><dd><a href="' . $this->routeUrl . '">' . $this->getPlace() . '</a></dd>' .
|
||||
'</dl>' .
|
||||
'</div>';
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
public function getHtmlDetails()
|
||||
{
|
||||
return
|
||||
'<dl>'
|
||||
. '<dt>Name</dt><dd><a href="' . $this->announcementUrl . '">' . $this->getHtmlName() . '</a></dd>'
|
||||
. '<dt>Datum</dt><dd>' . $this->getHtmlDate() . '</dd>'
|
||||
. '<dt>Altersklassen</dt><dd>' . $this->getHtmlDescriptiveAgeClasses() . '</dd>'
|
||||
. '<dt>Ort</dt><dd><a href="' . $this->routeUrl . '">' . $this->getPlace() . '</a></dd>' .
|
||||
'</dl>'
|
||||
;
|
||||
}
|
||||
|
||||
public function getHtmlDescriptiveAgeClasses()
|
||||
{
|
||||
$retList = [];
|
||||
@@ -128,121 +150,121 @@ class Shiai
|
||||
return implode(', ', $retList);
|
||||
}
|
||||
|
||||
/** convert a list of age class formatted strings into a list of intervals of years
|
||||
*
|
||||
* @param string $akListString
|
||||
* @param int $year
|
||||
* @return list[array(int,int)] list of tupels with lower/upper bound in date year of the age classes
|
||||
*/
|
||||
private static function akListString2jgArray(string $akListString, int $year = null)
|
||||
{
|
||||
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
|
||||
$ret = [];
|
||||
foreach (explode(' ', $akListString) as $ak) {
|
||||
$ret[$ak] = self::akString2jgIntervall($ak, $year);
|
||||
/** convert a list of age class formatted strings into a list of intervals of years
|
||||
*
|
||||
* @param string $akListString
|
||||
* @param int $year
|
||||
* @return list[array(int,int)] list of tupels with lower/upper bound in date year of the age classes
|
||||
*/
|
||||
private static function akListString2jgArray(string $akListString, int $year = null)
|
||||
{
|
||||
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
|
||||
$ret = [];
|
||||
foreach (explode(' ', $akListString) as $ak) {
|
||||
$ret[$ak] = self::akString2jgIntervall($ak, $year);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/** convert age class from formatted string to interval of years
|
||||
*
|
||||
* @param [string] $akString
|
||||
* @param [type] $year
|
||||
* @return array(int,int) [x,y] with x the lower bound and y the upper bound of the age class in years. Both bounds are still included in the interval.
|
||||
*/
|
||||
private static function akString2jgIntervall(string $akString, int $year /*= null*/)
|
||||
{
|
||||
// input sanitation
|
||||
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
|
||||
/** convert age class from formatted string to interval of years
|
||||
*
|
||||
* @param [string] $akString
|
||||
* @param [type] $year
|
||||
* @return array(int,int) [x,y] with x the lower bound and y the upper bound of the age class in years. Both bounds are still included in the interval.
|
||||
*/
|
||||
private static function akString2jgIntervall(string $akString, int $year /*= null*/)
|
||||
{
|
||||
// input sanitation
|
||||
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
|
||||
|
||||
$ret = [null, null];
|
||||
$ret = [null, null];
|
||||
|
||||
// Matching against the different age class formats
|
||||
// - ..Ux
|
||||
// - Jg.x-y
|
||||
// Matching against the different age class formats
|
||||
// - ..Ux
|
||||
// - Jg.x-y
|
||||
|
||||
// Case Ux
|
||||
$akUmatchString = '/(.*)U(.*)/';
|
||||
// Case Ux
|
||||
$akUmatchString = '/(.*)U(.*)/';
|
||||
|
||||
$matches = [];
|
||||
$matches = [];
|
||||
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// The found match should cover the whole string. Otherwise it isn't applicable.
|
||||
if ($matches[0] == $akString) {
|
||||
// The x in Ux should be a positive integer.
|
||||
$ageLimit = filterPosInt($matches[2]);
|
||||
if ($ageLimit) {
|
||||
$ret[0] = $year - $ageLimit + 1;
|
||||
// lowering the lower bound according to the modifiers
|
||||
if ($matches[1] == '') {
|
||||
$ret[1] = $year - $ageLimit + 2;
|
||||
} elseif ($matches[1] == '-') {
|
||||
$ret[1] = $year - $ageLimit + 3;
|
||||
} elseif ($matches[1] == '--') {
|
||||
$ret[1] = $year - $ageLimit + 4;
|
||||
} elseif (in_array($matches[1], ['<=', '≤', '≤', '≤', '≤'])) {
|
||||
$ret[1] = $year;
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// The found match should cover the whole string. Otherwise it isn't applicable.
|
||||
if ($matches[0] == $akString) {
|
||||
// The x in Ux should be a positive integer.
|
||||
$ageLimit = filterPosInt($matches[2]);
|
||||
if ($ageLimit) {
|
||||
$ret[0] = $year - $ageLimit + 1;
|
||||
// lowering the lower bound according to the modifiers
|
||||
if ($matches[1] == '') {
|
||||
$ret[1] = $year - $ageLimit + 2;
|
||||
} elseif ($matches[1] == '-') {
|
||||
$ret[1] = $year - $ageLimit + 3;
|
||||
} elseif ($matches[1] == '--') {
|
||||
$ret[1] = $year - $ageLimit + 4;
|
||||
} elseif (in_array($matches[1], ['<=', '≤', '≤', '≤', '≤'])) {
|
||||
$ret[1] = $year;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Case Jg.x-y
|
||||
$akUmatchString = "/Jg\.(.*)\-{1,2}(.*)/";
|
||||
|
||||
$matches = [];
|
||||
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// The found match should cover the whole string. Otherwise it isn't applicable.
|
||||
|
||||
if ($matches[0] == $akString) {
|
||||
$ret[0] = filterPosInt($matches[1]);
|
||||
$ret[1] = filterPosInt($matches[2]);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Case Jg.x-y
|
||||
$akUmatchString = "/Jg\.(.*)\-(.*)/";
|
||||
|
||||
$matches = [];
|
||||
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// The found match should cover the whole string. Otherwise it isn't applicable.
|
||||
|
||||
if ($matches[0] == $akString) {
|
||||
$ret[0] = filterPosInt($matches[1]);
|
||||
$ret[1] = filterPosInt($matches[2]);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/** grouping users kids by ageGroups
|
||||
*
|
||||
* @return array(ageGroup => list(users in ageGroup))
|
||||
*/
|
||||
public function ageGroups()
|
||||
{
|
||||
$kids = participo::getKids();
|
||||
return self::ageClassGrouping($this->ageclasses, $kids);
|
||||
}
|
||||
|
||||
/** grouping users by given age class
|
||||
*
|
||||
* @param array $ageClassList as array string representation of age class => [lower year bound, upper year bound]
|
||||
* @param array $starterList list of starter (User)
|
||||
* @return array of string representation of age class => array of user in this class
|
||||
*/
|
||||
private static function ageClassGrouping(array $ageClassList, array $starterList)
|
||||
{
|
||||
$grouping = [];
|
||||
foreach ($ageClassList as $ageClass => $yearBoundaries) {
|
||||
$grouping[$ageClass] = [];
|
||||
/** grouping users kids by ageGroups
|
||||
*
|
||||
* @return array(ageGroup => list(users in ageGroup))
|
||||
*/
|
||||
public function ageGroups()
|
||||
{
|
||||
$kids = participo::getKids();
|
||||
return self::ageClassGrouping($this->ageclasses, $kids);
|
||||
}
|
||||
$grouping[null] = [];
|
||||
|
||||
foreach ($starterList as $starter) {
|
||||
$startersAgeClass = $starter->yearOfBirth() ? self::getAgeClassFromYear($starter->yearOfBirth(), $ageClassList) : null;
|
||||
array_push($grouping[$startersAgeClass], $starter);
|
||||
}
|
||||
return $grouping;
|
||||
}
|
||||
|
||||
private static function getAgeClassFromYear(int $year, array $ageClassList)
|
||||
{
|
||||
foreach ($ageClassList as $ageClass => $yearBoundaries) {
|
||||
if (($yearBoundaries[0] <= $year) && ($year <= $yearBoundaries[1])) {
|
||||
return $ageClass;
|
||||
/** grouping users by given age class
|
||||
*
|
||||
* @param array $ageClassList as array string representation of age class => [lower year bound, upper year bound]
|
||||
* @param array $starterList list of starter (User)
|
||||
* @return array of string representation of age class => array of userId=>user in this class
|
||||
*/
|
||||
private static function ageClassGrouping(array $ageClassList, array $starterList)
|
||||
{
|
||||
$grouping = [];
|
||||
foreach ($ageClassList as $ageClass => $yearBoundaries) {
|
||||
$grouping[$ageClass] = [];
|
||||
}
|
||||
$grouping[null] = [];
|
||||
|
||||
foreach ($starterList as $starter) {
|
||||
$startersAgeClass = $starter->yearOfBirth() ? self::getAgeClassFromYear($starter->yearOfBirth(), $ageClassList) : null;
|
||||
$grouping[$startersAgeClass][$starter->getId()] = $starter;
|
||||
}
|
||||
return $grouping;
|
||||
}
|
||||
|
||||
private static function getAgeClassFromYear(int $year, array $ageClassList)
|
||||
{
|
||||
foreach ($ageClassList as $ageClass => $yearBoundaries) {
|
||||
if (($yearBoundaries[0] <= $year) && ($year <= $yearBoundaries[1])) {
|
||||
return $ageClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} // end class shiai
|
||||
|
||||
Reference in New Issue
Block a user