- Records page introduced
- rearangements in the include structure
This commit is contained in:
@@ -8,6 +8,13 @@ function processPostData($db, $post, $redirectLocation = "."){
|
||||
$post['userId'],
|
||||
$post['achievementId']
|
||||
);
|
||||
$u = getUserData($db, $post['userId']);
|
||||
$a = getAchievement($db, $post['achievementId']);
|
||||
sendEmail(
|
||||
"cwsvjudo@arcor.de",
|
||||
"kwT",
|
||||
$u['vorname']." ".$u['name']." got achievement ".$a[0]['name']
|
||||
);
|
||||
}
|
||||
if($post['action']=="addAchievement"){
|
||||
addAchievement(
|
||||
@@ -31,6 +38,18 @@ function processPostData($db, $post, $redirectLocation = "."){
|
||||
);
|
||||
}
|
||||
|
||||
if($post['action']=="autoAddAchievements"){
|
||||
$g=new achievementGroup;
|
||||
$g->setDbConnection($db);
|
||||
$g->loadAchievementGroupFromDb($post['achievementGroupId']);
|
||||
$g->autoAddAchievements(
|
||||
$post['messageTemplate'],
|
||||
$post['from'],
|
||||
$post['to'],
|
||||
$post['step']
|
||||
);
|
||||
}
|
||||
|
||||
if($post['action']=="updateAchievement"){
|
||||
updateAchievement(
|
||||
$db,
|
||||
@@ -63,19 +82,21 @@ function processPostData($db, $post, $redirectLocation = "."){
|
||||
);
|
||||
}
|
||||
if($post['action']=="setRecord"){
|
||||
# $u = getUserData($db, $post['userId']);
|
||||
# $ag = new achievementGroup;
|
||||
# achievementGroup::setDbConnection($db);
|
||||
# $ag->loadAchievementGroupFromDb($post['achievementGroupId']);
|
||||
# $m = $u['vorname']." ".$u['name']." hat in ".$ag->getName()." ".$post['value']." geschafft!";
|
||||
$m = $post['userId']." hat in ".$post['achievementGroupId']." ".$post['value']." geschafft!";
|
||||
sendEmail("cwsvjudo@arcor.de", $m, "[machs] Rekord eingetragen");
|
||||
# setRecord(
|
||||
# $db,
|
||||
# $post['userId'],
|
||||
# $post['achievementGroupId'],
|
||||
# $post['value']
|
||||
# );
|
||||
$u = getUserData($db, $post['userId']);
|
||||
$g = new achievementGroup;
|
||||
$g->setDbConnection($db);
|
||||
$g->loadAchievementGroupFromDb($post['achievementGroupId']);
|
||||
sendEmail(
|
||||
"cwsvjudo@arcor.de",
|
||||
$u['vorname']." ".$u['name']." got ".$post['value']." in ".$g->getName(),
|
||||
"[machs] Rekord eingetragen"
|
||||
);
|
||||
//setRecord(
|
||||
//$db,
|
||||
//$post['userId'],
|
||||
//$post['achievementGroupId'],
|
||||
//$post['value']
|
||||
//);
|
||||
}
|
||||
if($post['action']=="reportRecord"){
|
||||
# $u = getUserData($db, $post['userId']);
|
||||
|
||||
@@ -64,6 +64,8 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
||||
if(!$pdoResult){
|
||||
echo("Error during dbQuery!\n");
|
||||
echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo());
|
||||
// var_dump($aQueryString);
|
||||
// var_dump($aBindArray);
|
||||
// echo($pdoStatement.errorInfo());
|
||||
}
|
||||
if($someOptions['dontFetch']){
|
||||
@@ -245,8 +247,6 @@ INSERT INTO `cwsvjudo`.`achievements<=>user` (`userId`, `achievementId`) VALUE (
|
||||
SQL;
|
||||
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT], 'achievementId'=>['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT]];
|
||||
dbQuery($db, $query, $params);
|
||||
sendEmail("cwsvjudo@arcor.de", "kwT", "User ".$userId." got achievement ".$achievementId);
|
||||
//var_dump($query, $params);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,18 @@ SQL;
|
||||
return dbQuery($db, $query);
|
||||
}
|
||||
|
||||
function getAchievement($db, $id){
|
||||
$query = <<<SQL
|
||||
SELECT *
|
||||
FROM `cwsvjudo`.`achievements`
|
||||
WHERE `id`=:id;
|
||||
SQL;
|
||||
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
|
||||
return dbQuery($db, $query, $params);
|
||||
}
|
||||
|
||||
function addAchievement($db, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
|
||||
// var_dump($db);
|
||||
if($rootId=="")
|
||||
$rootId=null;
|
||||
if($imgUrl=="")
|
||||
|
||||
@@ -4,24 +4,34 @@ require_once('./lib/db.php');
|
||||
|
||||
// A series of achievements
|
||||
class achievementGroup{
|
||||
// data from the achievements group table
|
||||
// id of the group
|
||||
private $id;
|
||||
// name of the group
|
||||
private $name;
|
||||
// Achievement, that unlocks the group
|
||||
private $unlockingAchievementId;
|
||||
// an image for the group
|
||||
private $imageUrl;
|
||||
|
||||
// achievements, that belong to this group
|
||||
private $achievements;
|
||||
|
||||
|
||||
// pointer to the db that shall be used for queries
|
||||
private static $db=null;
|
||||
// name of the table
|
||||
// private static $tableName = "`cwsvjudo`.`machs_achievementGroups`";
|
||||
|
||||
static function setDbConnection($dbConnection){
|
||||
// set the dbConnection (just setting, no establishing)
|
||||
public static function setDbConnection($dbConnection){
|
||||
if($dbConnection instanceof PDO)
|
||||
self::$db = $dbConnection;
|
||||
else
|
||||
self::$db = null;
|
||||
return;
|
||||
}
|
||||
static function getDbConnection(){
|
||||
// get the db pointer
|
||||
public static function getDbConnection(){
|
||||
return self::$db;
|
||||
}
|
||||
|
||||
@@ -46,7 +56,7 @@ SQL;
|
||||
return $groups;
|
||||
}
|
||||
|
||||
//getter functions for the member variables
|
||||
//getter functions for the (primitive) member variables
|
||||
function getId(){return $this->id;}
|
||||
function getName(){return $this->name;}
|
||||
function getUnlockingAchievementId(){return $this->unlockingAchievementId;}
|
||||
@@ -69,13 +79,13 @@ SQL;
|
||||
return $this->achievements;
|
||||
} // end getAchievements
|
||||
|
||||
/// Load the achievementgroup $id from the db into the
|
||||
/// Load the achievementgroup $id from the db (into this)
|
||||
function loadAchievementGroupFromDb($id){
|
||||
$query = <<<SQL
|
||||
SELECT * FROM `cwsvjudo`.`machs_achievementGroups` WHERE `id` = :id;
|
||||
SQL;
|
||||
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
|
||||
$result = dbQuery(self::$db, $query, $param);
|
||||
$result = dbQuery(self::$db, $query, $params);
|
||||
|
||||
$this->setAchievementGroupData(
|
||||
$result[0]['id'],
|
||||
@@ -94,23 +104,6 @@ SQL;
|
||||
$this->imageUrl = $imageUrl;
|
||||
}
|
||||
|
||||
/// A simple representation of the group in html code
|
||||
function html(){
|
||||
$html = "";
|
||||
$html .= "<div>";
|
||||
$html .= "<dl>";
|
||||
$html .= "<dt>Id: </dt><dd>".$this->id."</dd>";
|
||||
$html .= "<dt>name: </dt><dd>".$this->name."</dd>";
|
||||
$html .= "<dt>unlockingAchievementId: </dt><dd>".$this->unlockingAchievementId."</dd>";
|
||||
$html .= "<dt>Achievements: </dt><dd><ul>";
|
||||
foreach($this->achievements as $a)
|
||||
$html .= "<li>".$a['name']."</li>";
|
||||
$html .= "</ul></dd>";
|
||||
$html .= "</dl>";
|
||||
$html .= "</div>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
/// gets all achievements of that user in that group reachedd
|
||||
function getUsersAchievements($userId, $options=[]){
|
||||
$getAll = $options['getAll']??false;
|
||||
@@ -131,7 +124,7 @@ return $result;
|
||||
///
|
||||
/// @param $uId id of the user the achievements should be
|
||||
function asHtmlCard($uId, $options=[]){
|
||||
$noForm = $options['noForm']??true;
|
||||
$noForm = $options['noForm']??true; // for deactivating the give achievement form
|
||||
$retHtml = "";
|
||||
$userData = record::getUserData($uId);
|
||||
$usersAchievements = $this->getUsersAchievements( $uId, ['getAll'=>true] );
|
||||
@@ -139,6 +132,7 @@ return $result;
|
||||
foreach($usersAchievements as $a){
|
||||
$usersAchievementIds[]=(int)$a['achievementId'];
|
||||
}
|
||||
// If the user hasn't have the needed Achievement
|
||||
if(!in_array($this->getUnlockingAchievementId(), $usersAchievementIds))
|
||||
return "";
|
||||
$records = record::getGroupsRecords(
|
||||
@@ -149,15 +143,17 @@ return $result;
|
||||
|
||||
$retHtml .= "<div class=\"col s12 m6 l4 xl3\">";
|
||||
$retHtml .= "<div class=\"card\">";
|
||||
$retHtml .= "<div class=\"card-content\">";
|
||||
|
||||
if($this->imageUrl != null){
|
||||
$retHtml .= "<div class=\"card-image\"><img src=\"".$this->imageUrl."\">";
|
||||
}
|
||||
$retHtml .= "<span class=\"card-title\">".$this->name."</span>";
|
||||
if($this->imageUrl != null){
|
||||
$retHtml .= "<span class=\"card-title\">".$this->name."</span>";
|
||||
$retHtml .= "</div>";
|
||||
}
|
||||
$retHtml .= "<ul>";
|
||||
else
|
||||
$retHtml .= "<span style=\"padding-left: 1vw;\" class=\"card-title\">".$this->name."</span>";
|
||||
|
||||
$retHtml .= "<div class=\"card-content\">";
|
||||
$retHtml .= "<ul class=\collapsible\">";
|
||||
foreach($achievements as $a){
|
||||
if(in_array((int)$a['id'], $usersAchievementIds)){
|
||||
$retHtml .= "<li>✓ ".$a['name'].": ".$a['description'];
|
||||
@@ -165,34 +161,43 @@ return $result;
|
||||
}
|
||||
else{
|
||||
$retHtml .= "<li style=\"color:gray\">".$a['name'].": ".$a['description'];
|
||||
if(!$noForm){
|
||||
if( canUserGetAchievementToday( $this->getDbConnection(), $uId) or isUserAdmin($this->getDbConnection(), $_SESSION['user']['userId']) ){
|
||||
$retHtml .= "<form action=\".\" method=\"POST\">";
|
||||
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\">";
|
||||
$retHtml .= "<input name=\"redirectLocation\" value=\"./#achievementList-".$uId."\" type=\"hidden\">";
|
||||
$retHtml .= "<input name=\"userId\" value=\"".$uId."\" type=\"hidden\">";
|
||||
$retHtml .= "<input name=\"achievementId\" value=\"".$a['id']."\" type=\"hidden\">";
|
||||
$retHtml .= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Achievement ".$a['name']." geben\">";
|
||||
$retHtml .= "</form>";
|
||||
}
|
||||
}
|
||||
if( $imgUrl != null )
|
||||
$retHtml .= " <div class=\"card-image\" ><img src=\"".$imgUrl."\"/></div>";
|
||||
$retHtml .= "</li>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
// show the current record
|
||||
|
||||
if( validateDate($userData[0]['gebDatum'])){
|
||||
$retHtml.=record::arrayRecord2htmlCard($records[0], $userData[0], $this->getId(), "li");
|
||||
}
|
||||
else{
|
||||
$retHtml.="<div>Rekorde können erst angezeigt werden, wenn das <a href=./setUserData.php>Geburtsdatum korrekt gesetzt</a> wurde!</div>";
|
||||
}
|
||||
|
||||
$retHtml .= "</ul>";
|
||||
$retHtml .= "</div>";// end card-content
|
||||
$retHtml .= "<div class=\"card-action\">";
|
||||
if(!$noForm){
|
||||
if( canUserGetAchievementToday( $this->getDbConnection(), $uId) or isUserAdmin($this->getDbConnection(), $_SESSION['user']['userId']) ){
|
||||
$retHtml .= "<form action=\".\" method=\"POST\">";
|
||||
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\" />";
|
||||
$retHtml .= "<input name=\"redirectLocation\" value=\"./#achievementList-".$uId."\" type=\"hidden\" />";
|
||||
$retHtml .= "<input name=\"userId\" value=\"".$uId."\" type=\"hidden\" />";
|
||||
$retHtml .= "<input name=\"achievementId\" value=\"".$a['id']."\" type=\"hidden\" />";
|
||||
$retHtml .= "<input name=\"submit\" type=\"submit\" value=\"".$a['name']." geben\">";
|
||||
// $retHtml .= "<button class=\"btn\" name=\"submit\" type=\"submit\" >Achievement ".$a['name']." geben</button>";
|
||||
$retHtml .= "</form>";
|
||||
}
|
||||
if( validateDate($userData[0]['gebDatum'])){
|
||||
$retHtml.=record::arrayRecord2htmlCardAction($records[0], $userData[0], $this->getId(), "li");
|
||||
}
|
||||
else{
|
||||
$retHtml.="<div>Rekorde können erst angezeigt werden, wenn das <a href=./setUserData.php>Geburtsdatum korrekt gesetzt</a> wurde!</div>";
|
||||
}
|
||||
}
|
||||
$retHtml .= "</div>";
|
||||
$retHtml .= "</div>";
|
||||
$retHtml .= "</div>";
|
||||
|
||||
$retHtml .= "</div>";// end card
|
||||
$retHtml .= "</div>";// end col
|
||||
return $retHtml;
|
||||
}// end asHtmlCard
|
||||
|
||||
@@ -228,5 +233,73 @@ return $result;
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function htmlAutoAddAchievementsForm($achievementGroupId, $messageTemplate=null, $from=null, $to=null, $step=null){
|
||||
$html = "";
|
||||
$html .= "<form action=\".\" method=\"POST\">";
|
||||
|
||||
$html .= "<input name=\"action\" type=\"hidden\" value=\"autoAddAchievements\" />";
|
||||
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
|
||||
$html .= "<input name=\"achievementGroupId\" type=\"hidden\" value=\"".$achievementGroupId."\"/>";
|
||||
|
||||
$html .= "<label for=\"messageTemplate\">messageTemplate ('%value%' is Placeholder for the value that goes from fromValue to toValue in step)</label>";
|
||||
$html .= "<input style=\"width:100%;display:block;\" name=\"messageTemplate\" type=\"textarea\" value=\"".$messageTemplate."\"/>";
|
||||
|
||||
$html .= "<label for\"from\">fromValue</label>";
|
||||
$html .= "<input name=\"from\" type=\"text\" value=\"".$from."\"/>";
|
||||
$html .= "<label for\"to\">toValue</label>";
|
||||
$html .= "<input name=\"to\" type=\"text\" value=\"".$to."\"/>";
|
||||
$html .= "<label for\"step\">step</label>";
|
||||
$html .= "<input name=\"step\" type=\"text\" value=\"".$step."\"/>";
|
||||
|
||||
$html .= "<input type=\"submit\" value=\"Auto Add Achievements\" />";
|
||||
$html .= "</form>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
/// auto generate the achievements for this group
|
||||
/// @todo only for empty groups?
|
||||
function autoAddAchievements($messageTemplate, $from, $to, $step){
|
||||
if(!empty($this->getAchievements())){
|
||||
echo("Won't auto-add Achievements to non-empty AchievementGroup!");
|
||||
return;
|
||||
}
|
||||
$level = 1;
|
||||
for ($value = (int)$from; $value <= (int)$to; $value+=(int)$step) {
|
||||
$name = $this->getName()." ".intToRomanRepresentation($level++);
|
||||
$description = str_replace("%value%", (string)$value, $messageTemplate);
|
||||
$this->addAchievement($name, $description, $level);
|
||||
}
|
||||
}
|
||||
|
||||
// adds an achievement to the group (in the db!)
|
||||
function addAchievement($name, $description, $level, $rootId=null){
|
||||
addAchievement(
|
||||
$this->getDbConnection(),
|
||||
$name,
|
||||
$rootId,
|
||||
$this->getId(),
|
||||
$level,
|
||||
$description,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// convert an int number to roman representation
|
||||
/// @param int $number
|
||||
/// @return string
|
||||
function intToRomanRepresentation($number){
|
||||
$map = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
|
||||
$returnValue = '';
|
||||
while ($number > 0) {
|
||||
foreach ($map as $roman => $int) {
|
||||
if($number >= $int) {
|
||||
$number -= $int;
|
||||
$returnValue .= $roman;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnValue;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -11,4 +11,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
var elems = document.querySelectorAll('.sidenav');
|
||||
var instances = M.Sidenav.init(elems, options);
|
||||
});
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var elems = document.querySelectorAll('.collapsible');
|
||||
var instances = M.Collapsible.init(elems, options);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<ul id="slide-out" class="sidenav">
|
||||
<li><?php echo $login_status;?></li>
|
||||
<li><a href=".">Achievements</a></li>
|
||||
<li><a href="records.php">Rekorde</a></li>
|
||||
<li><a href="./setUserData.php">Benutzerdaten</a></li>
|
||||
<?php
|
||||
if(isUserAdmin($dbConnection, $_SESSION['user']['userId'])){
|
||||
|
||||
@@ -5,18 +5,18 @@ 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;
|
||||
//< goup the record is for
|
||||
private $achievementGroupId;
|
||||
//< the age class the record is for
|
||||
private $ageClass;
|
||||
//< id of current holder in the db
|
||||
private $userId;
|
||||
//< 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;
|
||||
//< what the record is about
|
||||
private $description;
|
||||
|
||||
private static $db;
|
||||
/// Names of the columns in the db
|
||||
@@ -28,6 +28,10 @@ class record{
|
||||
self::$db = null;
|
||||
return;
|
||||
}
|
||||
public static function getDbConnection(){
|
||||
return self::$db;
|
||||
}
|
||||
|
||||
|
||||
public static function getAllRecords(){
|
||||
$query = <<<SQL
|
||||
@@ -42,6 +46,7 @@ SELECT * FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
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
|
||||
@@ -50,12 +55,10 @@ SQL;
|
||||
// - 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 ";
|
||||
$query = "SELECT *, `cwsvjudo`.`machs_records`.`id` as `recordId` 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 ]
|
||||
];
|
||||
@@ -63,10 +66,10 @@ SQL;
|
||||
$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);
|
||||
$query.= "ORDER BY `cwsvjudo`.`machs_records`.`value` DESC;";
|
||||
return dbQuery(self::$db, $query, $params);
|
||||
}
|
||||
|
||||
/// @param $r record as associative array
|
||||
public static function arrayRecord2htmlDl($r){
|
||||
$retHtml = "<dl>";
|
||||
@@ -75,6 +78,46 @@ SQL;
|
||||
$retHtml.= "</dl>";
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
public static function arrayRecord2htmlCardAction($r, $u, $gid){
|
||||
// $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.= "<strong>Anschließend</strong> 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 id=\"submit\" style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord eintragen\">";
|
||||
}
|
||||
else{
|
||||
$retHtml.= "<input disabled=\"true\" id=\"submit\" 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>";
|
||||
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"){
|
||||
@@ -88,52 +131,80 @@ SQL;
|
||||
$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;
|
||||
}
|
||||
|
||||
// get an ageClasses records including its holders
|
||||
public static function getRecordsOfAgeClass($ageClass, $achievementGroup, $options=[]){
|
||||
$query = <<<SQL
|
||||
SELECT * FROM `cwsvjudo`.`machs_records`
|
||||
JOIN `cwsvjudo`.`wkParticipo_Users`
|
||||
ON `cwsvjudo`.`machs_records`.`userId` = cwsvjudo`.`wkParticipo_Users`.`id`
|
||||
WHERE `cwsvjudo`.`machs_records`.`ageClass` = :ageClass ";
|
||||
AND `cwsvjudo`.`machs_records`.`achievementGroupId` = :achievementGroupId;
|
||||
SQL;
|
||||
$params = [
|
||||
':ageClass'=>['value'=>$ageClass, 'data_type'=>PDO::PARAM_INT],
|
||||
':achievementGroupId'=>['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
|
||||
];
|
||||
$returns = query($this->getDbConnection(), $query, $params);
|
||||
return $records;
|
||||
}
|
||||
|
||||
// returns all age classes with records
|
||||
public static function getAgeClassesWithRecord($achievementGroupId=null){
|
||||
$params = null;
|
||||
$query="SELECT DISTINCT `ageClass` FROM `cwsvjudo`.`machs_records` ";
|
||||
if($achievementGroupId != null){
|
||||
$query.="WHERE `achievementGroupId` = :achievementGroupId ";
|
||||
$params=[];
|
||||
$params[':achievementGroupId'] = ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT];
|
||||
}
|
||||
$query.="ORDER BY `ageClass`";
|
||||
$ageClasses = dbQuery(self::$db, $query, $params);
|
||||
return $ageClasses;
|
||||
}
|
||||
|
||||
// load the achievement from the DB
|
||||
public function loadFromDb($id){
|
||||
$query = "SELECT * from `cwsvjudo`.`machs_records` WHERE `id`=:id;";
|
||||
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
|
||||
$achievements = query($this->getDbConnection(), $query, $params);
|
||||
$this->setFromAssocArray($achievements[0]);
|
||||
}
|
||||
// set the members of the record via an associative array (like the ones, that are returned by dbquery)
|
||||
public function setFromAssocArray($assocArray){
|
||||
$this->id = (int)$assocArray['id'];
|
||||
$this->achievementGroupId = (int)$assocArray['achievementGroupId'];
|
||||
$this->ageClass = (int)$assocArray['ageClass'];
|
||||
$this->userId = (int)$assocArray['userId'];
|
||||
$this->timestap = $assocArray['userId'];
|
||||
$this->value = $assocArray['value'];
|
||||
}
|
||||
|
||||
static public function htmlRanking($recordList){
|
||||
if(empty($recordList))
|
||||
return "";
|
||||
$html = "<table>";
|
||||
$html.= "<tr><th>Judoka</th><th>Rekord</th><th>Video</th></tr>";
|
||||
foreach($recordList as $record){
|
||||
$html.="<tr><td>".$record['vorname']." ".$record['name']."</td><td>".$record['value']."</td><td><a href=\"videos.d/records/".$record['recordId'].".webm\" >Video</a></td></tr>";
|
||||
}
|
||||
$html.= "</table>";
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/// Als String gegebene Altersklassen als Jahrgangsintervalle
|
||||
|
||||
Reference in New Issue
Block a user