deactivate entry forms when deadline is over

This commit is contained in:
marko
2023-04-15 18:03:52 +02:00
parent bed173eac2
commit a610bed879
4 changed files with 79 additions and 14 deletions

View File

@@ -73,13 +73,15 @@ class Event
return $this->deadline; return $this->deadline;
} }
/** Getter for the shiai /** Getter for the linked Shiai
* *
* If the Shiai isn't loaded yet, it is loaded * - lazy loading: only load if not already loaded (overridable by the $forceLoading param)
* *
* @return Shiai shiai for the event * @param boolean $forceLoading if true, the loading is enforced even if there already is a shiai linked
*
* @return Shiai reference to the linked Shiai
*/ */
public function getShiai($forceLoading = false) public function shiai($forceLoading = false)
{ {
// We want to load if it isn't loaded yet or we want to enforce it. But in either case we need an id to load // We want to load if it isn't loaded yet or we want to enforce it. But in either case we need an id to load
if( (!isset($this->shiai) || $forceLoading) && isset($this->shiaiId) ){ if( (!isset($this->shiai) || $forceLoading) && isset($this->shiaiId) ){
@@ -109,7 +111,7 @@ class Event
*/ */
public function asHtmlCard() public function asHtmlCard()
{ {
$shiai = $this->getShiai(); $shiai = $this->shiai();
return return
'<div class="card blue-grey darken-1">' . '<div class="card blue-grey darken-1">' .
'<div class="card-content white-text">' . '<div class="card-content white-text">' .
@@ -128,7 +130,7 @@ class Event
public function htmlTableRow() public function htmlTableRow()
{ {
$shiai = $this->getShiai(); $shiai = $this->shiai();
return return
'<tr>' . '<tr>' .
'<td>' . $this->date->format('Y-m-d') . '</td>' . '<td>' . $this->date->format('Y-m-d') . '</td>' .
@@ -144,11 +146,24 @@ class Event
'<div id="event-modal-' . $this->id . '" class="modal black-text">' '<div id="event-modal-' . $this->id . '" class="modal black-text">'
. '<div class="modal-content">' . '<div class="modal-content">'
. $this->shiai->getHtml() . $this->shiai->getHtml()
. $this->getHtmlStarterStatistic()
. $this->getHtmlStarterList(); . $this->getHtmlStarterList();
$kids = participo::getKids(); $kids = participo::getKids();
$modal .= '<div class="row">'; $modal .= '<div class="row">';
foreach ($kids as $k) { $modal .= '<div>Deadline zum Eintragen: '.$this->deadline->format('Y-m-d').'</div>';
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl'=>'/participo/events#' . $this->id]);
$today = new DateTime();
if(
(isset($this->deadline) && ($today <= $this->deadline))
|| participo::isUserAdmin($userData['id'])
){
foreach ($kids as $k) {
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl'=>'/participo/events#' . $this->id]);
}
}
else{
$modal .= '<div>Es ist leider zu spät noch jemanden einzutragen!</div>';
} }
$modal .= '</div>'; $modal .= '</div>';
$modal .= $modal .=
@@ -204,6 +219,35 @@ class Event
return $starter; return $starter;
} }
/** get number of starters of a certain type for this event
*
* @param int $startingType it representation of the StartingType to count
* @return int count of starters
*/
public function getStarterCount(int $startingType)
{
$query = 'SELECT COUNT(`wkParticipo_Starter`.`id`) AS starterCount FROM `wkParticipo_Starter` '
. ' WHERE `wkParticipo_Starter`.`eventId` = :eventId AND `wkParticipo_Starter`.`type` = :typeId;';
$params = [
':eventId' => ['value' => $this->id, 'data_type' => PDO::PARAM_INT],
':typeId' => ['value' => $startingType, 'data_type' => PDO::PARAM_INT],
];
$response = dbConnector::query($query, $params);
return intval($response[0]['starterCount']);
}
public function getHtmlStarterStatistic(){
$retHtml = '<dl>';
foreach([StartingType::Fighter, StartingType::NoParticipation, StartingType::Audience] as $type){
$count = $this->getStarterCount($type);
if($count > 0){
$retHtml .= '<dt>'.StartingType::$AsString[$type].'</dt><dd>'.$count.'</dd>';
}
}
$retHtml .= '</dl>';
return $retHtml;
}
public static function fromDbArray($member) public static function fromDbArray($member)
{ {
$shiai = json_decode($member['bemerkungen'], true); $shiai = json_decode($member['bemerkungen'], true);
@@ -236,11 +280,19 @@ class Event
public function getHtmlAddStarterForm($user, $options = []) public function getHtmlAddStarterForm($user, $options = [])
{ {
$defaults = [
'formClass' =>'card col s12 m6 l3',
'inputClass' =>'input-field',
'buttonClass'=>'btn'
];
$options = array_merge($defaults, $options);
$returnToUrl = $options['returnToUrl'] ?? urlencode(getCurPagesUrl()); $returnToUrl = $options['returnToUrl'] ?? urlencode(getCurPagesUrl());
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null; $key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
$form = $form =
'<form class="card col s12 m6" action="api.starter.add.php" method="post">' '<form class="'.$options['formClass'].'" action="api.starter.add.php" method="post">'
. '<input type="hidden" name="eventId" id="eventId" value="' . $this->id . '">' . '<input type="hidden" name="eventId" id="eventId" value="' . $this->id . '">'
. '<input type="hidden" name="userId" id="userId" value="' . $user->getId() . '">' . '<input type="hidden" name="userId" id="userId" value="' . $user->getId() . '">'
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . $returnToUrl . '" >' . '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . $returnToUrl . '" >'
@@ -252,7 +304,7 @@ class Event
. '</select>' . '</select>'
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>' . '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
. '</div>' . '</div>'
. '<button class="btn" type="submit" name="submit">einschreiben</button>' . '<input class="'.$options['buttonClass'].'" type="submit" name="submit" value="eintragen">'
. '</form>'; . '</form>';
return $form; return $form;

View File

@@ -564,3 +564,17 @@ function filterId($id)
{ {
return filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); return filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
} }
/** filter a variable as count
*
* - count means a non negative integer
* - helper function to stay DRY
*
* @param mixed $variable
* @param integer $min
* @return integer the input variable as integer >= 0
*/
function filterCount($variable, int $min = 0){
return filter_var($variable, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
}

View File

@@ -8,7 +8,7 @@ class Shiai
private $id = null; //< unique id private $id = null; //< unique id
private $date = null; //< date of the shiai private $date = null; //< date of the shiai
private $name = null; //< name of the shiai as string private $name = null; //< name of the shiai as string
private $ageclasses = null; //< age classes as space separated Uxy in a string private $ageclasses = null; //< age classes as space separated 'Uxy' in a string
private $place = null; //< place of the shiai as string private $place = null; //< place of the shiai as string
private $announcementUrl = null; //< url to the announcement private $announcementUrl = null; //< url to the announcement
private $routeUrl = null; //< url to a routing planner private $routeUrl = null; //< url to a routing planner
@@ -88,8 +88,7 @@ class Shiai
); );
} }
/** /** shiai event as html code for displaying
* shiai event as html code for displaying
* *
* @return html formatted string * @return html formatted string
*/ */

View File

@@ -405,7 +405,7 @@ class Starter
// get html code of a list of starts // get html code of a list of starts
private static function getHtmlTable($starts) private static function getHtmlTable($starts)
{ {
$html = '<table>' $html = '<table class="responsive-table">'
. '<thead><tr><th>Datum</th><th>Veranstaltung</th><th>Starter</th><th></th><th></th></tr></thead>' . '<thead><tr><th>Datum</th><th>Veranstaltung</th><th>Starter</th><th></th><th></th></tr></thead>'
. '<tbody>'; . '<tbody>';
foreach ($starts as $start) { foreach ($starts as $start) {