pmelo working version
This commit is contained in:
@@ -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 "<form action=\"pmelo\" method=\"post\">" .
|
||||
"<input type= \"hidden\" name=\"pmelo[promote][promoteeId]\" value=\"" . $promoteeId . "\" />" .
|
||||
"<input type= \"hidden\" name=\"pmelo[promote][promoteeRank]\" value=\"" . $promoteeRank . "\" />" .
|
||||
"<input type= \"hidden\" name=\"pmelo[promote][degradeeId]\" value=\"" . $degradeeId . "\" />" .
|
||||
"<input type= \"hidden\" name=\"pmelo[promote][degradeeRank]\" value=\"" . $degradeeRank . "\">" .
|
||||
"<input class=\"btn\" type=\"submit\" value=\"^\">".
|
||||
"</form>";
|
||||
}
|
||||
|
||||
public $log = ["error" => [], "warning" => [], "info" => []];
|
||||
|
||||
Reference in New Issue
Block a user