'
+ ;
+ }
+
public function getHtmlDescriptiveAgeClasses()
{
$retList = [];
@@ -128,121 +150,121 @@ class Shiai
return implode(', ', $retList);
}
-/** convert a list of age class formatted strings into a list of intervals of years
- *
- * @param string $akListString
- * @param int $year
- * @return list[array(int,int)] list of tupels with lower/upper bound in date year of the age classes
- */
-private static function akListString2jgArray(string $akListString, int $year = null)
-{
- $year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
- $ret = [];
- foreach (explode(' ', $akListString) as $ak) {
- $ret[$ak] = self::akString2jgIntervall($ak, $year);
+ /** convert a list of age class formatted strings into a list of intervals of years
+ *
+ * @param string $akListString
+ * @param int $year
+ * @return list[array(int,int)] list of tupels with lower/upper bound in date year of the age classes
+ */
+ private static function akListString2jgArray(string $akListString, int $year = null)
+ {
+ $year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
+ $ret = [];
+ foreach (explode(' ', $akListString) as $ak) {
+ $ret[$ak] = self::akString2jgIntervall($ak, $year);
+ }
+ return $ret;
}
- return $ret;
-}
-/** convert age class from formatted string to interval of years
- *
- * @param [string] $akString
- * @param [type] $year
- * @return array(int,int) [x,y] with x the lower bound and y the upper bound of the age class in years. Both bounds are still included in the interval.
- */
-private static function akString2jgIntervall(string $akString, int $year /*= null*/)
-{
- // input sanitation
- $year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
+ /** convert age class from formatted string to interval of years
+ *
+ * @param [string] $akString
+ * @param [type] $year
+ * @return array(int,int) [x,y] with x the lower bound and y the upper bound of the age class in years. Both bounds are still included in the interval.
+ */
+ private static function akString2jgIntervall(string $akString, int $year /*= null*/)
+ {
+ // input sanitation
+ $year = filterPosInt($year) ?? filterPosInt((new DateTime)->format('Y'));
- $ret = [null, null];
+ $ret = [null, null];
- // Matching against the different age class formats
- // - ..Ux
- // - Jg.x-y
+ // Matching against the different age class formats
+ // - ..Ux
+ // - Jg.x-y
- // Case Ux
- $akUmatchString = '/(.*)U(.*)/';
+ // Case Ux
+ $akUmatchString = '/(.*)U(.*)/';
- $matches = [];
+ $matches = [];
- preg_match($akUmatchString, $akString, $matches);
- // The found match should cover the whole string. Otherwise it isn't applicable.
- if ($matches[0] == $akString) {
- // The x in Ux should be a positive integer.
- $ageLimit = filterPosInt($matches[2]);
- if ($ageLimit) {
- $ret[0] = $year - $ageLimit + 1;
- // lowering the lower bound according to the modifiers
- if ($matches[1] == '') {
- $ret[1] = $year - $ageLimit + 2;
- } elseif ($matches[1] == '-') {
- $ret[1] = $year - $ageLimit + 3;
- } elseif ($matches[1] == '--') {
- $ret[1] = $year - $ageLimit + 4;
- } elseif (in_array($matches[1], ['<=', '≤', '≤', '≤', '≤'])) {
- $ret[1] = $year;
+ preg_match($akUmatchString, $akString, $matches);
+ // The found match should cover the whole string. Otherwise it isn't applicable.
+ if ($matches[0] == $akString) {
+ // The x in Ux should be a positive integer.
+ $ageLimit = filterPosInt($matches[2]);
+ if ($ageLimit) {
+ $ret[0] = $year - $ageLimit + 1;
+ // lowering the lower bound according to the modifiers
+ if ($matches[1] == '') {
+ $ret[1] = $year - $ageLimit + 2;
+ } elseif ($matches[1] == '-') {
+ $ret[1] = $year - $ageLimit + 3;
+ } elseif ($matches[1] == '--') {
+ $ret[1] = $year - $ageLimit + 4;
+ } elseif (in_array($matches[1], ['<=', '≤', '≤', '≤', '≤'])) {
+ $ret[1] = $year;
+ }
+ return $ret;
}
+ }
+
+ // Case Jg.x-y
+ $akUmatchString = "/Jg\.(.*)\-{1,2}(.*)/";
+
+ $matches = [];
+
+ preg_match($akUmatchString, $akString, $matches);
+ // The found match should cover the whole string. Otherwise it isn't applicable.
+
+ if ($matches[0] == $akString) {
+ $ret[0] = filterPosInt($matches[1]);
+ $ret[1] = filterPosInt($matches[2]);
+
return $ret;
}
- }
-
- // Case Jg.x-y
- $akUmatchString = "/Jg\.(.*)\-(.*)/";
-
- $matches = [];
-
- preg_match($akUmatchString, $akString, $matches);
- // The found match should cover the whole string. Otherwise it isn't applicable.
-
- if ($matches[0] == $akString) {
- $ret[0] = filterPosInt($matches[1]);
- $ret[1] = filterPosInt($matches[2]);
return $ret;
}
- return $ret;
-}
-
-/** grouping users kids by ageGroups
- *
- * @return array(ageGroup => list(users in ageGroup))
- */
-public function ageGroups()
-{
- $kids = participo::getKids();
- return self::ageClassGrouping($this->ageclasses, $kids);
-}
-
-/** grouping users by given age class
- *
- * @param array $ageClassList as array string representation of age class => [lower year bound, upper year bound]
- * @param array $starterList list of starter (User)
- * @return array of string representation of age class => array of user in this class
- */
-private static function ageClassGrouping(array $ageClassList, array $starterList)
-{
- $grouping = [];
- foreach ($ageClassList as $ageClass => $yearBoundaries) {
- $grouping[$ageClass] = [];
+ /** grouping users kids by ageGroups
+ *
+ * @return array(ageGroup => list(users in ageGroup))
+ */
+ public function ageGroups()
+ {
+ $kids = participo::getKids();
+ return self::ageClassGrouping($this->ageclasses, $kids);
}
- $grouping[null] = [];
- foreach ($starterList as $starter) {
- $startersAgeClass = $starter->yearOfBirth() ? self::getAgeClassFromYear($starter->yearOfBirth(), $ageClassList) : null;
- array_push($grouping[$startersAgeClass], $starter);
- }
- return $grouping;
-}
-
-private static function getAgeClassFromYear(int $year, array $ageClassList)
-{
- foreach ($ageClassList as $ageClass => $yearBoundaries) {
- if (($yearBoundaries[0] <= $year) && ($year <= $yearBoundaries[1])) {
- return $ageClass;
+ /** grouping users by given age class
+ *
+ * @param array $ageClassList as array string representation of age class => [lower year bound, upper year bound]
+ * @param array $starterList list of starter (User)
+ * @return array of string representation of age class => array of userId=>user in this class
+ */
+ private static function ageClassGrouping(array $ageClassList, array $starterList)
+ {
+ $grouping = [];
+ foreach ($ageClassList as $ageClass => $yearBoundaries) {
+ $grouping[$ageClass] = [];
}
+ $grouping[null] = [];
+
+ foreach ($starterList as $starter) {
+ $startersAgeClass = $starter->yearOfBirth() ? self::getAgeClassFromYear($starter->yearOfBirth(), $ageClassList) : null;
+ $grouping[$startersAgeClass][$starter->getId()] = $starter;
+ }
+ return $grouping;
+ }
+
+ private static function getAgeClassFromYear(int $year, array $ageClassList)
+ {
+ foreach ($ageClassList as $ageClass => $yearBoundaries) {
+ if (($yearBoundaries[0] <= $year) && ($year <= $yearBoundaries[1])) {
+ return $ageClass;
+ }
+ }
+ return null;
}
- return null;
-}
} // end class shiai