add offered rided count to event overview

This commit is contained in:
marko
2023-04-18 20:05:30 +02:00
parent 730f456140
commit 612333f061
3 changed files with 186 additions and 147 deletions

View File

@@ -74,17 +74,17 @@ class Event
}
/** Getter for the linked Shiai
*
*
* - lazy loading: only load if not already loaded (overridable by the $forceLoading param)
*
* @param boolean $forceLoading if true, the loading is enforced even if there already is a shiai linked
*
* @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 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) ){
if ((!isset($this->shiai) || $forceLoading) && isset($this->shiaiId)) {
$this->shiai = Shiai::loadFromDb($this->shiaiId);
}
return $this->shiai;
@@ -123,7 +123,7 @@ class Event
'<dd>' . $this->deadline->format('Y-m-d') . '</dd>' .
'<dt>Altersklassen</dt>' .
'<dd>' . $this->shiai->getAgeClasses() . '</dd>' .
'</dl>'.
'</dl>' .
'</div>' .
'</div>';
}
@@ -150,19 +150,17 @@ class Event
. $this->getHtmlStarterList();
$kids = participo::getKids();
$modal .= '<div class="row">';
$modal .= '<div>Deadline zum Eintragen: '.$this->deadline->format('Y-m-d').'</div>';
$modal .= '<div>Deadline zum Eintragen: ' . $this->deadline->format('Y-m-d') . '</div>';
$today = new DateTime();
if(
if (
(isset($this->deadline) && ($today <= $this->deadline))
|| participo::isUserAdmin($userData['id'])
){
) {
foreach ($kids as $k) {
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl'=>'/participo/events#' . $this->id]);
$modal .= $this->getHtmlAddStarterForm($k, ['returnToUrl' => '/participo/events#' . $this->id]);
}
}
else{
} else {
$modal .= '<div>Es ist leider zu spät noch jemanden einzutragen!</div>';
}
$modal .= '</div>';
@@ -187,7 +185,7 @@ class Event
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() . ' ('.StartingType::$AsString[$start->getTypeId()].'):</div>'
. '<div class="col s6">' . $startingUser->getName() . ', ' . $startingUser->getFirstname() . ' (' . StartingType::$AsString[$start->getTypeId()] . '):</div>'
. '<div class="col s6">' . $start->getHtmlFormRemove() . '</div>'
. '</div></div>';
}
@@ -236,14 +234,21 @@ class Event
return intval($response[0]['starterCount']);
}
public function getHtmlStarterStatistic(){
public function getSeatCount()
{
return self::getSeatCountOf($this->id);
}
public function getHtmlStarterStatistic()
{
$retHtml = '<dl>';
foreach([StartingType::Fighter, StartingType::NoParticipation, StartingType::Audience] as $type){
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>';
if ($count > 0) {
$retHtml .= '<dt>' . StartingType::$AsString[$type] . '</dt><dd>' . $count . '</dd>';
}
}
$retHtml .= '<dt>Mitfahrgelegenheiten</dt><dd>' . $this->getSeatCount() . '</dd>';
$retHtml .= '</dl>';
return $retHtml;
}
@@ -266,8 +271,6 @@ class Event
/// Es erfolgt keine Überprüfung der Meldeberechtigung!
public static function addStarter($dbConnection, $starter)
{
$retMessage = [];
$query = 'INSERT INTO `wkParticipo_Starter` (eventId, userId, type) values (:eventId, :userId, :typeId);';
$params = [
':eventId' => ['value' => $starter->getEventId(), 'data_type' => PDO::PARAM_INT],
@@ -278,12 +281,23 @@ class Event
return dbConnector::query($query, $params);
}
public static function getSeatCountOf(int $id)
{
$query = 'SELECT SUM(plaetze) AS sumSeats FROM `cwsvjudo`.`wkParticipo_Fahrten` WHERE eventId = :eventId;';
$params = [
'eventId' => ['value' => $id, 'data_type' => PDO::PARAM_INT]
];
$response = dbConnector::query($query, $params);
$sumSeats = filterCount($response[0]['sumSeats']);
return $sumSeats;
}
public function getHtmlAddStarterForm($user, $options = [])
{
$defaults = [
'formClass' =>'card col s12 m6 l3',
'inputClass' =>'input-field',
'buttonClass'=>'btn'
'formClass' => 'card col s12 m6 l3',
'inputClass' => 'input-field',
'buttonClass' => 'btn'
];
$options = array_merge($defaults, $options);
@@ -292,7 +306,7 @@ class Event
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
$form =
'<form class="'.$options['formClass'].'" 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 . '" >'
@@ -304,7 +318,7 @@ class Event
. '</select>'
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
. '</div>'
. '<input class="'.$options['buttonClass'].'" type="submit" name="submit" value="eintragen">'
. '<input class="' . $options['buttonClass'] . '" type="submit" name="submit" value="eintragen">'
. '</form>';
return $form;