Merge branch 'homepage' of http://gitea.cwsvjudo.dedyn.io/marko/cwsvJudo into homepage

This commit is contained in:
marko
2024-04-07 09:05:55 +02:00
5 changed files with 594 additions and 343 deletions

View File

@@ -0,0 +1,145 @@
<?php
class Interval
{
function __construct(
$lowerBound,
$upperBound,
bool $lowerClosed = true,
bool $upperClosed = false
) {
$this->lowerBound = $lowerBound;
$this->upperBound = $upperBound;
$this->lowerClosed = $lowerClosed;
$this->upperClosed = $upperClosed;
}
function __toString(): string
{
return ($this->lowerClosed ? "[" : "(") .
$this->lowerBound .
", " .
$this->upperBound .
($this->upperClosed ? "]" : ")");
}
function contains($value)
{
return ($this->lowerClosed
? $this->lowerBound <= $value
: $this->lowerBound < $value) &&
($this->upperClosed
? $value <= $this->upperBound
: $value < $this->upperBound);
}
// private member
//- variables
// upper/lower bounds for the interval
private $lowerBound;
private $upperBound;
// on true the bound is in the interval, otherwise not
private $lowerClosed;
private $upperClosed;
}
// data type for an age class
class AgeGroup
{
// public member
// - functions
function __construct(string $label, Interval $years)
{
$this->label = $label;
$this->years = $years;
}
function __toString(): string
{
return $this->label . " " . $this->years;
}
function years()
{
return $this->years;
}
/** factory method for AgeGroup-s
*
* @param [string] $label string denoting the AgeGroup
* @param [type] $year the year to reference the AgeGroup to
* @return AgeGroup interval of years of the age group
*/
public static function create(string $label, ?int $year = null)
{
// input sanitation
$year =
filterPosInt($year) ?? filterPosInt((new DateTime())->format("Y"));
$lowerYear = null;
$upperYear = null;
// Matching against the different age class formats
// - ..Ux
// - Jg.x-y
// Case Ux
$akUmatchString = "/(.*)U([0-9]+)(.*)/";
$matches = [];
preg_match($akUmatchString, $label, $matches);
// The found match should cover the whole string. Otherwise it isn't applicable.
if ($matches[0] == $label) {
// The x in Ux should be a positive integer.
$ageLimit = filterPosInt($matches[2]);
if ($ageLimit) {
$lowerYear = $year - $ageLimit + 1;
// lowering the lower bound according to the modifiers
if ($matches[3] == "") {
$upperYear = $year - $ageLimit + 2;
} elseif ($matches[3] == "-") {
$upperYear = $year - $ageLimit + 3;
} elseif ($matches[3] == "--") {
$upperYear = $year - $ageLimit + 4;
} elseif (
in_array($matches[1], [
"<=",
"&le;",
"&#x2264;",
"&#8804;",
"",
])
) {
$upperYear = $year;
}
return new AgeGroup(
$label,
new Interval($lowerYear, $upperYear, true, true)
);
}
}
// Case Jg.x-y
$akUmatchString = "/Jg\.(.*)\-{1,2}(.*)/";
$matches = [];
preg_match($akUmatchString, $label, $matches);
// The found match should cover the whole string. Otherwise it isn't applicable.
if ($matches[0] == $label) {
$lowerYear = filterPosInt($matches[1]);
$upperYear = filterPosInt($matches[2]);
return new AgeGroup(
$label,
new Interval($lowerYear, $upperYear, true, true)
);
}
return new AgeGroup(
$label,
new Interval($lowerYear, $upperYear, true, true)
);
}
// private member
// - functions
// - variables
private $label;
private $years;
}

View File

@@ -1,5 +1,7 @@
<?php <?php
require_once "participoLib/shiai.php";
class EventPage class EventPage
{ {
public function __construct($eventId = null) public function __construct($eventId = null)
@@ -9,21 +11,23 @@ class EventPage
public function init() public function init()
{ {
$params = participo::parseParams( $params = participo::parseParams([
['eventId' => function ($param) {return filterId($param); }] "eventId" => function ($param) {
); return filterId($param);
$this->eventId = $params['eventId']; },
]);
$this->eventId = $params["eventId"];
return; return;
} }
public function getHtmlNotFound() public function getHtmlNotFound()
{ {
return '<div>Der Event "' . $this->id . '" existiert leider nicht!</div>' return '<div>Der Event "' .
. '<h2>Anstehende Termine</h2>' $this->id .
. eventPlaner::getHtmlEventTable( '" existiert leider nicht!</div>' .
eventPlaner::getComingWkEvents() "<h2>Anstehende Termine</h2>" .
); eventPlaner::getHtmlEventTable(eventPlaner::getComingWkEvents());
} }
public function getHtml() public function getHtml()
@@ -32,40 +36,72 @@ class EventPage
return $this->getHtmlNotFound(); return $this->getHtmlNotFound();
} }
$html = ''; $html = "";
$html .= $html .=
'<div>' "<div>" .
. '<dl>' "<dl>" .
. '<dt>Termine</dt>' "<dt>Termine</dt>" .
. '<dd> '<dd>
<dl>' <dl>' .
. '<dt>Datum</dt><dd>' . $this->event()->htmlDate() . '</dd>' "<dt>Datum</dt><dd>" .
. '<dt>Deadline zum Einschreiben:</dt><dd>' . $this->event()->htmlDeadline() . '</dd>' $this->event()->htmlDate() .
. '</dl>'; "</dd>" .
"<dt>Deadline zum Einschreiben:</dt><dd>" .
$this->event()->htmlDeadline() .
"</dd>" .
"</dl>";
// Not all Events have a shiai linked to them // Not all Events have a shiai linked to them
if ($this->event()->shiai()) { if ($this->event()->shiai()) {
$html .= $html .=
'<dt>Wettkampfdetails</dt><dd>' . $this->event()->shiai()->getHtmlDetails() . '</dd>'; "<dt>Wettkampfdetails</dt><dd>" .
$this->event()
->shiai()
->getHtmlDetails() .
"</dd>";
} }
$html .= $html .=
'<dt>Einschreibungen</dt><dd>' . $this->event()->getHtmlStarterStatistic() . '</dd>' "<dt>Einschreibungen</dt><dd>" .
. '<dt>Eigene, gemeldete Starter</dt><dd>' . $this->event()->getHtmlStarterList() . '</dd>' $this->event()->getHtmlStarterStatistic() .
. '</dl>' "</dd>" .
. '</div>'; "<dt>Eigene, gemeldete Starter</dt><dd>" .
$this->event()->getHtmlStarterList() .
"</dd>" .
"</dl>" .
"</div>";
$html .= "<div>";
foreach (
$this->event()
->shiai()
->ageGroups()
as $ageClass => $starterList
) {
$html .= $html .=
'<div>'; "<dl>" .
foreach ($this->event()->shiai()->ageGroups() as $ageClass => $starterList) { "<dt>" .
$html .= (!empty($ageClass)
'<dl>' . ? AgeGroup::create($ageClass)
'<dt>' . (!empty($ageClass) ? $ageClass : 'keiner Altersklasse zugeordnet') . '</dt>' : "keiner Altersklasse zugeordnet") .
. '<dd> "</dt>" .
'<dd>
<ul>'; <ul>';
foreach ($starterList as $starter) { foreach ($starterList as $starter) {
if (!array_key_exists($starter->getId(), $this->event()->getStarter())) { if (
!array_key_exists(
$starter->getId(),
$this->event()->getStarter()
)
) {
$html .= $html .=
'<li>' . $starter->getName() . ', ' . $starter->getFirstname() . ' - ' . $starter->yearOfBirth() . ' "<li>" .
$starter->getName() .
", " .
$starter->getFirstname() .
" - " .
$starter->yearOfBirth() .
'
</li>'; </li>';
} }
} }
@@ -73,14 +109,14 @@ class EventPage
</dd> </dd>
</ul>'; </ul>';
} }
$html .= '</div>'; $html .= "</div>";
return $html; return $html;
} }
public function html() public function html()
{ {
echo($this->getHtml()); echo $this->getHtml();
} }
private function event(bool $forceLoading = false) private function event(bool $forceLoading = false)

View File

@@ -1,5 +1,6 @@
<?php <?php
require_once 'participoLib/participo.php'; require_once "participoLib/participo.php";
require_once "participoLib/ageGroup.php";
/** frame for a shiai /** frame for a shiai
*/ */
@@ -21,13 +22,24 @@ class Shiai
*/ */
private static $tableName = "wettkampfkalender"; private static $tableName = "wettkampfkalender";
public function __construct($id, $date, $name, $ageclasses, $place, $announcementUrl, $routeUrl, $galleryUrl=null, $promoImgUrl=null) public function __construct(
{ $id,
$date,
$name,
$ageclasses,
$place,
$announcementUrl,
$routeUrl,
$galleryUrl = null,
$promoImgUrl = null
) {
//! @todo input validation and sanitation //! @todo input validation and sanitation
$this->id = filterId($id); $this->id = filterId($id);
$this->date = DateTime::createFromFormat('Y-m-d', $date); $this->date = DateTime::createFromFormat("Y-m-d", $date);
$this->name = $name; $this->name = $name;
$this->ageclasses = $ageclasses ? self::akListString2jgArray($ageclasses) : null; $this->ageclasses = $ageclasses
? self::akListString2jgArray($ageclasses)
: null;
$this->place = $place; $this->place = $place;
$this->announcementUrl = $announcementUrl; $this->announcementUrl = $announcementUrl;
$this->routeUrl = $routeUrl; $this->routeUrl = $routeUrl;
@@ -35,29 +47,39 @@ class Shiai
$this->promoImgUrl = $promoImgUrl; $this->promoImgUrl = $promoImgUrl;
} }
public static function fromArray(array $shiai){ public static function fromArray(array $shiai)
$id = $shiai['id'] ?? null; {
$date = $shiai['date'] ?? null; $id = $shiai["id"] ?? null;
$name = $shiai['name'] ?? null; $date = $shiai["date"] ?? null;
$ageclasses = $shiai['ageclasses'] ?? null; $name = $shiai["name"] ?? null;
$place = $shiai['place'] ?? null; $ageclasses = $shiai["ageclasses"] ?? null;
$announcementUrl = $shiai['announcementUrl'] ?? null; $place = $shiai["place"] ?? null;
$routeUrl = $shiai['routeUrl'] ?? null; $announcementUrl = $shiai["announcementUrl"] ?? null;
$routeUrl = $shiai["routeUrl"] ?? null;
// gallery stuff removed for now // gallery stuff removed for now
return new Shiai($id, $date, $name, $ageclasses, $place, $announcementUrl, $routeUrl); return new Shiai(
$id,
$date,
$name,
$ageclasses,
$place,
$announcementUrl,
$routeUrl
);
} }
public function asArray(){ public function asArray()
{
return [ return [
'id'=>$this->id, "id" => $this->id,
'date'=>$this->date->format('Y-m-d'), "date" => $this->date->format("Y-m-d"),
'name'=>$this->name, "name" => $this->name,
// @todo at least in theory this should again hold age categories // @todo at least in theory this should again hold age categories
'ageclasses'=>implode(" ", $this->ageclasses), "ageclasses" => implode(" ", $this->ageclasses),
'place'=>$this->place, "place" => $this->place,
'announcementUrl'=>$this->announcementUrl, "announcementUrl" => $this->announcementUrl,
'routeUrl'=>$this->announcementUrl "routeUrl" => $this->announcementUrl,
]; ];
} }
@@ -68,26 +90,28 @@ class Shiai
public function getHtmlName() public function getHtmlName()
{ {
$name = ($this->name != null ? $this->name : 'Wettkampf ohne Namen'); $name = $this->name != null ? $this->name : "Wettkampf ohne Namen";
foreach (['meisterschaft', 'turnier', 'randori'] as $fragment) { foreach (["meisterschaft", "turnier", "randori"] as $fragment) {
$name = str_replace($fragment, '&shy;' . $fragment, $name); $name = str_replace($fragment, "&shy;" . $fragment, $name);
} }
return $name; return $name;
} }
public function getHtmlDate() public function getHtmlDate()
{ {
return ($this->date != null ? $this->date->format('Y-m-d') : 'fehlendes Datum'); return $this->date != null
? $this->date->format("Y-m-d")
: "fehlendes Datum";
} }
public function getAgeClasses() public function getAgeClasses()
{ {
return ($this->ageclasses != null ? $this->ageclasses : '-'); return $this->ageclasses != null ? $this->ageclasses : "-";
} }
public function getPlace() public function getPlace()
{ {
return ($this->place != null ? $this->place : '-'); return $this->place != null ? $this->place : "-";
} }
public function getAnnouncementUrl() public function getAnnouncementUrl()
@@ -104,8 +128,9 @@ class Shiai
{ {
$id = filterId($id); $id = filterId($id);
$query = 'SELECT * FROM `cwsvjudo`.`wettkampfkalender` WHERE `lfdeNr` = :id;'; $query =
$params = [':id' => ['value' => $id, 'data_type' => PDO::PARAM_INT]]; "SELECT * FROM `cwsvjudo`.`wettkampfkalender` WHERE `lfdeNr` = :id;";
$params = [":id" => ["value" => $id, "data_type" => PDO::PARAM_INT]];
$response = dbConnector::query($query, $params); $response = dbConnector::query($query, $params);
// ids are considered unique. so every other count then 1 is treated as error to prevent unprivileged access // ids are considered unique. so every other count then 1 is treated as error to prevent unprivileged access
@@ -119,8 +144,14 @@ class Shiai
* *
* - by default, only coming events will be returned * - by default, only coming events will be returned
*/ */
public static function dbSelect(){ public static function dbSelect()
$query = "SELECT `".self::$tableName."`.* FROM `".self::$tableName."` WHERE `Datum` >= CURDATE();"; {
$query =
"SELECT `" .
self::$tableName .
"`.* FROM `" .
self::$tableName .
"` WHERE `Datum` >= CURDATE();";
$response = dbConnector::query($query); $response = dbConnector::query($query);
return $response; return $response;
@@ -129,15 +160,15 @@ class Shiai
public static function fromDbArray($member) public static function fromDbArray($member)
{ {
return new shiai( return new shiai(
$member['lfdeNr'] ?? null, $member["lfdeNr"] ?? null,
$member['Datum'] ?? null, $member["Datum"] ?? null,
$member['Veranstaltung'] ?? '<fehlender Name>', $member["Veranstaltung"] ?? "<fehlender Name>",
$member['Altersklassen'] ?? null, $member["Altersklassen"] ?? null,
$member['Ort'] ?? '<fehlender Ort>', $member["Ort"] ?? "<fehlender Ort>",
$member['Ausschreibung'] ?? null, $member["Ausschreibung"] ?? null,
$member['Routenplaner'] ?? null, $member["Routenplaner"] ?? null,
$member['galleryLink'] ?? null, $member["galleryLink"] ?? null,
$member['promoPic'] ?? null $member["promoPic"] ?? null
); );
} }
@@ -147,50 +178,56 @@ class Shiai
*/ */
public function getHtml() public function getHtml()
{ {
$retHtml = ''; $retHtml = "";
$retHtml = $retHtml =
'<div>' . "<div>" .
'<h3><a href="' . $this->announcementUrl . '">' . $this->getHtmlName() . '</a></h3>' . '<h3><a href="' .
'<dl>' . $this->announcementUrl .
'<dt>Datum</dt><dd>' . $this->getHtmlDate() . '</dd>' . '">' .
'<dt>Altersklassen</dt><dd>' . $this->getHtmlDescriptiveAgeClasses() . '</dd>' . $this->getHtmlName() .
'<dt>Ort</dt><dd><a href="' . $this->routeUrl . '">' . $this->getPlace() . '</a></dd>' . "</a></h3>" .
'</dl>' . "<dl>" .
'</div>'; "<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>" .
"</div>";
return $retHtml; return $retHtml;
} }
public function getHtmlDetails() public function getHtmlDetails()
{ {
return return "<dl>" .
'<dl>' '<dt>Name</dt><dd><a href="' .
. '<dt>Name</dt><dd><a href="' . $this->announcementUrl . '">' . $this->getHtmlName() . '</a></dd>' $this->announcementUrl .
. '<dt>Datum</dt><dd>' . $this->getHtmlDate() . '</dd>' '">' .
. '<dt>Altersklassen</dt><dd>' . $this->getHtmlDescriptiveAgeClasses() . '</dd>' $this->getHtmlName() .
. '<dt>Ort</dt><dd><a href="' . $this->routeUrl . '">' . $this->getPlace() . '</a></dd>' . "</a></dd>" .
'</dl>' "<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() public function getHtmlDescriptiveAgeClasses()
{ {
$retList = []; return join(", ", $this->ageclasses);
foreach ($this->ageclasses as $ageclass => $years) {
$htmlFragment = $ageclass;
$years = $years[0];
if ($years[0] || $years[1]) {
$htmlFragment .= '(';
if ($years[1]) {
$htmlFragment .= strval($years[0]) . '-' . strval($years[1]);
} else {
$htmlFragment .= '<=' . strval($years[0]);
}
$htmlFragment .= ')';
}
$retList[] = $htmlFragment;
}
return implode(', ', $retList);
} }
/** convert a list of age class formatted strings into a list of intervals of years /** convert a list of age class formatted strings into a list of intervals of years
@@ -199,14 +236,19 @@ class Shiai
* @param int $year * @param int $year
* @return list[array(int,int)] list of tupels with lower/upper bound in date year of the age classes * @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) private static function akListString2jgArray(
{ string $akListString,
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y')); ?int $year = null
$ret = []; ) {
foreach (explode(' ', $akListString) as $ak) { $year =
$ret[$ak] = self::akString2jgIntervall($ak, $year); filterPosInt($year) ?? filterPosInt((new DateTime())->format("Y"));
$ageGroups = [];
foreach (explode(" ", $akListString) as $label) {
$ageGroups[$label] = AgeGroup::create($label, $year);
} }
return $ret;
return $ageGroups;
} }
/** convert age class from formatted string to interval of years /** convert age class from formatted string to interval of years
@@ -215,10 +257,11 @@ class Shiai
* @param [type] $year * @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. * @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*/) private static function akString2jgIntervall(string $akString, int $year)
{ {
// input sanitation /*= null*/ // input sanitation
$year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y')); $year =
filterPosInt($year) ?? filterPosInt((new DateTime())->format("Y"));
$ret = [null, null]; $ret = [null, null];
@@ -227,7 +270,7 @@ class Shiai
// - Jg.x-y // - Jg.x-y
// Case Ux // Case Ux
$akUmatchString = '/(.*)U(.*)/'; $akUmatchString = "/(.*)U(.*)/";
$matches = []; $matches = [];
@@ -239,13 +282,21 @@ class Shiai
if ($ageLimit) { if ($ageLimit) {
$ret[0] = $year - $ageLimit + 1; $ret[0] = $year - $ageLimit + 1;
// lowering the lower bound according to the modifiers // lowering the lower bound according to the modifiers
if ($matches[1] == '') { if ($matches[1] == "") {
$ret[1] = $year - $ageLimit + 2; $ret[1] = $year - $ageLimit + 2;
} elseif ($matches[1] == '-') { } elseif ($matches[1] == "-") {
$ret[1] = $year - $ageLimit + 3; $ret[1] = $year - $ageLimit + 3;
} elseif ($matches[1] == '--') { } elseif ($matches[1] == "--") {
$ret[1] = $year - $ageLimit + 4; $ret[1] = $year - $ageLimit + 4;
} elseif (in_array($matches[1], ['<=', '&le;', '&#x2264;', '&#8804;', '≤'])) { } elseif (
in_array($matches[1], [
"<=",
"&le;",
"&#x2264;",
"&#8804;",
"",
])
) {
$ret[1] = $year; $ret[1] = $year;
} }
return $ret; return $ret;
@@ -286,26 +337,35 @@ class Shiai
* @param array $starterList list of starter (User) * @param array $starterList list of starter (User)
* @return array of string representation of age class => array of userId=>user in this class * @return array of string representation of age class => array of userId=>user in this class
*/ */
private static function ageClassGrouping(array $ageClassList, array $starterList) private static function ageClassGrouping(
{ array $ageClassList,
array $starterList
) {
$grouping = []; $grouping = [];
foreach ($ageClassList as $ageClass => $yearBoundaries) { foreach ($ageClassList as $ageClass => $yearBoundaries) {
$grouping[$ageClass] = []; $grouping[$ageClass] = [];
} }
$grouping[null] = []; $grouping[null] = [];
foreach ($starterList as $starter) { foreach ($starterList as $starter) {
$startersAgeClass = $starter->yearOfBirth() ? self::getAgeClassFromYear($starter->yearOfBirth(), $ageClassList) : null; $startersAgeClass = $starter->yearOfBirth()
? self::getAgeClassFromYear(
$starter->yearOfBirth(),
$ageClassList
)
: null;
$grouping[$startersAgeClass][$starter->getId()] = $starter; $grouping[$startersAgeClass][$starter->getId()] = $starter;
} }
return $grouping; return $grouping;
} }
private static function getAgeClassFromYear(int $year, array $ageClassList) private static function getAgeClassFromYear(int $year, array $ageClassList)
{ {
foreach ($ageClassList as $ageClass => $yearBoundaries) { foreach ($ageClassList as $label => $ageGroup) {
if (($yearBoundaries[0] <= $year) && ($year <= $yearBoundaries[1])) { if ($ageGroup->years()->contains($year)) {
return $ageClass; return $label;
} }
} }
return null; return null;

View File

@@ -0,0 +1,5 @@
.PHONY: build
build:
npm install
npm run release

5
submodules/buildVideoJs.sh Executable file
View File

@@ -0,0 +1,5 @@
#! /usr/bin/env bash
cd video.js
npm install
npm run release