- added simple achievement editor
- added records
This commit is contained in:
221
homepage/machs/lib/record.php
Normal file
221
homepage/machs/lib/record.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
require_once('./lib/db.php');
|
||||
|
||||
|
||||
class record{
|
||||
//< id of the record in the db
|
||||
private $id;
|
||||
//< id of current holder in the db
|
||||
private $userId;
|
||||
//< the age class the record is for
|
||||
private $ageClass;
|
||||
//< when the record was established
|
||||
private $timestap;
|
||||
//< what the record is about
|
||||
private $description;
|
||||
//< the value to beat
|
||||
private $value;
|
||||
//< the achievement needed for the record
|
||||
private $unlockingAchievement;
|
||||
|
||||
private static $db;
|
||||
/// Names of the columns in the db
|
||||
private static $colNames = ['id', 'achievementGroupId', 'ageClass', 'userId', 'timestamp', 'value', 'description'];
|
||||
public static function setDbConnection($dbConnection){
|
||||
if($dbConnection instanceof PDO)
|
||||
self::$db = $dbConnection;
|
||||
else
|
||||
self::$db = null;
|
||||
return;
|
||||
}
|
||||
|
||||
public static function getAllRecords(){
|
||||
$query = <<<SQL
|
||||
SELECT * FROM `cwsvjudo`.`machs_records`;
|
||||
SQL;
|
||||
return dbQuery(self::$db, $query);
|
||||
}
|
||||
public static function getUserData($userId){
|
||||
$query = <<<SQL
|
||||
SELECT * FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
WHERE `cwsvjudo`.`wkParticipo_Users`.`id` = :userId ;
|
||||
SQL;
|
||||
return dbQuery(self::$db, $query, ['userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]);
|
||||
}
|
||||
// request the records of a group together with its holder
|
||||
// @param $groupId id of the group of achievements where the records are wanted
|
||||
// @param $ageClass the age class (as int only) for which the record is holding
|
||||
//
|
||||
// a record of an achievement group consists of:
|
||||
// - a value
|
||||
// - an age class
|
||||
public static function getGroupsRecords($groupId, $ageClass=null){
|
||||
// var_dump($groupId, $ageClass);
|
||||
//$ageClass = null; // DEBUG
|
||||
$query = "SELECT * FROM `cwsvjudo`.`machs_records` ";
|
||||
$query.= "JOIN `cwsvjudo`.`wkParticipo_Users` ";
|
||||
$query.= " ON `cwsvjudo`.`machs_records`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id` ";
|
||||
$query.= "WHERE `cwsvjudo`.`machs_records`.`achievementGroupId` = :groupId ";
|
||||
$params =[
|
||||
'groupId'=>[ 'value'=>$groupId, 'data_type'=>PDO::PARAM_INT ]
|
||||
];
|
||||
if($ageClass != null){
|
||||
$query.= " AND `cwsvjudo`.`machs_records`.`ageClass` <= :ageClass ";
|
||||
$params['ageClass'] = [ 'value'=>$ageClass, 'data_type'=>PDO::PARAM_INT ];
|
||||
}
|
||||
$query.= "ORDER BY `cwsvjudo`.`machs_records`.`value`;";
|
||||
//var_dump($query, $params);
|
||||
return dbQuery(self::$db, $query, $params);
|
||||
}
|
||||
/// @param $r record as associative array
|
||||
public static function arrayRecord2htmlDl($r){
|
||||
$retHtml = "<dl>";
|
||||
foreach(self::$colNames as $i)
|
||||
$retHtml.= "<dt>".$i."</dt><dd>".$r[$i]."</dd>";
|
||||
$retHtml.= "</dl>";
|
||||
return $retHtml;
|
||||
}
|
||||
/// @param $r record joined with it's holder as associative error
|
||||
/// @param $u user for whom the record is shown
|
||||
public static function arrayRecord2htmlCard($r, $u, $gid, $frameTag="div"){
|
||||
$retHtml = "<".$frameTag." class=\"card\">";
|
||||
$retHtml.= "<div class=\"card-content\">";
|
||||
$retHtml.= "<span class=\"card-title\">Zu schlagender Rekord</span>";
|
||||
if(empty($r)){
|
||||
$retHtml.= "Noch kein Rekord für die Altersklasse U".record::birthday2ageClass($u['gebDatum']);
|
||||
}
|
||||
else{
|
||||
$retHtml.= $r['vorname']." ".$r['name']." mit ".$r['value']." in der U".$r['ageClass'];
|
||||
}
|
||||
$retHtml.= "</div>";
|
||||
$retHtml.= "<div class=\"card-action\">";
|
||||
$retHtml.= "<a class=\"waves-effect waves-light btn modal-trigger\" href=\"#reportRecord-user-".$u['id']."-group-".$gid."\">Rekord melden</a>";
|
||||
$retHtml.= "<div id=\"reportRecord-user-".$u['id']."-group-".$gid."\" class=\"modal\">";
|
||||
$retHtml.= "<div class=\"modal-content\">";
|
||||
$retHtml.= "Rekorde stellen in jeder Achievementgruppe und Altersklasse die Bestleistung unter allen Judoka dar. Rekorde können unabhänging vom eigenen, aktuellen Achievementstand aufgestellt werden.";
|
||||
$retHtml.= "Die Rekorde der jüngeren gelten auch für die älteren, aber nicht umgekehrt. ";
|
||||
$retHtml.= "Damit ein Rekord auch eingetragen wird, muss er mit einem Nachweis in Videoform gemeldet werden.";
|
||||
$retHtml.= "<h4>Rekord melden</h4>";
|
||||
$retHtml.= "Um einen Rekord zu melden, lade ein Video des Rekordes hoch:";
|
||||
$retHtml.= htmlUsersUploadBox(self::$db, $u['id']);
|
||||
$retHtml.= "Anschließend kannst Du den Rekord melden:";
|
||||
$retHtml.= "<form action=\".\" method=\"POST\">";
|
||||
if(isUserAdmin(record::$db, $_SESSION['user']['userId'])){
|
||||
$retHtml.= "<input name=\"action\" value=\"setRecord\" type=\"hidden\">";
|
||||
}
|
||||
else{
|
||||
$retHtml.= "<input name=\"action\" value=\"reportRecord\" type=\"hidden\">";
|
||||
}
|
||||
$retHtml.= "<input name=\"userId\" value=\"".$u['id']."\" type=\"hidden\">";
|
||||
$retHtml.= "<input name=\"achievementGroupId\" value=\"".$gid."\" type=\"hidden\">";
|
||||
$retHtml.= $u['vorname']." ".$u['name']." hat <input name=\"value\" placeholder=\"Zeit/Anzahl\"> geschafft.";
|
||||
if(isUserAdmin(record::$db, $_SESSION['user']['userId'])){
|
||||
$retHtml.= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord eintragen\">";
|
||||
}
|
||||
else{
|
||||
$retHtml.= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord melden\">";
|
||||
}
|
||||
$retHtml.= "</form>";
|
||||
$retHtml.= "</div>";
|
||||
$retHtml.= "<div class=\"modal-footer\">";
|
||||
$retHtml.= "<a href=\"#!\" class=\"modal-close waves-effect waves-green btn-flat\">Zurück</a>";
|
||||
$retHtml.= "</div>";
|
||||
$retHtml.= "</div>";
|
||||
$retHtml.= "</div>";
|
||||
$retHtml.= "</".$frameTag.">";
|
||||
return $retHtml;
|
||||
|
||||
|
||||
|
||||
}
|
||||
public static function birthday2ageClass($birthdateString){
|
||||
$birthDate = DateTime::createFromFormat("Y-m-d", $birthdateString);
|
||||
$birthYear= (int)$birthDate->format("Y");
|
||||
$thisYear = (int)date('Y');
|
||||
return $thisYear - $birthYear + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Als String gegebene Altersklassen als Jahrgangsintervalle
|
||||
/// ausdrücken
|
||||
function akListString2jgArray($akListString, $year = NULL ){
|
||||
$ret = array();
|
||||
if($year==NULL)
|
||||
$year=date("Y");
|
||||
else{
|
||||
if( !((int)$year == $year && (int)$year >= 0) )
|
||||
$year=date("Y");
|
||||
}
|
||||
|
||||
$year = (int)$year;
|
||||
|
||||
foreach(explode(" ", $akListString) as $ak)
|
||||
array_push(
|
||||
$ret,
|
||||
akString2jgIntervall($ak, $year)
|
||||
);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/// Aus einer als String gegebenen Altersklasse ein Jahrgangsintervall
|
||||
/// machen
|
||||
function akString2jgIntervall($akString, $year=null){
|
||||
if($year==NULL)
|
||||
$year=date("Y");
|
||||
else{
|
||||
if( !((int)$year == $year && (int)$year >= 0) )
|
||||
$year=date("Y");
|
||||
}
|
||||
|
||||
$ret= array(NULL, NULL);
|
||||
|
||||
// Speziell für die Ux-Altersklassen
|
||||
// Es fehlt noch das <=U
|
||||
$akUmatchString = "/(.*)U(.*)/";
|
||||
$matches = array();
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// Wenn wir nicht den gesamten akString Matchen ist etwas schief
|
||||
// gelaufen
|
||||
if($matches[0]==$akString){
|
||||
// Das ausgelesene Alter der Ux sollte eine positive Integer sein,
|
||||
// sonst ist was schiefgelaufen
|
||||
$ageLimit = (int)$matches[2];
|
||||
if( ($ageLimit == $matches[2] && $ageLimit > 0) ){
|
||||
$ret[0] = $year-$ageLimit+1;
|
||||
|
||||
if($matches[1] == "")
|
||||
$ret[1] = $year-$ageLimit+2;
|
||||
else{
|
||||
if($matches[1] == "-")
|
||||
$ret[1] = $year-$ageLimit+3;
|
||||
else{
|
||||
if($matches[1] == "--")
|
||||
$ret[1] = $year-$ageLimit+4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// Speziell Altersklassen der Form Jg.x-y
|
||||
$akUmatchString = "/Jg\.(.*)\-(.*)/";
|
||||
$matches = array();
|
||||
preg_match($akUmatchString, $akString, $matches);
|
||||
// Wenn wir nicht den gesamten akString Matchen ist etwas schief
|
||||
// gelaufen
|
||||
if($matches[0]==$akString){
|
||||
$ret[0]=(int)$matches[1];
|
||||
$ret[1]=(int)$matches[2];
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function validateDate($date, $format = 'Y-m-d')
|
||||
{
|
||||
$d = DateTime::createFromFormat($format, $date);
|
||||
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
|
||||
return $d && $d->format($format) === $date;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user