add offered rided count to event overview
This commit is contained in:
@@ -74,17 +74,17 @@ class Event
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Getter for the linked Shiai
|
/** Getter for the linked Shiai
|
||||||
*
|
*
|
||||||
* - lazy loading: only load if not already loaded (overridable by the $forceLoading param)
|
* - 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
|
* @return Shiai reference to the linked Shiai
|
||||||
*/
|
*/
|
||||||
public function shiai($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)) {
|
||||||
$this->shiai = Shiai::loadFromDb($this->shiaiId);
|
$this->shiai = Shiai::loadFromDb($this->shiaiId);
|
||||||
}
|
}
|
||||||
return $this->shiai;
|
return $this->shiai;
|
||||||
@@ -123,7 +123,7 @@ class Event
|
|||||||
'<dd>' . $this->deadline->format('Y-m-d') . '</dd>' .
|
'<dd>' . $this->deadline->format('Y-m-d') . '</dd>' .
|
||||||
'<dt>Altersklassen</dt>' .
|
'<dt>Altersklassen</dt>' .
|
||||||
'<dd>' . $this->shiai->getAgeClasses() . '</dd>' .
|
'<dd>' . $this->shiai->getAgeClasses() . '</dd>' .
|
||||||
'</dl>'.
|
'</dl>' .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
@@ -150,19 +150,17 @@ class Event
|
|||||||
. $this->getHtmlStarterList();
|
. $this->getHtmlStarterList();
|
||||||
$kids = participo::getKids();
|
$kids = participo::getKids();
|
||||||
$modal .= '<div class="row">';
|
$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();
|
$today = new DateTime();
|
||||||
if(
|
if (
|
||||||
(isset($this->deadline) && ($today <= $this->deadline))
|
(isset($this->deadline) && ($today <= $this->deadline))
|
||||||
|| participo::isUserAdmin($userData['id'])
|
|| participo::isUserAdmin($userData['id'])
|
||||||
){
|
) {
|
||||||
foreach ($kids as $k) {
|
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>Es ist leider zu spät noch jemanden einzutragen!</div>';
|
||||||
}
|
}
|
||||||
$modal .= '</div>';
|
$modal .= '</div>';
|
||||||
@@ -187,7 +185,7 @@ class Event
|
|||||||
foreach ($listOfStarter as $start) {
|
foreach ($listOfStarter as $start) {
|
||||||
$startingUser = $start->loadStarter();
|
$startingUser = $start->loadStarter();
|
||||||
$starterList .= '<div class="col s12 m6"><div class="row valign-wrapper">'
|
$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 class="col s6">' . $start->getHtmlFormRemove() . '</div>'
|
||||||
. '</div></div>';
|
. '</div></div>';
|
||||||
}
|
}
|
||||||
@@ -236,14 +234,21 @@ class Event
|
|||||||
return intval($response[0]['starterCount']);
|
return intval($response[0]['starterCount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHtmlStarterStatistic(){
|
public function getSeatCount()
|
||||||
|
{
|
||||||
|
return self::getSeatCountOf($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHtmlStarterStatistic()
|
||||||
|
{
|
||||||
$retHtml = '<dl>';
|
$retHtml = '<dl>';
|
||||||
foreach([StartingType::Fighter, StartingType::NoParticipation, StartingType::Audience] as $type){
|
foreach ([StartingType::Fighter, StartingType::NoParticipation, StartingType::Audience] as $type) {
|
||||||
$count = $this->getStarterCount($type);
|
$count = $this->getStarterCount($type);
|
||||||
if($count > 0){
|
if ($count > 0) {
|
||||||
$retHtml .= '<dt>'.StartingType::$AsString[$type].'</dt><dd>'.$count.'</dd>';
|
$retHtml .= '<dt>' . StartingType::$AsString[$type] . '</dt><dd>' . $count . '</dd>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$retHtml .= '<dt>Mitfahrgelegenheiten</dt><dd>' . $this->getSeatCount() . '</dd>';
|
||||||
$retHtml .= '</dl>';
|
$retHtml .= '</dl>';
|
||||||
return $retHtml;
|
return $retHtml;
|
||||||
}
|
}
|
||||||
@@ -266,8 +271,6 @@ class Event
|
|||||||
/// Es erfolgt keine Überprüfung der Meldeberechtigung!
|
/// Es erfolgt keine Überprüfung der Meldeberechtigung!
|
||||||
public static function addStarter($dbConnection, $starter)
|
public static function addStarter($dbConnection, $starter)
|
||||||
{
|
{
|
||||||
$retMessage = [];
|
|
||||||
|
|
||||||
$query = 'INSERT INTO `wkParticipo_Starter` (eventId, userId, type) values (:eventId, :userId, :typeId);';
|
$query = 'INSERT INTO `wkParticipo_Starter` (eventId, userId, type) values (:eventId, :userId, :typeId);';
|
||||||
$params = [
|
$params = [
|
||||||
':eventId' => ['value' => $starter->getEventId(), 'data_type' => PDO::PARAM_INT],
|
':eventId' => ['value' => $starter->getEventId(), 'data_type' => PDO::PARAM_INT],
|
||||||
@@ -278,12 +281,23 @@ class Event
|
|||||||
return dbConnector::query($query, $params);
|
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 = [])
|
public function getHtmlAddStarterForm($user, $options = [])
|
||||||
{
|
{
|
||||||
$defaults = [
|
$defaults = [
|
||||||
'formClass' =>'card col s12 m6 l3',
|
'formClass' => 'card col s12 m6 l3',
|
||||||
'inputClass' =>'input-field',
|
'inputClass' => 'input-field',
|
||||||
'buttonClass'=>'btn'
|
'buttonClass' => 'btn'
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
@@ -292,7 +306,7 @@ class Event
|
|||||||
|
|
||||||
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
|
$key = isset($_SESSION['apiKey']) ? $_SESSION['apiKey'] : null;
|
||||||
$form =
|
$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="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 . '" >'
|
||||||
@@ -304,7 +318,7 @@ class Event
|
|||||||
. '</select>'
|
. '</select>'
|
||||||
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
|
. '<label for="selectTypeForm">' . $user->getName() . ', ' . $user->getFirstname() . '</label>'
|
||||||
. '</div>'
|
. '</div>'
|
||||||
. '<input class="'.$options['buttonClass'].'" type="submit" name="submit" value="eintragen">'
|
. '<input class="' . $options['buttonClass'] . '" type="submit" name="submit" value="eintragen">'
|
||||||
. '</form>';
|
. '</form>';
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
|||||||
@@ -3,145 +3,170 @@
|
|||||||
require_once 'participoLib/participo.php';
|
require_once 'participoLib/participo.php';
|
||||||
|
|
||||||
/** Frame for a variable synced with a db*/
|
/** Frame for a variable synced with a db*/
|
||||||
class PdoCellValue{
|
class PdoCellValue
|
||||||
public function __construct(string $name, $value, $type){
|
{
|
||||||
$this->name = $name;
|
public function __construct(string $name, $value, $type)
|
||||||
$this->value = $value;
|
{
|
||||||
$this->type = $type;
|
$this->name = $name;
|
||||||
}
|
$this->value = $value;
|
||||||
static public function collect(array $row){
|
$this->type = $type;
|
||||||
$names = [];
|
}
|
||||||
foreach($row as $entry){
|
|
||||||
if(isset($entry->name)){
|
public static function collect(array $row)
|
||||||
$names[] = $entry->name;
|
{
|
||||||
}
|
$names = [];
|
||||||
}
|
foreach ($row as $entry) {
|
||||||
return $names;
|
if (isset($entry->name)) {
|
||||||
}
|
$names[] = $entry->name;
|
||||||
public function value(){return $this->value;}
|
}
|
||||||
public function setValue($value){$this->value = $value;}
|
}
|
||||||
private string $name = null;
|
return $names;
|
||||||
private $value = null;
|
}
|
||||||
private int $data_type = null;
|
|
||||||
|
public function value()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private member variables
|
||||||
|
private ?string $name = null;
|
||||||
|
private $value = null;
|
||||||
|
private ?int $type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Ride{
|
class Ride
|
||||||
/** Constructor
|
{
|
||||||
*
|
/** Constructor
|
||||||
* - filters/sanitizes all inputs
|
*
|
||||||
* - sets all members
|
* - filters/sanitizes all inputs
|
||||||
*
|
* - sets all members
|
||||||
* @param mixed $id setValue for the id
|
*
|
||||||
* @param mixed $eventId setValue for the eventId
|
* @param mixed $id setValue for the id
|
||||||
* @param mixed $driverId setValue for the driverId
|
* @param mixed $eventId setValue for the eventId
|
||||||
* @param mixed $seats setValue for the seats
|
* @param mixed $driverId setValue for the driverId
|
||||||
* @param string $passengerIds string of comma separated values
|
* @param mixed $seats setValue for the seats
|
||||||
*/
|
* @param string $passengerIds string of comma separated values
|
||||||
public function __construct($id, $eventId, $driverId, $seats, string $passengerIds){
|
*/
|
||||||
$this->id = new PdoCellValue('id', filterId($id), PDO::PARAM_INT);
|
public function __construct($id, $eventId, $driverId, $seats, string $passengerIds)
|
||||||
$this->eventId = new PdoCellValue('eventId', filterId($eventId), PDO::PARAM_INT);
|
{
|
||||||
$this->driverId = new PdoCellValue('fahrerId', filterId($driverId), PDO::PARAM_INT);
|
$this->id = new PdoCellValue('id', filterId($id), PDO::PARAM_INT);
|
||||||
$this->seats= new PdoCellValue('plaetze', filterCount($seats), PDO::PARAM_INT);
|
$this->eventId = new PdoCellValue('eventId', filterId($eventId), PDO::PARAM_INT);
|
||||||
$this->passengerIds = new PdoCellValue('mitfahrer', filterCsv($passengerIds, filterId), PDO::PARAM_STRING);
|
$this->driverId = new PdoCellValue('fahrerId', filterId($driverId), PDO::PARAM_INT);
|
||||||
}
|
$this->seats = new PdoCellValue('plaetze', filterCount($seats), PDO::PARAM_INT);
|
||||||
|
$this->passengerIds = new PdoCellValue('mitfahrer', filterCsv($passengerIds, filterId), PDO::PARAM_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
/** parse and sanitize a csvFormatted string */
|
/** parse and sanitize a csvFormatted string */
|
||||||
function filterCsv(string $list, $callback, string $separator=',', bool $dontTrim = false){
|
public function filterCsv(string $list, $callback, string $separator = ',', bool $dontTrim = false)
|
||||||
$list = explode($separator, $list);
|
{
|
||||||
foreach($list as &$element){
|
$list = explode($separator, $list);
|
||||||
$element = $callback($element);
|
foreach ($list as &$element) {
|
||||||
if(!$dontTrim){
|
$element = $callback($element);
|
||||||
$element = trim($element);
|
if (!$dontTrim) {
|
||||||
}
|
$element = trim($element);
|
||||||
}
|
}
|
||||||
return $list;
|
}
|
||||||
}
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
// private functions
|
// private functions
|
||||||
////
|
////
|
||||||
|
|
||||||
// DbInterface
|
// DbInterface
|
||||||
private static $dbName = 'cwsvjudo';
|
private const dbName = 'cwsvjudo';
|
||||||
private static $dbTableName = 'wkParticipo_Fahrten';
|
private const dbTableName = 'wkParticipo_Fahrten';
|
||||||
private static $dbFullTableNameString = '`'.$dbName.'`.`'.$dbTableName.'`';
|
private const dbFullTableNameString = '`' . self::dbName . '`.`' . self::dbTableName . '`';
|
||||||
|
|
||||||
/** Slice a list of arrays 'horizontal' through a specific key
|
/** Slice a list of arrays 'horizontal' through a specific key
|
||||||
*
|
*
|
||||||
* - iterate through a list of arrays and collect the values under a specific key
|
* - iterate through a list of arrays and collect the values under a specific key
|
||||||
* - if the key doesn't exist nothing (not even null) will be collected
|
* - if the key doesn't exist nothing (not even null) will be collected
|
||||||
*
|
*
|
||||||
* @param array $array source array
|
* @param array $array source array
|
||||||
* @param mixed $key key to collect
|
* @param mixed $key key to collect
|
||||||
* @return array list of array entries
|
* @return array list of array entries
|
||||||
*/
|
*/
|
||||||
function sliceArrayByKey(array $array, $key){
|
public function sliceArrayByKey(array $array, $key)
|
||||||
$sliced = [];
|
{
|
||||||
foreach($array as $entry){
|
$sliced = [];
|
||||||
if(isset($entry[$key])){
|
foreach ($array as $entry) {
|
||||||
$sliced[] = $entry[$key];
|
if (isset($entry[$key])) {
|
||||||
}
|
$sliced[] = $entry[$key];
|
||||||
}
|
}
|
||||||
return $sliced;
|
}
|
||||||
}
|
return $sliced;
|
||||||
|
}
|
||||||
|
|
||||||
private static function dbSelect(){}
|
private static function dbSelect()
|
||||||
private static function dbInsert(array $values){
|
{
|
||||||
$names = [];
|
}
|
||||||
$binds = [];
|
|
||||||
$params = [];
|
|
||||||
foreach($values as $value){
|
|
||||||
$names[] = $value->name;
|
|
||||||
$binds[] = ':'.$value->name;
|
|
||||||
$params[':'.$value->name] = [
|
|
||||||
'value' => $value->name
|
|
||||||
, 'data_type' => $value->type
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = 'INSERT INTO '.$dbFullTableNameString.' ('.implode(',', $names).') values ('.implode(',', $binds).');';
|
private static function dbInsert(array $values)
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
$binds = [];
|
||||||
|
$params = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
$names[] = $value->name;
|
||||||
|
$binds[] = ':' . $value->name;
|
||||||
|
$params[':' . $value->name] = [
|
||||||
|
'value' => $value->name, 'data_type' => $value->type
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// @todo remove ignoreErrors again
|
$query = 'INSERT INTO ' . $dbFullTableNameString . ' (' . implode(',', $names) . ') values (' . implode(',', $binds) . ');';
|
||||||
// @todo Inserting-Starter-Statement returns false on execution: Why? It seems to succeed!
|
|
||||||
$response = dbConnector::query($query, $params, ['ignoreErrors'=>true]);
|
// @todo remove ignoreErrors again
|
||||||
|
// @todo Inserting-Starter-Statement returns false on execution: Why? It seems to succeed!
|
||||||
|
$response = dbConnector::query($query, $params, ['ignoreErrors' => true]);
|
||||||
return dbConnector::getLastInsertId();
|
return dbConnector::getLastInsertId();
|
||||||
}
|
}
|
||||||
private static function dbDelete(){}
|
|
||||||
private static function dbUpdate(){}
|
|
||||||
|
|
||||||
private
|
private static function dbDelete()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function dbUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
// private variables
|
// private variables
|
||||||
////
|
////
|
||||||
|
|
||||||
/** Unique Identifier for the Ride
|
/** Unique Identifier for the Ride
|
||||||
*
|
*
|
||||||
* @var int > 0
|
* @var int > 0
|
||||||
*/
|
*/
|
||||||
private $id=null;
|
private $id = null;
|
||||||
/** Id of the event for the ride
|
/** Id of the event for the ride
|
||||||
*
|
*
|
||||||
* @var int > 0
|
* @var int > 0
|
||||||
*/
|
*/
|
||||||
private $eventId = null;
|
private $eventId = null;
|
||||||
/** Id of the user who offered the drive
|
/** Id of the user who offered the drive
|
||||||
*
|
*
|
||||||
* @var int > 0
|
* @var int > 0
|
||||||
*/
|
*/
|
||||||
private $driverId = null;
|
private $driverId = null;
|
||||||
/** number of seats the drive offers
|
/** number of seats the drive offers
|
||||||
*
|
*
|
||||||
* @var int > 0
|
* @var int > 0
|
||||||
*/
|
*/
|
||||||
private $seats = null;
|
private $seats = null;
|
||||||
/** List of Ids of the users this ride chauffeurs
|
/** List of Ids of the users this ride chauffeurs
|
||||||
*
|
*
|
||||||
* @var array(int > 0)
|
* @var array(int > 0)
|
||||||
*/
|
*/
|
||||||
private $passengerIds = null;
|
private $passengerIds = null;
|
||||||
|
|
||||||
private $event = null;
|
private $event = null;
|
||||||
private $driver = null;
|
private $driver = null;
|
||||||
private $passengers = null;
|
private $passengers = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class Shiai
|
|||||||
$retHtml =
|
$retHtml =
|
||||||
'<div>' .
|
'<div>' .
|
||||||
'<h3>' . $this->getHtmlName() . '</h3>' .
|
'<h3>' . $this->getHtmlName() . '</h3>' .
|
||||||
'<dl>' .
|
'<dl>'.
|
||||||
'<dt>Datum:</dt><dd>' . $this->getHtmlDate() . '</dd>' .
|
'<dt>Datum:</dt><dd>' . $this->getHtmlDate() . '</dd>' .
|
||||||
'<dt>Altersklassen</dt><dd>' . $this->getAgeClasses() . '</dd>' .
|
'<dt>Altersklassen</dt><dd>' . $this->getAgeClasses() . '</dd>' .
|
||||||
'<dt>Ort</dt><dd>' . $this->getPlace() . '</dd>' .
|
'<dt>Ort</dt><dd>' . $this->getPlace() . '</dd>' .
|
||||||
|
|||||||
Reference in New Issue
Block a user