110 lines
3.0 KiB
PHP
110 lines
3.0 KiB
PHP
<?php
|
|
require_once 'participoLib/participo.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 getHtmlName()
|
|
{
|
|
$name = ($this->name != null ? $this->name : 'Wettkampf ohne Namen');
|
|
foreach (['meisterschaft', 'turnier', 'randori'] as $fragment) {
|
|
$name = str_replace($fragment, '­' . $fragment, $name);
|
|
}
|
|
return $name;
|
|
}
|
|
|
|
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 loadFromDb(int $id)
|
|
{
|
|
$id = filterId($id);
|
|
|
|
$query = 'SELECT * FROM `cwsvjudo`.`wettkampfkalender` WHERE `lfdeNr` = :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 self::fromDbArray($response[0]);
|
|
}
|
|
|
|
public static function fromDbArray($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 formatted string
|
|
*/
|
|
public function getHtml()
|
|
{
|
|
$retHtml = '';
|
|
$retHtml =
|
|
'<div>' .
|
|
'<h3>' . $this->getHtmlName() . '</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
|