add 12NächteChallenge2021

This commit is contained in:
marko
2021-12-21 10:21:17 +01:00
parent 0c4334990e
commit 40efdcea23
2 changed files with 33 additions and 8 deletions

View File

@@ -52,6 +52,26 @@ processPostData($dbConnection, $_POST);
<body>
<?php include("lib/machs/sidenav.php");?>
<?php // Für die 12-Nächte-Challenge
$now = new DateTime();
$promoStart = new DateTime("2021-11-24");
$promoEnd = new DateTime("2022-02-06");
$from = new DateTime("2021-12-24");
if($promoStart <= $now && $now <= $promoEnd) {
echo("<h1 style=\"font-size:1.5rem;\">12-Nächte-Challenge</h1>");
if($now < $from) echo("<p>Die 12-Nächte-Challenge geht vom 24.12.2021--06.01.2022. Ziel ist es möglichts an allen Tagen ein Achievement zu erhalten. Sobald es losgeht, wird hier die aktuelle Rangliste stehen.");
record::setDbConnection($dbConnection);
$zwölfer = record::getTopAchievers(array('from'=>"2021-12-24", 'to'=>"2022-01-06"));
echo("<table>");
record::setDbConnection($dbConnection);
foreach( record::getTopAchievers(array('from'=>"2021-12-24", 'to'=>"2022-01-06")) as $t ){
echo("<tr><td>".$t['vorname']."</td><td>".$t['name']."</td><td>".$t['COUNT(*)']."</td></tr>");
}
echo("</table>");
}
?>
<?php
if( hasUserAttribute($dbConnection, $_SESSION['user']['userId'], "inTraining" ) ){
echo( "<h2>Eigene Achievements</h2>" );

View File

@@ -33,14 +33,19 @@ class record{
}
public static function getTopAchievers($options=array()){
$query = <<<SQL
SELECT `wkParticipo_Users`.`vorname`, `wkParticipo_Users`.`name`, COUNT(*)
FROM `achievements<=>user`
JOIN `wkParticipo_Users`
ON `wkParticipo_Users`.`id` = `achievements<=>user`.`userId`
GROUP BY `wkParticipo_Users`.`id`
ORDER BY `COUNT(*)` DESC;
SQL;
$from = array_key_exists('from',$options)?$options['from']:null;
$to = array_key_exists('to',$options)?$options['to']:null;
$query =
"SELECT `wkParticipo_Users`.`vorname`, `wkParticipo_Users`.`name`, COUNT(*) ".
"FROM `achievements<=>user` JOIN `wkParticipo_Users` ".
"ON `wkParticipo_Users`.`id` = `achievements<=>user`.`userId` ".
(
($from!=null&&$to!=null)?
("BETWEEN CONVERT(\"".$from."\", datetime) AND CONVERT(\"".$to."\", datetime) "):
("")
).
"GROUP BY `wkParticipo_Users`.`id` ".
"ORDER BY `COUNT(*)` DESC;";
return dbQuery(self::$db, $query);
}