libpairtwo/dist/template.php

145 lines
4.3 KiB
PHP
Raw Permalink Normal View History

2019-09-30 20:43:07 +02:00
<?php
// EDIT ME!
$pairingfile = 'your pairing-file.swar';
2019-12-22 18:15:25 +01:00
$fileformat = 'Swar-4'; // Possible values: Pairtwo-5, Pairtwo-6, Swar-4
2019-09-30 20:43:07 +02:00
?>
2019-09-28 00:07:17 +02:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
2019-09-28 00:52:43 +02:00
<title>My tournament</title>
2019-09-28 00:07:17 +02:00
<meta name="description" content="Libpairtwo">
2019-09-28 00:52:43 +02:00
<meta name="author" content="The chessclub">
2019-09-28 00:07:17 +02:00
<link rel="stylesheet" href="css/styles.css">
2019-09-28 00:07:17 +02:00
</head>
<body>
<?php
use JeroenED\Libpairtwo\IOFactory;
require_once 'vendor/autoload.php';
if (!file_exists($pairingfile)) {
2020-11-22 17:13:13 +01:00
trigger_error(
'Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again',
E_USER_ERROR
);
}
2019-06-19 22:01:50 +02:00
$reader = IOFactory::createReader($fileformat);
$reader->read($pairingfile);
// From here on you can start. Please use the examples on https://github.com/jeroened/libpairtwo/wiki
// You can also use the doc/api folder to get all possible methods and fields
// Below is an example of what can be used. Feel free to modify this.
2019-11-17 17:46:16 +01:00
echo '<h1>' . $reader->Tournament->Name . '</h1>' . PHP_EOL;
foreach ($reader->Tournament->Rounds as $round) {
echo '<h2>Round ' . ($round->RoundNo + 1) . ': ' . $round->Date->format('m/d/Y') . '</h2>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
echo '<table>' . PHP_EOL;
echo '<thead>' . PHP_EOL;
2019-09-28 21:21:19 +02:00
echo '<tr><th></th><th>White</th><th>Black</th><th>Result</th></tr>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
echo '</thead>' . PHP_EOL;
echo '<tbody>' . PHP_EOL;
2019-11-17 17:46:16 +01:00
foreach ($round->GamesByBoard as $game) {
2019-09-28 00:07:17 +02:00
echo '<tr>' . PHP_EOL;
2019-11-17 17:46:16 +01:00
echo '<td>' . ($game->Board + 1) . '</td>' . PHP_EOL;
2020-11-22 17:13:13 +01:00
echo '<td>' .
$game->White->Player->Name .
' (' .
$game->White->Player->getElo($reader->Tournament->PriorityElo) .
')</td>' .
PHP_EOL;
echo '<td>' .
$game->Black->Player->Name .
' (' .
$game->Black->Player->getElo($reader->Tournament->PriorityElo) .
')</td>' .
PHP_EOL;
2019-11-17 17:46:16 +01:00
echo '<td>' . $game->Result->getValue() . '</td>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
echo '</tr>' . PHP_EOL;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
echo '<p><strong>Bye:</strong> ';
$bye = [];
2019-11-17 17:46:16 +01:00
foreach ($round->Bye as $pairing) {
$bye[] = $pairing->Player->Name;
2019-09-28 00:07:17 +02:00
}
2019-09-30 20:43:07 +02:00
echo implode('; ', $bye);
2019-09-28 00:07:17 +02:00
echo '</p>' . PHP_EOL;
2019-09-30 20:43:07 +02:00
2019-09-28 10:42:05 +02:00
echo '<p><strong>Absent:</strong> ';
2019-09-28 00:07:17 +02:00
$bye = [];
2019-11-17 17:46:16 +01:00
foreach ($round->Absent as $pairing) {
$bye[] = $pairing->Player->Name;
2019-09-28 00:07:17 +02:00
}
echo implode('; ', $bye);
echo '</p>' . PHP_EOL;
}
echo '<h2>Global Rankings</h2>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
echo '<table>' . PHP_EOL;
echo '<thead>' . PHP_EOL;
echo '<tr><th> </th><th>Name (elo)</th><th>Category</th>' . PHP_EOL;
foreach ($reader->Tournament->Tiebreaks as $tiebreak) {
2019-09-28 00:07:17 +02:00
echo '<th>' . $tiebreak->getValue() . '</th>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL;
echo '</thead>' . PHP_EOL;
echo '<tbody>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
$rank = 1;
2019-11-17 17:46:16 +01:00
foreach ($reader->Tournament->Ranking as $player) {
2019-09-28 00:07:17 +02:00
echo '<tr>' . PHP_EOL;
echo '<td>' . $rank . '</td>' . PHP_EOL;
echo '<td>' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . $player->Category . '</td>' . PHP_EOL;
2019-11-17 17:46:16 +01:00
echo '<td>' . implode('</td><td>', $player->Tiebreaks) . '</td>' . PHP_EOL;
2019-09-28 00:07:17 +02:00
echo '</tr>' . PHP_EOL;
$rank++;
}
2019-09-28 00:07:17 +02:00
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
?>
<?php
echo '<h2>Rankings per Category</h2>' . PHP_EOL;
2020-11-22 17:13:13 +01:00
foreach ($reader->Tournament->Categories as $category) {
echo '<table>' . PHP_EOL;
echo '<caption>' . $category . '</caption>';
echo '<thead>' . PHP_EOL;
echo '<tr><th> </th><th>Name (elo)</th>' . PHP_EOL;
foreach ($reader->Tournament->Tiebreaks as $tiebreak) {
echo '<th>' . $tiebreak->getValue() . '</th>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL;
echo '</thead>' . PHP_EOL;
echo '<tbody>' . PHP_EOL;
$rank = 1;
foreach ($reader->Tournament->RankingForCategory($category) as $player) {
echo '<tr>' . PHP_EOL;
echo '<td>' . $rank . '</td>' . PHP_EOL;
echo '<td>' . $player->Name . ' (' . $player->getElo($reader->Tournament->PriorityElo) . ')</td>' . PHP_EOL;
echo '<td>' . implode('</td><td>', $player->Tiebreaks) . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
$rank++;
}
echo '</tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
}
2019-09-28 00:07:17 +02:00
?>
2020-11-22 17:13:13 +01:00
<script src="js/scripts.js"></script>
2019-09-28 00:07:17 +02:00
</body>
</html>