Added attendanceType, participoUser as php class
This commit is contained in:
@@ -108,8 +108,6 @@ SQL;
|
|||||||
$this->unlockingAchievementId = ($unlockingAchievementId == null ? null : (int)$unlockingAchievementId);
|
$this->unlockingAchievementId = ($unlockingAchievementId == null ? null : (int)$unlockingAchievementId);
|
||||||
$this->imageUrl = $imageUrl;
|
$this->imageUrl = $imageUrl;
|
||||||
$this->canHaveRecords = (bool)$canHaveRecords;
|
$this->canHaveRecords = (bool)$canHaveRecords;
|
||||||
# echo("bool(".$canHaveRecords.")=".$this->canHaveRecords."\n");
|
|
||||||
# var_dump($canHaveRecords, $this->canHaveRecords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the next achievement, the user has to accomplish in that group
|
/// get the next achievement, the user has to accomplish in that group
|
||||||
@@ -162,8 +160,6 @@ SQL;
|
|||||||
if(!$getAll)
|
if(!$getAll)
|
||||||
$params[':achievementGroupId'] = array('value'=>$this->getId(), 'data_type'=>PDO::PARAM_INT);
|
$params[':achievementGroupId'] = array('value'=>$this->getId(), 'data_type'=>PDO::PARAM_INT);
|
||||||
$result = dbQuery($this->getDbConnection(), $query, $params);
|
$result = dbQuery($this->getDbConnection(), $query, $params);
|
||||||
# var_dump($query);
|
|
||||||
# var_dump($result);
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,80 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
|||||||
$userData = getUserData($dbConnection, $_SESSION['user']['userId']);
|
$userData = getUserData($dbConnection, $_SESSION['user']['userId']);
|
||||||
$usersKids = getUsersKids($dbConnection, $_SESSION['user']['userId']);
|
$usersKids = getUsersKids($dbConnection, $_SESSION['user']['userId']);
|
||||||
|
|
||||||
|
abstract class AttendanceType {
|
||||||
|
const __default = null;
|
||||||
|
|
||||||
|
const Training = 1;
|
||||||
|
const Excused = 2;
|
||||||
|
const Ill = 3;
|
||||||
|
const SpecialTraining = 4;
|
||||||
|
const Competition = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class UserAttribute {
|
||||||
|
const __default = null;
|
||||||
|
|
||||||
|
const IsAdmin = 1;
|
||||||
|
const WantsNewsLetter = 2;
|
||||||
|
const Passive = 3;
|
||||||
|
const InTraining = 4;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Datastructure and interface for an user
|
||||||
|
*/
|
||||||
|
class User{
|
||||||
|
private $id = null;
|
||||||
|
private $familyName = null;
|
||||||
|
private $givenName = null;
|
||||||
|
|
||||||
|
private $attributes = null;
|
||||||
|
|
||||||
|
function __construct($id, $familyName, $givenName){
|
||||||
|
$this->id = (int)$id;
|
||||||
|
$this->familyName = $familyName;
|
||||||
|
$this->givenName = $givenName;
|
||||||
|
}
|
||||||
|
static function fromArray($member){
|
||||||
|
$id = $member['id'];
|
||||||
|
$familyName = $member['familyName'];
|
||||||
|
$givenName = $member['givenName'];
|
||||||
|
return new User($id, $familyName, $givenName);
|
||||||
|
}
|
||||||
|
static function getUsers($db, $options = []){
|
||||||
|
$attributeId = $options["attributeId"] ?? null;
|
||||||
|
$params = [];
|
||||||
|
$query = "SELECT ".
|
||||||
|
"`cwsvjudo`.`wkParticipo_Users`.`id` AS `id`".
|
||||||
|
", `cwsvjudo`.`wkParticipo_Users`.`vorname` AS `givenName`".
|
||||||
|
", `cwsvjudo`.`wkParticipo_Users`.`name` AS `familyName`".
|
||||||
|
", `cwsvjudo`.`wkParticipo_userAttributes`.`name` AS `attributeName`".
|
||||||
|
"FROM `cwsvjudo`.`wkParticipo_Users` ".
|
||||||
|
"JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes` ".
|
||||||
|
"ON `cwsvjudo`.`wkParticipo_Users`.`id` = `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`".
|
||||||
|
"JOIN `cwsvjudo`.`wkParticipo_userAttributes` ".
|
||||||
|
"ON `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` = `cwsvjudo`.`wkParticipo_userAttributes`.`id`";
|
||||||
|
if($attributeId != null){
|
||||||
|
$query .= " WHERE `cwsvjudo`.`wkParticipo_userAttributes`.`id` = :attributeId";
|
||||||
|
$params['attributeId'] = ['value'=>$attributeId, 'data_type'=>PDO::PARAM_INT];
|
||||||
|
}
|
||||||
|
$query .= ";";
|
||||||
|
$response = dbQuery($db, $query, $params);
|
||||||
|
|
||||||
|
$users = [];
|
||||||
|
foreach( $response as $r){
|
||||||
|
$users[] = User::fromArray($r);
|
||||||
|
}
|
||||||
|
return $users;
|
||||||
|
}
|
||||||
|
static function htmlTable($users){
|
||||||
|
echo("<table><tr><th>Id<th>Name</th><th>Vorname</th></tr>");
|
||||||
|
foreach( $users as $u){
|
||||||
|
echo("<tr><td>".$u->id."</td><td>".$u->familyName."</td><td>".$u->givenName."</td></tr>");
|
||||||
|
}
|
||||||
|
echo("</table>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Datastructure and interface for attendances
|
* Datastructure and interface for attendances
|
||||||
*/
|
*/
|
||||||
@@ -32,9 +106,18 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
|||||||
private $id = null; //< id in the db
|
private $id = null; //< id in the db
|
||||||
private $userId = null; //< user of the attendance
|
private $userId = null; //< user of the attendance
|
||||||
private $date = null; //< date of the attendance
|
private $date = null; //< date of the attendance
|
||||||
static private $NameOfMonth =["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
|
private $type = null; //< type of attendance
|
||||||
|
|
||||||
|
static private $Types = [
|
||||||
|
AttendanceType::Training => "Training"
|
||||||
|
, AttendanceType::Excused => "Entschuldigt"
|
||||||
|
, AttendanceType::Ill => "Krank"
|
||||||
|
, AttendanceType::SpecialTraining => "SonderTraining"
|
||||||
|
, AttendanceType::Competition => "Wettkampf"
|
||||||
|
];
|
||||||
|
static private $NameOfMonth = [1=>"Januar", 2=>"Februar", 3=>"März", 4=>"April", 4=>"Mai", 6=>"Juni", 7=>"Juli", 8=>"August", 9=>"September", 10=>"Oktober", 11=>"November", 12=>"Dezember"];
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* constructor
|
||||||
*
|
*
|
||||||
* @param string/int $id id in the db
|
* @param string/int $id id in the db
|
||||||
* @param string/int $userId user of the attendance
|
* @param string/int $userId user of the attendance
|
||||||
@@ -102,7 +185,7 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
|||||||
$htmlTableString .= "<dt>Gesamt zweites Halbjahr:</dt><dd>".$attendanceCountH2."</dd>";
|
$htmlTableString .= "<dt>Gesamt zweites Halbjahr:</dt><dd>".$attendanceCountH2."</dd>";
|
||||||
krsort($months);
|
krsort($months);
|
||||||
foreach($months as $month=>$days){
|
foreach($months as $month=>$days){
|
||||||
$htmlTableString .= "<dt>".Attendance::$NameOfMonth[$month-1]."</dt>";
|
$htmlTableString .= "<dt>".Attendance::$NameOfMonth[$month]."</dt>";
|
||||||
$htmlTableString .= "<dd>".join(", ", $days)."</dd>";
|
$htmlTableString .= "<dd>".join(", ", $days)."</dd>";
|
||||||
}
|
}
|
||||||
$htmlTableString .= "</dl></li>";
|
$htmlTableString .= "</dl></li>";
|
||||||
@@ -111,16 +194,22 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
|||||||
|
|
||||||
return $htmlTableString;
|
return $htmlTableString;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* group the attendances by year and month.
|
||||||
|
*
|
||||||
|
* @param list $attendances list of attendances
|
||||||
|
* @return array[int][int](list of int) array with a list of days for every month in every year
|
||||||
|
*/
|
||||||
static function groupAttendances($attendances){
|
static function groupAttendances($attendances){
|
||||||
$groupedAttendances = [];
|
$groupedAttendances = [];
|
||||||
foreach($attendances as $a){
|
foreach($attendances as $a){
|
||||||
$year = $a->date->format("Y");
|
$year =(int) $a->date->format("Y");
|
||||||
if(!array_key_exists($year, $groupedAttendances))
|
if(!array_key_exists($year, $groupedAttendances))
|
||||||
$groupedAttendances[$year] = [];
|
$groupedAttendances[$year] = [];
|
||||||
$month = $a->date->format("m");
|
$month = (int) $a->date->format("m");
|
||||||
if(!array_key_exists($month, $groupedAttendances[$year]))
|
if(!array_key_exists($month, $groupedAttendances[$year]))
|
||||||
$groupedAttendances[$year][$month] = [];
|
$groupedAttendances[$year][$month] = [];
|
||||||
$day = $a->date->format("d");
|
$day = (int) $a->date->format("d");
|
||||||
$groupedAttendances[$year][$month][]=$day;
|
$groupedAttendances[$year][$month][]=$day;
|
||||||
}
|
}
|
||||||
return $groupedAttendances;
|
return $groupedAttendances;
|
||||||
@@ -184,6 +273,7 @@ foreach($usersKids as $k){
|
|||||||
if($_SESSION['login']){
|
if($_SESSION['login']){
|
||||||
?>
|
?>
|
||||||
<main>
|
<main>
|
||||||
|
<?php User::htmlTable( User::getUsers($dbConnection, ['attributeId' => UserAttribute::InTraining]));?>
|
||||||
<?php // show own ...
|
<?php // show own ...
|
||||||
$ownAttendances = Attendance::getUsersAttendance($dbConnection, $_SESSION['user']['userId']);
|
$ownAttendances = Attendance::getUsersAttendance($dbConnection, $_SESSION['user']['userId']);
|
||||||
if (!empty($ownAttendances)){
|
if (!empty($ownAttendances)){
|
||||||
|
|||||||
@@ -64,9 +64,6 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
|||||||
if(!$pdoResult){
|
if(!$pdoResult){
|
||||||
echo("Error during dbQuery!\n");
|
echo("Error during dbQuery!\n");
|
||||||
echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo());
|
echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo());
|
||||||
// var_dump($aQueryString);
|
|
||||||
// var_dump($aBindArray);
|
|
||||||
// echo($pdoStatement.errorInfo());
|
|
||||||
}
|
}
|
||||||
if($someOptions['dontFetch']){
|
if($someOptions['dontFetch']){
|
||||||
$ret = NULL;
|
$ret = NULL;
|
||||||
@@ -91,9 +88,6 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//var_dump($ret);
|
|
||||||
//var_dump($aQueryString);
|
|
||||||
//var_dump($aBindArray);
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user