id = (int)$id; // $this->familyName = $familyName; // $this->givenName = $givenName; // } // public static function fromArray($member) // { // $id = $member['id']; // $familyName = $member['familyName']; // $givenName = $member['givenName']; // return new User($id, $familyName, $givenName); // } // public 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::fromDbArray($r); // } // return $users; // } // public static function htmlTable($users) // { // echo(''); // foreach ($users as $u) { // echo(''); // } // echo('
IdNameVorname
' . $u->id . '' . $u->familyName . '' . $u->givenName . '
'); // } // } /** * Datastructure and interface for attendances */ class Attendance { private $id = null; //< id in the db private $userId = null; //< user of the attendance private $date = null; //< date of the attendance private $type = null; //< type of attendance private static $Types = [ AttendanceType::Training => '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', 4 => '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 PDO $db * @param int/string $userId * @return array with attendances */ public static function getUsersAttendance($db, $userId) { $userId = (int)$userId; $query = 'SELECT `id`, `date` FROM `cwsvjudo`.`anwesenheit` WHERE `userId` = :userId'; $response = dbQuery($db, $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 PDO $db * @param string/int $userId * @return string with html code of the attendance table */ public static function userAttendanceHtmlTable($db, $userId) { $htmlTableString = ''; $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 */ public static function groupAttendances($attendances) { $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
UserAttribute::InTraining]));?> Eigene Anwesenheiten' . Attendance::userAttendanceHtmlTable(dbConnector::getDbConnection(), $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(dbConnector::getDbConnection(), $k['kidId']) ); } } ?>