make add/remove starter buttons date sensitive

This commit is contained in:
marko
2023-01-29 19:55:33 +01:00
parent 4ff0659f90
commit ece0ef5025
9 changed files with 492 additions and 196 deletions

View File

@@ -1,9 +1,13 @@
<?php
require_once 'participoLib/participo.php';
require_once 'participoLib/shiai.php';
/** Framework for a event
*/
class Event
{
// members in the db
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)
@@ -19,22 +23,78 @@ class Event
* @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)
public function __construct($id, $date, $shiaiId, $deadline, $remarks)
{
//! @todo InputValidation
$this->id = (int) $id;
$this->id = filterId($id);
$this->date = DateTime::createFromFormat('Y-m-d', $date);
$this->shiaiId = (($shiaiId != null) ? ((int)$shiaiId) : (null));
$this->shiaiId = filterId($shiaiId);
$this->deadline = DateTime::createFromFormat('Y-m-d', $deadline);
$this->remarks = $remarks;
$this->shiai = $shiai;
}
// Getter
/** Getter for the id
*
* @return (int) Id of the event
*/
public function getId()
{
return $this->id;
}
/** Getter for the date
*
* @return DateTime date of the event
*/
public function getDate()
{
return $this->date;
}
/** Getter for the shiaiId
*
* @return int>0 id for the shiai in the db
*/
public function getShiaiId()
{
return $this->shiaiId;
}
/** Getter for the deadline
*
* @return DateTime deadline for the event
*/
public function getDeadLine()
{
return $this->deadline;
}
/** Getter for the shiai
*
* @return Shiai shiai for the event
*/
public function getShiai()
{
return $this->shiai;
}
public function loadShiai()
{
if ($this->shiaiId != null) {
$this->shiai = Shiai::loadFromDb($this->shiaiId);
}
return $this->shiai;
}
public static function loadFromDb(int $id)
{
$id = filterId($id);
$query = 'SELECT * FROM `cwsvjudo`.`wkParticipo_Events` WHERE `id` = :id;';
$params = [':id' => ['value' => $id, 'data_type' => PDO::PARAM_INT]];
$response = dbConnector::query($query, $params);
@@ -43,7 +103,7 @@ class Event
if (count($response) != 1) {
return null;
}
return Event::fromDbArray($response[0]);
return self::fromDbArray($response[0]);
}
/** Representation of an event as (materializeCss) card
@@ -52,10 +112,11 @@ class Event
*/
public function asHtmlCard()
{
$shiai = self::loadShiai();
return
'<div class="card blue-grey darken-1">' .
'<div class="card-content white-text">' .
'<span class="card-title">' . $this->shiai->getHtmlName() . '</span>' .
'<span class="card-title">' . $shiai->getHtmlName() . '</span>' .
'<dl>' .
'<dt>Datum</dt>' .
'<dd>' . $this->date->format('Y-m-d') . '</dd>' .
@@ -69,11 +130,12 @@ class Event
public function htmlTableRow()
{
$shiai = $this->loadShiai();
return
'<tr>' .
'<td>' . $this->date->format('Y-m-d') . '</td>' .
'<td><a href="/participo/events#' . $this->id . '" >' . $this->shiai->getHtmlName() . '</a></td>' .
'<td>' . $this->shiai->getAgeClasses() . '</td>' .
'<td><a href="/participo/events#' . $this->id . '" >' . $shiai->getHtmlName() . '</a></td>' .
'<td>' . $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>';
}
@@ -109,9 +171,12 @@ class Event
return '';
}
$starterList .= 'Bereits eingetragen: <div class="row">';
foreach ($listOfStarter as $s) {
$u = $s->getUser();
$starterList .= '<div class="col s12 m6">' . $u->getName() . ', ' . $u->getFirstname() . $this->getHtmlRemoveStarterForm($s->getEventId(), $s->getUserId()) . '</div>';
foreach ($listOfStarter as $start) {
$startingUser = $start->loadStarter();
$starterList .= '<div class="col s12 m6"><div class="row valign-wrapper">'
. '<div class="col s6">' . $startingUser->getName() . ', ' . $startingUser->getFirstname() . ':</div>'
. '<div class="col s6">' . $start->getHtmlFormRemove() . '</div>'
. '</div></div>';
}
$starterList .= '</div>';
return $starterList;
@@ -141,7 +206,7 @@ class Event
return $starter;
}
public static function fromArray($member)
public static function fromDbArray($member)
{
$shiai = json_decode($member['bemerkungen'], true);
@@ -151,7 +216,7 @@ class Event
$member['wkId'] ?? null,
$member['meldefrist'] ?? null,
$member['bemerkungen'] ?? null,
shiai::fromArray(($shiai != null) ? $shiai : $member)
shiai::fromDbArray(($shiai != null) ? $shiai : $member)
);
}
@@ -172,7 +237,13 @@ class Event
}
// @todo docu
public static function getHtmlRemoveStarterForm($eventId, $userId, $class = null)
public function getHtmlRemoveStarterForm($starterId)
{
$html = self::getHtmlRemoveStarterFromEventForm($this->id, $starterId);
}
// returns html code for a button to remove the user from an event
public static function getHtmlRemoveStarterFromEventForm($eventId, $userId, $class = null)
{
$form =
'<form ' . (isset($class) ? ('class="' . $class . '"') : '') . ' action="api.starter.remove.php" method="post">'