WIP: bring participo back - consistent use of bootstrap - formatting -
phpstan level 0 error free - fixes for kyu subpage - move mams into participo framework - remove legacy `lib/db.php` usage - add attributer admin function - add newsposter - fixing apiKey creation
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
<?php
|
||||
setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
|
||||
|
||||
// Configs
|
||||
require_once "config/participo.php";
|
||||
require_once $config["basePath"] . "/config/cwsvJudo.config.php";
|
||||
require_once "bootstrap.php";
|
||||
|
||||
// Libs
|
||||
require_once "participoLib/user.php";
|
||||
|
||||
participo::init($cwsvJudoConfig);
|
||||
participo::init($CONFIG["cwsvJudo"], $SECRETS["cwsvJudo"]);
|
||||
|
||||
$pmelo = new PmElo();
|
||||
|
||||
@@ -63,12 +58,11 @@ class PmElo
|
||||
$promote["promoteeId"],
|
||||
$promote["promoteeRank"],
|
||||
$promote["degradeeId"],
|
||||
$promote["degradeeRank"]
|
||||
$promote["degradeeRank"],
|
||||
);
|
||||
|
||||
header("Location: pmelo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// save the updated ranking
|
||||
@@ -81,18 +75,21 @@ class PmElo
|
||||
///
|
||||
|
||||
/** Echo the fighterInputForm */
|
||||
public function htmlFighterInputForm(){
|
||||
echo($this->getFighterInputForm($this->trainees));
|
||||
public function htmlFighterInputForm()
|
||||
{
|
||||
echo $this->getFighterInputForm($this->trainees);
|
||||
}
|
||||
|
||||
/** Echo the fighterTable */
|
||||
public function htmlFighterTable(){
|
||||
echo($this->getFighterTable($this->fighters, $this->rankings));
|
||||
public function htmlFighterTable()
|
||||
{
|
||||
echo $this->getFighterTable($this->fighters, $this->rankings);
|
||||
}
|
||||
|
||||
/** Echo logOutput */
|
||||
public function htmlLogOutput(){
|
||||
echo($this->getLogOutput($this->log));
|
||||
public function htmlLogOutput()
|
||||
{
|
||||
echo $this->getLogOutput($this->log);
|
||||
}
|
||||
|
||||
////
|
||||
@@ -100,11 +97,11 @@ class PmElo
|
||||
////
|
||||
|
||||
/** load all active trainees into a id=>User assoc array */
|
||||
static private function getTrainees()
|
||||
private static function getTrainees()
|
||||
{
|
||||
$traineeList = array_map(
|
||||
"User::fromDbArray",
|
||||
User::dbSelectWithAttribute(4)
|
||||
User::dbSelectWithAttribute(4),
|
||||
);
|
||||
$traineeAssocArray = [];
|
||||
foreach ($traineeList as $trainee) {
|
||||
@@ -114,13 +111,13 @@ class PmElo
|
||||
}
|
||||
|
||||
/** load ranking from json file */
|
||||
static private function loadRankings()
|
||||
private static function loadRankings()
|
||||
{
|
||||
return json_decode(file_get_contents(self::$pmeloJson));
|
||||
}
|
||||
|
||||
/** save a ranking to json file */
|
||||
static private function saveRankings(array $rankings)
|
||||
private static function saveRankings(array $rankings)
|
||||
{
|
||||
file_put_contents(self::$pmeloJson, json_encode($rankings));
|
||||
}
|
||||
@@ -130,7 +127,7 @@ class PmElo
|
||||
////
|
||||
|
||||
/** create the ranking for the current session
|
||||
*
|
||||
*
|
||||
* - load saved ranking from file
|
||||
* - remove old trainees
|
||||
* - add new trainees
|
||||
@@ -184,7 +181,7 @@ class PmElo
|
||||
} else {
|
||||
array_unshift(
|
||||
$updatedRanking,
|
||||
$newTraineesIds[$idxNewTrainees]
|
||||
$newTraineesIds[$idxNewTrainees],
|
||||
);
|
||||
$idxNewTrainees -= 1;
|
||||
}
|
||||
@@ -201,9 +198,9 @@ class PmElo
|
||||
}
|
||||
|
||||
/** promote a fighter
|
||||
*
|
||||
*
|
||||
* Promotion means two fighter switch places
|
||||
*
|
||||
*
|
||||
* $promoteeId (int>0) id to promote
|
||||
* $promopteeRank (int>0) current rank of the one to be promoted
|
||||
* $degradeeId (int>0) id to demote
|
||||
@@ -213,7 +210,7 @@ class PmElo
|
||||
int $promoteeId,
|
||||
int $promoteeRank,
|
||||
int $degradeeId,
|
||||
int $degradeeRank
|
||||
int $degradeeRank,
|
||||
) {
|
||||
// input sanitation
|
||||
filterId($promoteeId);
|
||||
@@ -247,141 +244,168 @@ class PmElo
|
||||
////
|
||||
|
||||
/** Assemble the Input form for the fighter selection
|
||||
*
|
||||
*
|
||||
* $trainees (array(participo::user)) list of trainees that can be selected for fighting
|
||||
*
|
||||
*
|
||||
* return fighterInputForm as html code
|
||||
*/
|
||||
static private function getFighterInputForm(array $trainees){
|
||||
private static function getFighterInputForm(array $trainees)
|
||||
{
|
||||
$style = [
|
||||
'classes'=>[
|
||||
'input-field' => "input-field col s12"
|
||||
]
|
||||
"classes" => [
|
||||
"input-field" => "input-field col s12",
|
||||
],
|
||||
];
|
||||
|
||||
$retHtml =
|
||||
'<form id="pmelo-form-fighters" action="pmelo" method="post">'
|
||||
// selects have to be wrapped into an .input-field, limitation of materializeCss
|
||||
.'<div class='.$style['classes']['input-field'].'>'
|
||||
.'<select name="pmelo[fighterIds][]" id="pmelo-form-fighters-select" multiple>'
|
||||
.'<option value="" disabled selected>Kämpfer auswählen</option>';
|
||||
'<form id="pmelo-form-fighters" action="pmelo" method="post">' .
|
||||
// selects have to be wrapped into an .input-field, limitation of materializeCss
|
||||
"<div class=" .
|
||||
$style["classes"]["input-field"] .
|
||||
">" .
|
||||
'<select name="pmelo[fighterIds][]" id="pmelo-form-fighters-select" multiple>' .
|
||||
'<option value="" disabled selected>Kämpfer auswählen</option>';
|
||||
foreach ($trainees as $trainee) {
|
||||
$retHtml .=
|
||||
'<option value="'.$trainee->getId().'">'.
|
||||
$trainee->getFirstname().' '.$trainee->getName().
|
||||
'</option>';
|
||||
'<option value="' .
|
||||
$trainee->getId() .
|
||||
'">' .
|
||||
$trainee->getFirstname() .
|
||||
" " .
|
||||
$trainee->getName() .
|
||||
"</option>";
|
||||
}
|
||||
$retHtml .=
|
||||
'</select>'.
|
||||
'<label for="pmelo-form-fighters-select">'.
|
||||
'Kämpfer auswählen'.
|
||||
'</label>'.
|
||||
'<input type="submit" value="Liste erstellen">'.
|
||||
'</div>'.
|
||||
'</form>';
|
||||
$retHtml .=
|
||||
"</select>" .
|
||||
'<label for="pmelo-form-fighters-select">' .
|
||||
"Kämpfer auswählen" .
|
||||
"</label>" .
|
||||
'<input type="submit" value="Liste erstellen">' .
|
||||
"</div>" .
|
||||
"</form>";
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
/** Assemble the ranking table of the fighters
|
||||
*
|
||||
*
|
||||
* $fighters (array(id=>participo::User)) list of fighters in the active round
|
||||
* $ranking (array(rank=>id)) ranking of the current selected fighters
|
||||
*
|
||||
*
|
||||
* return fighter ranking table as html code
|
||||
*/
|
||||
static private function getFighterTable(array $fighters, array $rankings){
|
||||
$retHtml =
|
||||
'<table>'.
|
||||
'<thead><tr><th>Platz</th><th>Name</th><th>Aufstieg</th></tr></thead>'.
|
||||
'<tbody>';
|
||||
private static function getFighterTable(array $fighters, array $rankings)
|
||||
{
|
||||
$retHtml =
|
||||
"<table>" .
|
||||
"<thead><tr><th>Platz</th><th>Name</th><th>Aufstieg</th></tr></thead>" .
|
||||
"<tbody>";
|
||||
if (!empty($fighters)) {
|
||||
// cache the predecessor in the ranking for the promoting form
|
||||
$lastOne = null;
|
||||
foreach ($rankings as $rank => $id) {
|
||||
if (array_key_exists($id, $fighters)) {
|
||||
$fighter = $fighters[$id];
|
||||
$retHtml .= '<tr>'.
|
||||
'<td>'.$rank.'</td>'.
|
||||
'<td>'.join(' ', [$fighter->getFirstName(), $fighter->getName()]).'</td>';
|
||||
if (!is_null($lastOne)){
|
||||
$retHtml .= '<td>'.self::getPromoteButton(
|
||||
$fighter->getId(),$rank,
|
||||
$lastOne["id"],$lastOne["rank"]
|
||||
).'</td>';
|
||||
$retHtml .=
|
||||
"<tr>" .
|
||||
"<td>" .
|
||||
$rank .
|
||||
"</td>" .
|
||||
"<td>" .
|
||||
join(" ", [
|
||||
$fighter->getFirstName(),
|
||||
$fighter->getName(),
|
||||
]) .
|
||||
"</td>";
|
||||
if (!is_null($lastOne)) {
|
||||
$retHtml .=
|
||||
"<td>" .
|
||||
self::getPromoteButton(
|
||||
$fighter->getId(),
|
||||
$rank,
|
||||
$lastOne["id"],
|
||||
$lastOne["rank"],
|
||||
) .
|
||||
"</td>";
|
||||
}
|
||||
$retHtml .= '</tr>';
|
||||
$retHtml .= "</tr>";
|
||||
$lastOne = ["id" => $fighter->getId(), "rank" => $rank];
|
||||
}
|
||||
}
|
||||
}
|
||||
$retHtml .=
|
||||
'</tbody>'.
|
||||
'</table>';
|
||||
|
||||
$retHtml .= "</tbody>" . "</table>";
|
||||
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
/** Assemble a Promote button
|
||||
*
|
||||
*
|
||||
* $promoteeId (int>0) id to promote
|
||||
* $promoteeRank (int>0) current rank of the promotee
|
||||
* $degradeeId (int>0) id to demote
|
||||
* $degradeeRank (int>0) rank of the to be demoted
|
||||
*/
|
||||
static private function getPromoteButton(
|
||||
private static function getPromoteButton(
|
||||
int $promoteeId,
|
||||
int $promoteeRank,
|
||||
int $degradeeId,
|
||||
int $degradeeRank
|
||||
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>";
|
||||
"<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>";
|
||||
}
|
||||
|
||||
/** Assemble the log Output
|
||||
*
|
||||
*
|
||||
* $log (array logLevel=>array(messages)) lists of log messages per logLevel
|
||||
*
|
||||
*
|
||||
* return logOutput as html code
|
||||
*/
|
||||
private static function getLogOutput(array $log){
|
||||
private static function getLogOutput(array $log)
|
||||
{
|
||||
$retHtml =
|
||||
'<ul class="collection with-header">'.
|
||||
'<li class="collection-header"><h3>Logs</h3></li>';
|
||||
'<ul class="collection with-header">' .
|
||||
'<li class="collection-header"><h3>Logs</h3></li>';
|
||||
foreach ($log as $logLevel => $messages) {
|
||||
if (!empty($messages)) {
|
||||
$retHtml .=
|
||||
'<li class="collection-item">'.
|
||||
'<ul class="collection with-header">'.
|
||||
'<li class="collection-header">'.$logLevel.'</li>';
|
||||
foreach ($messages as $message) {
|
||||
$retHtml .=
|
||||
'<li>'.$message.'</li>';
|
||||
}
|
||||
$retHtml .=
|
||||
'</ul>'.
|
||||
'</li>';
|
||||
'<li class="collection-item">' .
|
||||
'<ul class="collection with-header">' .
|
||||
'<li class="collection-header">' .
|
||||
$logLevel .
|
||||
"</li>";
|
||||
foreach ($messages as $message) {
|
||||
$retHtml .= "<li>" . $message . "</li>";
|
||||
}
|
||||
$retHtml .= "</ul>" . "</li>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
/** simple logger to a logging buffer */
|
||||
private function var_log(
|
||||
$variable,
|
||||
string $prefix = null,
|
||||
string $logChannel = "info"
|
||||
) {
|
||||
mixed $variable,
|
||||
?string $prefix = null,
|
||||
string $logChannel = "info",
|
||||
): void {
|
||||
if (!in_array($logChannel, ["info", "warning", "error"])) {
|
||||
$logChannel = "info";
|
||||
}
|
||||
$prefix = !empty($prefix) ? $prefix . ": " : "";
|
||||
$prefix = !empty($prefix) ? "{$prefix}: " : "";
|
||||
$this->log[$logChannel][] = $prefix . var_export($variable, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user