diff --git a/homepage/participo/pmelo.inc.php b/homepage/participo/pmelo.inc.php index b6304a3..9a491dc 100644 --- a/homepage/participo/pmelo.inc.php +++ b/homepage/participo/pmelo.inc.php @@ -17,7 +17,6 @@ class PmElo { function __construct() { - // $this->var_log($_SESSION, "session"); // starting/continuing a session session_start(); @@ -39,29 +38,11 @@ class PmElo // init members $this->trainees = self::getTrainees(); - $this->var_log( - array_map(function ($user) { - return $user->getFirstName(); - }, $this->trainees), - "trainees from db" - ); $this->rankings = $this->createRankings(); - $this->var_log( - array_map(function ($id) { - return $this->trainees[$id]->getFirstName(); - }, $this->rankings), - "current ranking" - ); $this->fighters = []; foreach ($_SESSION["pmelo"]["fighterIds"] as $id) { $this->fighters[$id] = $this->trainees[$id]; } - $this->var_log( - array_map(function ($user) { - return $user->getFirstName(); - }, $this->fighters), - "fighters" - ); // @todo Can be split. Some actions need the members to be already filled, some could be done earlier. // check for action in post data @@ -72,10 +53,10 @@ class PmElo $_SESSION["pmelo"]["fighterIds"] = $_POST["pmelo"]["fighterIds"]; - header("Location: ."); + header("Location: pmelo"); } - if (array_key_exist("promote", $_POST["pmelo"])) { + if (array_key_exists("promote", $_POST["pmelo"])) { $promote = $_POST["pmelo"]["promote"]; $this->promote( $promote["promoteeId"], @@ -84,10 +65,9 @@ class PmElo $promote["degradeeRank"] ); - header("Location: ."); + header("Location: pmelo"); } - // $this->var_log($_SESSION, "session"); } // save the updated ranking @@ -144,13 +124,6 @@ class PmElo { // load the last state of the ranking $loadedRanking = self::loadRankings(); - $this->var_log( - array_map(function ($id) { - $user = $this->trainees[$id]; - return $user->getFirstName(); - }, $loadedRanking), - "loaded ranking" - ); // check if the ranked trainees still are in training // - the ranking with @@ -179,13 +152,6 @@ class PmElo ? 1 : 0); }); - // $this->var_log( - // array_map( - // function($id){return $this->trainees[$id]->getStrBirthday()." ".$this->trainees[$id]->getFirstName();} - // , $newTraineesIds - // ) - // , "newTraineesBy B-Day" - // ); // now we do a mergesort (step) $updatedRanking = []; @@ -193,21 +159,15 @@ class PmElo $idxRanking = count($cleanRanking) - 1; // - while we can merge, we merge while ($idxRanking >= 0 && $idxNewTrainees >= 0) { - // $this->var_log( [$idxRanking.", ".$idxNewTrainees=>$updatedRanking] ); - // $this->var_log( - // [$this->trainees[$cleanRanking[$idxRanking]]->getStrBirthday(), $this->trainees[$newTraineesIds[$idxRanking]]->getStrBirthday()] - // ); if ( $this->trainees[$cleanRanking[$idxRanking]]->getDateOfBirth() > $this->trainees[ $newTraineesIds[$idxNewTrainees] ]->getDateOfBirth() ) { - // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "merge ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); $idxRanking -= 1; } else { - // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "merge trainees insert" ); array_unshift( $updatedRanking, $newTraineesIds[$idxNewTrainees] @@ -215,17 +175,11 @@ class PmElo $idxNewTrainees -= 1; } } - // $this->var_log( - // ["idxR ".$idxRanking." idxNT ".$idxNewTrainees=>[$cleanRanking, $newTraineesIds]] - // , "after merge" - // ); while ($idxRanking >= 0) { - // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "rest ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); $idxRanking -= 1; } while ($idxNewTrainees >= 0) { - // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "rest newTrainees insert" ); array_unshift($updatedRanking, $newTraineesIds[$idxNewTrainees]); $idxNewTrainees -= 1; } @@ -259,20 +213,28 @@ class PmElo $this->rankings[$promoteeRank] = $degradeeId; $this->rankings[$degradeeRank] = $promoteeId; - $this->saveRankings(); + $this->saveRankings($this->rankings); } } } // save the updated ranking + $this->saveRankings($this->rankings); } // promotion means switching the position with another user // id-s would already be sufficient, rank is just for controlling - function htmlPromoteButton( + public static function htmlPromoteButton( int $promoteeId, int $promoteeRank, int $degradeeId, int $degradeeRank ) { + return "
" . + "" . + "" . + "" . + "" . + "". + "
"; } public $log = ["error" => [], "warning" => [], "info" => []]; diff --git a/homepage/participo/pmelo.php b/homepage/participo/pmelo.php index da60dfb..caf4e6e 100644 --- a/homepage/participo/pmelo.php +++ b/homepage/participo/pmelo.php @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ - + @@ -32,7 +32,7 @@ cwsvJudoApps - + @@ -43,11 +43,16 @@
@@ -59,46 +64,57 @@ PlatzNameAufstieg - fighters)){ - foreach($pmelo->rankings as $rank=>$id){ - if(array_key_exists($id, $pmelo->fighters)){ - $fighter = $pmelo->fighters[$id]; - // echo("".$rank."".$fighter->getFirstName()."".PHP_EOL); - echo("".$rank."".$fighter->getFirstName()." ".$fighter->getName()."^".PHP_EOL); - } - } -} - ?> + fighters)) { + // remember the predecessor for the promoting form + $lastOne = null; + foreach ($pmelo->rankings as $rank => $id) { + if (array_key_exists($id, $pmelo->fighters)) { + $fighter = $pmelo->fighters[$id]; + echo "" . + "" . + $rank . + "" . + "" . + $fighter->getFirstName() . + " " . + $fighter->getName() . + "" . + "" . + (!is_null($lastOne) + ? $pmelo->htmlPromoteButton( + $fighter->getId(), + $rank, + $lastOne["id"], + $lastOne["rank"] + ) + : "") . + "" . + "" . + PHP_EOL; + $lastOne = ["id" => $fighter->getId(), "rank" => $rank]; + } + } + } ?>