diff --git a/homepage/machs/lib/machs/achievementGroup.php b/homepage/machs/lib/machs/achievementGroup.php index 315ce84..e156f52 100644 --- a/homepage/machs/lib/machs/achievementGroup.php +++ b/homepage/machs/lib/machs/achievementGroup.php @@ -108,8 +108,6 @@ SQL; $this->unlockingAchievementId = ($unlockingAchievementId == null ? null : (int)$unlockingAchievementId); $this->imageUrl = $imageUrl; $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 @@ -162,8 +160,6 @@ SQL; if(!$getAll) $params[':achievementGroupId'] = array('value'=>$this->getId(), 'data_type'=>PDO::PARAM_INT); $result = dbQuery($this->getDbConnection(), $query, $params); -# var_dump($query); -# var_dump($result); return $result; } diff --git a/homepage/participo/attendance.php b/homepage/participo/attendance.php index def7efb..5a31526 100644 --- a/homepage/participo/attendance.php +++ b/homepage/participo/attendance.php @@ -25,6 +25,80 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); $userData = getUserData($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(""); + foreach( $users as $u){ + echo(""); + } + echo("
IdNameVorname
".$u->id."".$u->familyName."".$u->givenName."
"); + } + } + /** * 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 $userId = null; //< user 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 $userId user of the attendance @@ -102,7 +185,7 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); $htmlTableString .= "
Gesamt zweites Halbjahr:
".$attendanceCountH2."
"; krsort($months); foreach($months as $month=>$days){ - $htmlTableString .= "
".Attendance::$NameOfMonth[$month-1]."
"; + $htmlTableString .= "
".Attendance::$NameOfMonth[$month]."
"; $htmlTableString .= "
".join(", ", $days)."
"; } $htmlTableString .= ""; @@ -111,16 +194,22 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); 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){ $groupedAttendances = []; foreach($attendances as $a){ - $year = $a->date->format("Y"); + $year =(int) $a->date->format("Y"); if(!array_key_exists($year, $groupedAttendances)) $groupedAttendances[$year] = []; - $month = $a->date->format("m"); + $month = (int) $a->date->format("m"); if(!array_key_exists($month, $groupedAttendances[$year])) $groupedAttendances[$year][$month] = []; - $day = $a->date->format("d"); + $day = (int) $a->date->format("d"); $groupedAttendances[$year][$month][]=$day; } return $groupedAttendances; @@ -184,6 +273,7 @@ foreach($usersKids as $k){ if($_SESSION['login']){ ?>
+ UserAttribute::InTraining]));?> errorInfo()); -// var_dump($aQueryString); -// var_dump($aBindArray); -// echo($pdoStatement.errorInfo()); } if($someOptions['dontFetch']){ $ret = NULL; @@ -91,9 +88,6 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false; ); } } -//var_dump($ret); -//var_dump($aQueryString); -//var_dump($aBindArray); return $ret; }