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;
}
/** 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
if( (!isset($this->shiai) || $forceLoading) && isset($this->shiaiId) ){
@@ -109,7 +111,7 @@ class Event
*/
public function asHtmlCard()
{
$shiai = $this->getShiai();
$shiai = $this->shiai();
return
'<div class="card blue-grey darken-1">' .
'<div class="card-content white-text">' .
@@ -128,7 +130,7 @@ class Event
public function htmlTableRow()
{
$shiai = $this->getShiai();
$shiai = $this->shiai();
return
'<tr>' .
'<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 class="modal-content">'
. $this->shiai->getHtml()
. $this->getHtmlStarterStatistic()
. $this->getHtmlStarterList();
$kids = participo::getKids();
$modal .= '<div class="row">';
foreach ($kids as $k) {
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl'=>'/participo/events#' . $this->id]);
$modal .= '<div>Deadline zum Eintragen: '.$this->deadline->format('Y-m-d').'</div>';
$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 .=
@@ -204,6 +219,35 @@ class Event
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)
{
$shiai = json_decode($member['bemerkungen'], true);
@@ -236,11 +280,19 @@ class Event
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());
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
$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="userId" id="userId" value="' . $user->getId() . '">'
. '<input type="hidden" name="returnToUrl" id="returnToUrl" value="' . $returnToUrl . '" >'
@@ -252,7 +304,7 @@ class Event
. '</select>'
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
. '</div>'
. '<button class="btn" type="submit" name="submit">einschreiben</button>'
. '<input class="'.$options['buttonClass'].'" type="submit" name="submit" value="eintragen">'
. '</form>';
return $form;