"Training",
AttendanceType::Excused => "Entschuldigt",
AttendanceType::Ill => "Krank",
AttendanceType::SpecialTraining => "SonderTraining",
AttendanceType::Competition => "Wettkampf",
];
private static $NameOfMonth = [
1 => "Januar",
2 => "Februar",
3 => "März",
4 => "April",
5 => "Mai",
6 => "Juni",
7 => "Juli",
8 => "August",
9 => "September",
10 => "Oktober",
11 => "November",
12 => "Dezember",
];
/**
* constructor
*
* @param string/int $id id in the db
* @param string/int $userId user of the attendance
* @param string $date date of the attendance
*/
public function __construct($id, $userId, $date)
{
$this->id = (int) $id;
$this->userId = (int) $userId;
$this->date = DateTime::createFromFormat("Y-m-d", $date);
}
/**
* create an Attendance from an assoziative array
*
* @param array $member
* @return Attendance
*/
public static function constructFromArray($member)
{
return new Attendance(
$member["id"],
$member["userId"],
$member["date"],
);
}
/**
* request a users attendances from the database
*
* @param int/string $userId
* @return array with attendances
*/
public static function getUsersAttendance($userId)
{
$userId = (int) $userId;
$query =
"SELECT `id`, `date` FROM `cwsvjudo_main`.`anwesenheit` WHERE `userId` = :userId";
$response = dbConnector::query($query, [
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
]);
$attendances = [];
foreach ($response as $r) {
$attendances[] = new Attendance($r["id"], $userId, $r["date"]);
}
return $attendances;
}
/**
* html table with users attendances
*
* @param int $userId
* @return string with html code of the attendance table
*/
public static function userAttendanceHtmlTable(int $userId): string
{
$htmlTableString = "";
$htmlTableString .= "
";
$userAttendances = Attendance::groupAttendances(
Attendance::getUsersAttendance($userId),
);
krsort($userAttendances);
foreach ($userAttendances as $year => $months) {
$htmlTableString .= "{$year}";
// Counting the attendances per half year
$attendanceCountH1 = 0;
$attendanceCountH2 = 0;
foreach ($months as $month => $days) {
if (1 <= $month and $month <= 6) {
$attendanceCountH1 += count($days);
}
if (7 <= $month and $month <= 12) {
$attendanceCountH2 += count($days);
}
}
$htmlTableString .= "Gesamt erstes Halbjahr: {$attendanceCountH1} ";
$htmlTableString .= "Gesamt zweites Halbjahr: {$attendanceCountH2} ";
krsort($months);
foreach ($months as $month => $days) {
$htmlTableString .=
"" . Attendance::$NameOfMonth[$month] . " ";
$htmlTableString .= "" . join(", ", $days) . " ";
}
$htmlTableString .= " ";
}
$htmlTableString .= " ";
return $htmlTableString;
}
/**
* group the attendances by year and month.
*
* @param array $attendances list of attendances
* @return array (list of int) array with a list of days for every month in every year
*/
public static function groupAttendances(array $attendances): array
{
$groupedAttendances = [];
foreach ($attendances as $a) {
$year = (int) $a->date->format("Y");
if (!array_key_exists($year, $groupedAttendances)) {
$groupedAttendances[$year] = [];
}
$month = (int) $a->date->format("m");
if (!array_key_exists($month, $groupedAttendances[$year])) {
$groupedAttendances[$year][$month] = [];
}
$day = (int) $a->date->format("d");
$groupedAttendances[$year][$month][] = $day;
}
return $groupedAttendances;
}
}
?>
participo
Eigene Anwesenheiten' .
Attendance::userAttendanceHtmlTable($userData["id"]);
require_once "./lib/participoLib/participo.php";
} // ... and kids attendances
if (!empty($usersKids)) {
echo "Anwesenheit der Kinder ";
foreach ($usersKids as $k) {
if ($userData["id"] == $k["kidId"]) {
continue;
}
echo '' .
$k["vorname"] .
" " .
$k["name"] .
" " .
Attendance::userAttendanceHtmlTable($k["kidId"]);
}
}
?>