CLEANED UP DA CODE

This commit is contained in:
Jeroen De Meerleer 2020-11-22 17:13:13 +01:00
parent aac0322491
commit 400780ef54
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
18 changed files with 1992 additions and 1785 deletions

View File

@ -51,7 +51,9 @@
<option name="BINARY_OPERATION_WRAP" value="5" />
<option name="TERNARY_OPERATION_WRAP" value="5" />
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="MODIFIER_LIST_WRAP" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="5" />
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />

View File

@ -2,7 +2,10 @@
"name": "jeroened/libpairtwo",
"type": "library",
"description": "Export chess tournaments directly on the web",
"keywords": ["chess", "pairing"],
"keywords": [
"chess",
"pairing"
],
"license": "AGPL-3.0-or-later",
"authors": [
{

19
dist/template.php vendored
View File

@ -27,7 +27,10 @@ use JeroenED\Libpairtwo\IOFactory;
require_once 'vendor/autoload.php';
if (!file_exists($pairingfile)) {
trigger_error('Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again', E_USER_ERROR);
trigger_error(
'Your file is not set or doesn\'t exist! Edit the file: ' . __FILE__ . ' and try again',
E_USER_ERROR
);
}
$reader = IOFactory::createReader($fileformat);
@ -49,8 +52,18 @@ foreach ($reader->Tournament->Rounds as $round) {
foreach ($round->GamesByBoard as $game) {
echo '<tr>' . PHP_EOL;
echo '<td>' . ($game->Board + 1) . '</td>' . PHP_EOL;
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;
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;
echo '<td>' . $game->Result->getValue() . '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
}

View File

@ -6,11 +6,10 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns="http://www.w3.org/2000/svg"
width="134.01421mm"
height="89.507103mm"
viewBox="0 0 134.01421 89.507103"

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -6,11 +6,10 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns="http://www.w3.org/2000/svg"
width="134.01421mm"
height="89.507103mm"
viewBox="0 0 134.01421 89.507103"

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -1,53 +1,153 @@
<HTML>
<HEAD>
<style type="text/css">
body { font-size: 10pt; font-family: verdana;}
h1 {background-color: navy;color: #FDE0AA;font-size: 24pt;font-weight:bold;font-family:Arial;text-align:center;}
th {background-color: #408080; font-size: 20pt; text-align: center;}
.rh {background-color: #408080; font-size: 16pt; text-align: center;}
.vh {font-size: 10pt; text-align: center;}
.thr {font-size: 10pt; text-align: right}
.thl {font-size: 10pt; text-align: left}
.thc {font-size: 10pt; text-align: center}
.tdr {font-size: 8pt; text-align: right}
.tdl {font-size: 8pt; text-align: left}
.tdc {font-size: 8pt; text-align: center;}
.tdp {font-size: 10pt; font-weight:bold;text-align: center; background-color='yellow'}
.tde {font-size: 8pt; font-style:italic;text-align: right; background-color='#ceceff'}
table {font-size: 10pt; font-family: Arial}
a { text-decoration: none; color: blue;}
a:visited { text-decoration: none; color: blue;}
a:hover { text-decoration:none ; color: red;}
body {
font-size: 10pt;
font-family: verdana;
}
h1 {
background-color: navy;
color: #FDE0AA;
font-size: 24pt;
font-weight: bold;
font-family: Arial;
text-align: center;
}
th {
background-color: #408080;
font-size: 20pt;
text-align: center;
}
.rh {
background-color: #408080;
font-size: 16pt;
text-align: center;
}
.vh {
font-size: 10pt;
text-align: center;
}
.thr {
font-size: 10pt;
text-align: right
}
.thl {
font-size: 10pt;
text-align: left
}
.thc {
font-size: 10pt;
text-align: center
}
.tdr {
font-size: 8pt;
text-align: right
}
.tdl {
font-size: 8pt;
text-align: left
}
.tdc {
font-size: 8pt;
text-align: center;
}
.tdp {
font-size: 10pt;
font-weight: bold;
text-align: center;
background-color = 'yellow'
}
.tde {
font-size: 8pt;
font-style: italic;
text-align: right;
background-color = '#ceceff'
}
table {
font-size: 10pt;
font-family: Arial
}
a {
text-decoration: none;
color: blue;
}
a:visited {
text-decoration: none;
color: blue;
}
a:hover {
text-decoration: none;
color: red;
}
</style>
<TITLE>Libpairtwo Tournament</TITLE>
<META name='DESCRIPTION' content='Classement, Résultats, Appariement, Grille Américaine'>
<META name='AUTHOR' content='Georges Marchal'>
<META name='KEYWORDS' content='échecs,echecs,chess,jeux,game,belgique,belgium,forum'>
<META name='KEYWORDS' content='liège,liege,666,elo,classement,tournoi,interclub'>
<META name='KEYWORDS' content='pairtwo, kbsb,frbe,fefb,666'>
<META name='ROBOTS' content='INDEX,FOLLOW'>
<META content='Classement, R<EFBFBD>sultats, Appariement, Grille Am<41>ricaine' name='DESCRIPTION'>
<META content='Georges Marchal' name='AUTHOR'>
<META content='<27>checs,echecs,chess,jeux,game,belgique,belgium,forum' name='KEYWORDS'>
<META content='li<6C>ge,liege,666,elo,classement,tournoi,interclub' name='KEYWORDS'>
<META content='pairtwo, kbsb,frbe,fefb,666' name='KEYWORDS'>
<META content='INDEX,FOLLOW' name='ROBOTS'>
</HEAD>
<BODY>
<A name=Top></A>
<!-- TITRE GENERAL EN BLEU -->
<!-- ===================== -->
<TABLE width='90%' align='center' bgColor='#000080' border='0'>
<TR><TD><H1>Libpairtwo Tournament</H1></TD></TR></TABLE>
<TABLE align='center' bgColor='#000080' border='0' width='90%'>
<TR>
<TD><H1>Libpairtwo Tournament</H1></TD>
</TR>
</TABLE>
<!-- =============== -->
<!-- INFO DU TOURNOI -->
<!-- =============== --><br>
<table align='center' border='1''>
<tr><td align='center' valign='middle'><font size='+2'><b>313</b></font></td>
<td><TABLE border='1' align='center' style='font-size: 8pt; font-family: verdana;'>
<tr><td align='center' bgColor='#000090'><font color='white' size='-1'><b>(&copy;) FRBE 2005</b></font></td>
<td align='center' bgColor='#000090'><font color='white' size='-1'><b>PairTwo 6.13 (2015/08/10)</b></font></td></tr>
<tr><td><i> Org. : </i></td><td>Libpairtwo Organiser ,Libpairtwo Place ,2019</td></tr>
<tr><td><i>Arbit. : </i></td><td>Libpairtwo Organiser</td></tr>
<tr><td><i> Tempo : </i></td><td>40c/2h + 1h QPF</td></tr>
<tr><td><i>Tie Break</i></td><td>Pts,&nbsp;Mutual Result,&nbsp;Number of Victories,&nbsp;Number of game Black played,&nbsp;Bucholtz Cut 1,&nbsp;SonneBorn-Berger</td></tr>
<table align='center' border='1'
'>
<tr>
<td align='center' valign='middle'><font size='+2'><b>313</b></font></td>
<td>
<TABLE align='center' border='1' style='font-size: 8pt; font-family: verdana;'>
<tr>
<td align='center' bgColor='#000090'><font color='white' size='-1'><b>(&copy;) FRBE 2005</b></font></td>
<td align='center' bgColor='#000090'><font color='white' size='-1'><b>PairTwo 6.13
(2015/08/10)</b></font></td>
</tr>
<tr>
<td><i> Org. : </i></td>
<td>Libpairtwo Organiser ,Libpairtwo Place ,2019</td>
</tr>
<tr>
<td><i>Arbit. : </i></td>
<td>Libpairtwo Organiser</td>
</tr>
<tr>
<td><i> Tempo : </i></td>
<td>40c/2h + 1h QPF</td>
</tr>
<tr>
<td><i>Tie Break</i></td>
<td>Pts,&nbsp;Mutual Result,&nbsp;Number of Victories,&nbsp;Number of game Black played,&nbsp;Bucholtz
Cut 1,&nbsp;SonneBorn-Berger
</td>
</tr>
</TABLE>
</td>
<td align='center' valign='middle'><font size='+2'><b>F.R.B.E.</b></font></td>
@ -56,13 +156,16 @@ a:hover { text-decoration:none ; color: red;}
<!-- ================== -->
<!-- === REFERENCES === -->
<!-- ================== -->
<br><TABLE align='center' border='3' bgcolor='#ffffdd'>
<br>
<TABLE align='center' bgcolor='#ffffdd' border='3'>
<TR>
<TD class='vh'><A HREF='#Round1'>R1</A></TD>
<TD class='vh'><A HREF='#Round2'>R2</A></TD>
<TD class='vh'><A HREF='#Round3'>R3</A></TD>
</TR>
<TR><TD class='vh' colspan='3'><A HREF='#Americaine'>American Ranking</A></TD></TR>
<TR>
<TD class='vh' colspan='3'><A HREF='#Americaine'>American Ranking</A></TD>
</TR>
</TABLE>
<br>
<DIV ALIGN='CENTER'>
@ -70,25 +173,36 @@ a:hover { text-decoration:none ; color: red;}
<!-- =========================== -->
<!-- === DEBUT DU CLASSEMENT === -->
<!-- =========================== -->
<TR><TH>Ranking after round 3</TH></TR>
<TR><TD><PRE>
<TR>
<TH>Ranking after round 3</TH>
</TR>
<TR>
<TD><PRE>
<b><u>Tit Name Rati F/M Club Cou Pts Res Vic #Bla BC1 S B </u></b>
1<b> FM</b> <b>Libpairtwo Player 2 </b> (1802) M Liga Vlaams-Brabant (VSF) BEL <b> 3.0</b>/<i>3 </i> 0.0 0 0 0.0 0.00
2<b> *</b> <b>Libpairtwo Player 1 </b> (1801) M Liga Antwerpen (VSF) BEL <b> 1.5</b>/<i>3 </i> 0.0 0 0 0.0 0.00
3<b> IM</b> <b>Libpairtwo Player 3 </b> (1803) F Liga West Vlaanderen (VSF) BEL <b> 1.0</b>/<i>2 </i> 0.0 0 0 0.0 0.00
4<b> GM</b> <b>Libpairtwo Player 4 </b> (1804) F Liga Oost Vlaanderen (VSF) BEL <b> 0.5</b>/<i>2 </i> 0.0 0 0 0.0 0.00
<A href='#Top'>Top of Page</A>
</PRE></TD></TR>
<TR><TH class='rh'><A NAME='Round1' style='color: black'>Round 1 (01-01-2019)</A></TH></TR>
<TR><TD><PRE>
</PRE>
</TD>
</TR>
<TR>
<TH class='rh'><A NAME='Round1' style='color: black'>Round 1 (01-01-2019)</A></TH>
</TR>
<TR>
<TD><PRE>
1 Libpairtwo Player 2 ( 3) <b>1-0 </b>Libpairtwo Player 4 ( 1)
2 Libpairtwo Player 3 ( 2) <b>0-1 </b>Libpairtwo Player 1 ( 4)
</pre>
<A HREF="#Top">(Go to Top)</A>
</TD>
<TR><TH class='rh'><A NAME='Round2' style='color: black'>Round 2 (06-01-2019)</A></TH></TR>
<TR><TD><PRE>
<TR>
<TH class='rh'><A NAME='Round2' style='color: black'>Round 2 (06-01-2019)</A></TH>
</TR>
<TR>
<TD><PRE>
1 Libpairtwo Player 1 ( 4) <b>0-1 </b>Libpairtwo Player 2 ( 3)
2 Libpairtwo Player 3 ( 2) <font color='red'> Bye</font>
Libpairtwo Player 4 ( 1)<font color='red'> Absent </font>
@ -96,16 +210,20 @@ a:hover { text-decoration:none ; color: red;}
<A HREF="#Top">(Go to Top)</A>
</TD>
<TR><TH class='rh'><A NAME='Round3' style='color: black'>Round 3 (11-01-2019)</A></TH></TR>
<TR><TD><PRE>
1 Libpairtwo Player 4 ( 1) <b>½-½ </b>Libpairtwo Player 1 ( 4)
<TR>
<TH class='rh'><A NAME='Round3' style='color: black'>Round 3 (11-01-2019)</A></TH>
</TR>
<TR>
<TD><PRE>
1 Libpairtwo Player 4 ( 1) <b><EFBFBD>-<2D> </b>Libpairtwo Player 1 ( 4)
2 Libpairtwo Player 2 ( 3) <font color='red'> Bye</font>
Libpairtwo Player 3 ( 2)<font color='red'> Absent </font>
</pre>
<A HREF="#Top">(Go to Top)</A>
</TD>
</table></div>
</table>
</div>
<!-- ================= -->
<!-- GRILLE AMERICAINE -->
<!-- ================= -->
@ -114,7 +232,8 @@ a:hover { text-decoration:none ; color: red;}
<TR>
<TH colspan='14'>
<FONT size='+2'>American Ranking</FONT>
<A name=Americaine></A></TH></TR>
<A name=Americaine></A></TH>
</TR>
<TR bgcolor='#cccccc'>
<TD class='thr'>&nbsp;</TD>
@ -133,83 +252,89 @@ a:hover { text-decoration:none ; color: red;}
</tr>
<tr>
<td class='tdr' bgcolor='#eeeeee'> 1</td>
<td class='tdl' bgcolor='#eeeeee'><B>Libpairtwo Player 2 (FM)</B></td>
<td class='tdr' bgcolor='#eeeeee'>1802</td>
<td class='tdr' bgcolor='#eeeeee'><B>3.0</B></td>
<td class='tdr' bgcolor='#eeeeee'><i>2602</i></td>
<td class='tdc' bgcolor='#eeeeee'> 4W +</td>
<td class='tdc' bgcolor='#eeeeee'> 2B +</td>
<td class='tdc' bgcolor='#eeeeee'>bye</td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i>0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i>0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.00</i></td>
<td bgcolor='#eeeeee' class='tdr'> 1</td>
<td bgcolor='#eeeeee' class='tdl'><B>Libpairtwo Player 2 (FM)</B></td>
<td bgcolor='#eeeeee' class='tdr'>1802</td>
<td bgcolor='#eeeeee' class='tdr'><B>3.0</B></td>
<td bgcolor='#eeeeee' class='tdr'><i>2602</i></td>
<td bgcolor='#eeeeee' class='tdc'> 4W +</td>
<td bgcolor='#eeeeee' class='tdc'> 2B +</td>
<td bgcolor='#eeeeee' class='tdc'>bye</td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i>0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i>0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.00</i></td>
</tr>
<tr>
<td class='tdr' bgcolor='#cccccc'> 2</td>
<td class='tdl' bgcolor='#cccccc'><B>Libpairtwo Player 1 (*)</B></td>
<td class='tdr' bgcolor='#cccccc'>1801</td>
<td class='tdr' bgcolor='#cccccc'><B>1.5</B></td>
<td class='tdr' bgcolor='#cccccc'><i>1810</i></td>
<td class='tdc' bgcolor='#cccccc'> 3B +</td>
<td class='tdc' bgcolor='#cccccc'> 1W -</td>
<td class='tdc' bgcolor='#cccccc'> 4B =</td>
<td class='tdc' bgcolor='#cccccc'><i> 0.0</i></td>
<td class='tdc' bgcolor='#cccccc'><i>0</i></td>
<td class='tdc' bgcolor='#cccccc'><i>0</i></td>
<td class='tdc' bgcolor='#cccccc'><i> 0.0</i></td>
<td class='tdc' bgcolor='#cccccc'><i> 0.00</i></td>
<td bgcolor='#cccccc' class='tdr'> 2</td>
<td bgcolor='#cccccc' class='tdl'><B>Libpairtwo Player 1 (*)</B></td>
<td bgcolor='#cccccc' class='tdr'>1801</td>
<td bgcolor='#cccccc' class='tdr'><B>1.5</B></td>
<td bgcolor='#cccccc' class='tdr'><i>1810</i></td>
<td bgcolor='#cccccc' class='tdc'> 3B +</td>
<td bgcolor='#cccccc' class='tdc'> 1W -</td>
<td bgcolor='#cccccc' class='tdc'> 4B =</td>
<td bgcolor='#cccccc' class='tdc'><i> 0.0</i></td>
<td bgcolor='#cccccc' class='tdc'><i>0</i></td>
<td bgcolor='#cccccc' class='tdc'><i>0</i></td>
<td bgcolor='#cccccc' class='tdc'><i> 0.0</i></td>
<td bgcolor='#cccccc' class='tdc'><i> 0.00</i></td>
</tr>
<tr>
<td class='tdr' bgcolor='#eeeeee'> 3</td>
<td class='tdl' bgcolor='#eeeeee'><B>Libpairtwo Player 3 (IM)</B></td>
<td class='tdr' bgcolor='#eeeeee'>1803</td>
<td class='tdr' bgcolor='#eeeeee'><B>1.0</B></td>
<td class='tdr' bgcolor='#eeeeee'><i>1331</i></td>
<td class='tdc' bgcolor='#eeeeee'> 2W -</td>
<td class='tdc' bgcolor='#eeeeee'>bye</td>
<td class='tdc' bgcolor='#eeeeee'>...</td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i>0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i>0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.0</i></td>
<td class='tdc' bgcolor='#eeeeee'><i> 0.00</i></td>
<td bgcolor='#eeeeee' class='tdr'> 3</td>
<td bgcolor='#eeeeee' class='tdl'><B>Libpairtwo Player 3 (IM)</B></td>
<td bgcolor='#eeeeee' class='tdr'>1803</td>
<td bgcolor='#eeeeee' class='tdr'><B>1.0</B></td>
<td bgcolor='#eeeeee' class='tdr'><i>1331</i></td>
<td bgcolor='#eeeeee' class='tdc'> 2W -</td>
<td bgcolor='#eeeeee' class='tdc'>bye</td>
<td bgcolor='#eeeeee' class='tdc'>...</td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i>0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i>0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.0</i></td>
<td bgcolor='#eeeeee' class='tdc'><i> 0.00</i></td>
</tr>
<tr>
<td class='tdr' bgcolor='#cccccc'> 4</td>
<td class='tdl' bgcolor='#cccccc'><B>Libpairtwo Player 4 (GM)</B></td>
<td class='tdr' bgcolor='#cccccc'>1804</td>
<td class='tdr' bgcolor='#cccccc'><B>0.5</B></td>
<td class='tdr' bgcolor='#cccccc'><i>1626</i></td>
<td class='tdc' bgcolor='#cccccc'> 1B -</td>
<td class='tdc' bgcolor='#cccccc'>...</td>
<td class='tdc' bgcolor='#cccccc'> 2W =</td>
<td class='tdc' bgcolor='#cccccc'><i> 0.0</i></td>
<td class='tdc' bgcolor='#cccccc'><i>0</i></td>
<td class='tdc' bgcolor='#cccccc'><i>0</i></td>
<td class='tdc' bgcolor='#cccccc'><i> 0.0</i></td>
<td class='tdc' bgcolor='#cccccc'><i> 0.00</i></td>
<td bgcolor='#cccccc' class='tdr'> 4</td>
<td bgcolor='#cccccc' class='tdl'><B>Libpairtwo Player 4 (GM)</B></td>
<td bgcolor='#cccccc' class='tdr'>1804</td>
<td bgcolor='#cccccc' class='tdr'><B>0.5</B></td>
<td bgcolor='#cccccc' class='tdr'><i>1626</i></td>
<td bgcolor='#cccccc' class='tdc'> 1B -</td>
<td bgcolor='#cccccc' class='tdc'>...</td>
<td bgcolor='#cccccc' class='tdc'> 2W =</td>
<td bgcolor='#cccccc' class='tdc'><i> 0.0</i></td>
<td bgcolor='#cccccc' class='tdc'><i>0</i></td>
<td bgcolor='#cccccc' class='tdc'><i>0</i></td>
<td bgcolor='#cccccc' class='tdc'><i> 0.0</i></td>
<td bgcolor='#cccccc' class='tdc'><i> 0.00</i></td>
</tr>
</TABLE></DIV>
</TABLE>
</DIV>
<P align='center'><A href='#Top'><FONT size='-1'>Top of Page</FONT></A>
</TABLE>
<!-- ========= -->
<!-- COPYRIGHT -->
<!-- ========= -->
<p><TABLE border='0'>
<TR><TD align='center' bgColor='#000090'>
<p>
<TABLE border='0'>
<TR>
<TD align='center' bgColor='#000090'>
<FONT color='white' size='-1'><b>(&copy;) FRBE 2005</b></font></TD>
<TD align='center' bgColor='#000090'>
<FONT color='white' size='-1'><b>PairTwo 6.13 (2015/08/10)</b></font></td></tr>
</TD></TR></TABLE></p>
</body></html>
<FONT color='white' size='-1'><b>PairTwo 6.13 (2015/08/10)</b></font></td>
</tr>
</TD></TR></TABLE>
</p>
</body>
</html>

View File

@ -28,7 +28,7 @@ use JeroenED\Libpairtwo\Enums\Result;
*/
class Constants
{
public const WON = [Result::WON, Result::WON_FORFAIT, Result::WON_BYE, Result::WON_ADJOURNED];
public const BLACK = [Color::BLACK];
public const DRAW = [Result::DRAW, Result::DRAW_ADJOURNED];
@ -49,7 +49,7 @@ class Constants
Result::ADJOURNED
];
public const BLACK = [Color::BLACK];
public const WHITE = [Color::WHITE];
public const WON = [Result::WON, Result::WON_FORFAIT, Result::WON_BYE, Result::WON_ADJOURNED];
}

View File

@ -14,8 +14,6 @@
namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Enums\Gameresult;
use JeroenED\Libpairtwo\Pairing;
use DateTime;
/**
* Class Games
@ -29,13 +27,6 @@ use DateTime;
*/
class Game
{
/**
* The pairing for this games as seen from white's side
*
* @var Pairing | null
*/
public $White;
/**
* The pairing for this games as seen from black's side
*
@ -43,13 +34,6 @@ class Game
*/
public $Black;
/**
* The calculated game result
*
* @var GameResult | null
*/
private $CalculatedResult;
/**
* The board where this game is held
*
@ -57,11 +41,26 @@ class Game
*/
public $Board;
/**
* The calculated game result
*
* @var GameResult | null
*/
private $CalculatedResult;
/**
* The pairing for this games as seen from white's side
*
* @var Pairing | null
*/
public $White;
/**
* Returns fields that were not directly assigned.
* Class Game contains the special field Result containing the result of the game
*
* @param string $key
*
* @return Gameresult
*/
public function __get(string $key)
@ -69,6 +68,7 @@ class Game
if ($key == 'Result') {
return $this->calculateResult();
}
return null;
}
@ -113,6 +113,7 @@ class Game
* Checks if 2 games are equal
*
* @param Game $game
*
* @return bool
*/
public function equals(Game $game): bool

View File

@ -15,7 +15,6 @@ namespace JeroenED\Libpairtwo;
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
use JeroenED\Libpairtwo\Readers\Pairtwo6;
/**
* Class IOFactory
@ -40,13 +39,13 @@ abstract class IOFactory
'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical
];
/**
* Creates a reader for $type
*
* Compatible types are Swar-4, Pairtwo-5, Pairtwo-6
*
* @param string $type
*
* @return ReaderInterface
* @throws LibpairtwoException
*/

View File

@ -13,8 +13,6 @@
namespace JeroenED\Libpairtwo\Interfaces;
use JeroenED\Libpairtwo\Tournament;
/**
* Interface ReaderInterface
*
@ -31,6 +29,7 @@ interface ReaderInterface
* Reads out $filename
*
* @param $filename
*
* @return void
*/
public function read(string $filename): void;

View File

@ -29,11 +29,19 @@ use JeroenED\Libpairtwo\Enums\Result;
class Pairing
{
/**
* The player of the pairing. Please note this means the pairing was seen from the point of view of this player
* The number of the board where the game was held
*
* @var Player | null
* @var int
*/
public $Player;
public $Board;
/**
* The color of the player.
* Possible values are Black and White
*
* @var Color
*/
public $Color;
/**
* The opponent of player
@ -43,12 +51,11 @@ class Pairing
public $Opponent;
/**
* The color of the player.
* Possible values are Black and White
* The player of the pairing. Please note this means the pairing was seen from the point of view of this player
*
* @var Color
* @var Player | null
*/
public $Color;
public $Player;
/**
* The result of the Game. Possible values contain Won, Lost, Draw, Forfait, Bye, etc.
@ -63,11 +70,4 @@ class Pairing
* @var int
*/
public $Round;
/**
* The number of the board where the game was held
*
* @var int
*/
public $Board;
}

View File

@ -13,9 +13,9 @@
namespace JeroenED\Libpairtwo;
use DateTime;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Title;
use DateTime;
/**
* Class Player
@ -30,25 +30,19 @@ use DateTime;
class Player
{
/**
* Name of the player
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
/**
* The category the player belongs to
*
* @var string
*/
public $Name;
/**
* The player ids for the player. Possible keys are, but not limited to nation and fide
*
* @var int[]
*/
public $Ids;
/**
* The Elos for the player. Possible keys are, but not limited to nation and fide
*
* @var int[]
*/
public $Elos;
public $Category;
/**
* Birthday of the player
@ -58,33 +52,11 @@ class Player
public $DateOfBirth;
/**
* Tiebreak points of the player. These values are calculated when Tournament->Ranking is called
* The Elos for the player. Possible keys are, but not limited to nation and fide
*
* @var float[]
* @var int[]
*/
public $Tiebreaks = [];
/**
* The nation the player belongs to. Be noted this does not actually mean this is his main nationality. A player can be signed USCF but may be Italian
*
* @var string
*/
public $Nation;
// TODO: Implement categories
/**
* The category the player belongs to
*
* @var string
*/
public $Category;
/**
* The title of the player. Possible values can be GM, IM, IA, etc.
*
* @var Title
*/
public $Title;
public $Elos;
/**
* The gender of the player. Possible values contain Male, Female and Neutral
@ -93,6 +65,30 @@ class Player
*/
public $Gender;
/**
* The player ids for the player. Possible keys are, but not limited to nation and fide
*
* @var int[]
*/
public $Ids;
// TODO: Implement categories
/**
* Name of the player
*
* @var string
*/
public $Name;
/**
* The nation the player belongs to. Be noted this does not actually mean this is his main nationality. A player
* can be signed USCF but may be Italian
*
* @var string
*/
public $Nation;
/**
* The pairings of the player
*
@ -101,23 +97,49 @@ class Player
public $Pairings = [];
/**
* Binary data that was read out of the pairing file
* Tiebreak points of the player. These values are calculated when Tournament->Ranking is called
*
* @var bool|DateTime|int|string[]
* @var float[]
*/
private $BinaryData;
public $Tiebreaks = [];
/**
* Adds a pairing to the tournament
* The title of the player. Possible values can be GM, IM, IA, etc.
*
* @param Pairing $pairing
* @var Title
*/
public function addPairing(Pairing $pairing): void
public $Title;
/**
* Returns the performance rating of the player
*
* WARNING: Calculation currently incorrect. Uses the rule of 400 as temporary solution
*
* @param $type
* @param $unratedElo
*
* @return float
*/
public function Performance(string $type, int $unratedElo): float
{
$newArray = $this->Pairings;
$newArray[] = $pairing;
$this->Pairings = $newArray;
$total = 0;
$opponents = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$opponentElo = $pairing->Opponent->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->Result, Constants::WON) !== false) {
$total += $opponentElo + 400;
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$total += $opponentElo - 400;
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$total += $opponentElo;
}
$opponents++;
}
}
return round($total / $opponents);
}
/**
@ -125,6 +147,7 @@ class Player
*
* @param string $search
* @param Tournament $tournament
*
* @return Player[]
*/
public static function PlayersByName(string $search, Tournament $tournament): array
@ -149,71 +172,48 @@ class Player
}
/**
* Returns the elo of elotype for the player
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $type
* @return int
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function getElo(string $type): int
public function __get(string $key)
{
return $this->Elos[$type];
if ($key == 'PlayedGames') {
return $this->playedGames();
} elseif ($key == 'NoOfWins') {
return $this->noOfWins();
} elseif ($key == 'Opponents') {
return $this->opponents();
} elseif (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
/**
* Sets the elo of elotype for the player
* Sets binary data that is read out the pairing file but is not needed immediately
*
* @param string $type
* @param int $value
* @param string $key
* @param bool|int|DateTime|string $value
*/
public function setElo(string $type, int $value): void
public function __set(string $key, $value): void
{
$currentElos = $this->Elos;
$currentElos[$type] = $value;
$this->Elos = $currentElos;
$this->BinaryData[ $key ] = $value;
}
/**
* Returns the identifier of type for the player
* Adds a pairing to the tournament
*
* Common possible values are Fide or National
*
* @param string $type
* @return string
* @param Pairing $pairing
*/
public function getId(string $type): string
public function addPairing(Pairing $pairing): void
{
return $this->Ids[$type];
}
/**
* Sets the identifier of type for the player
*
* Common possible values are Fide or National
*
* @param string $type
* @param string $value
*/
public function setId(string $type, string $value): void
{
$currentIds = $this->Ids;
$currentIds[$type] = $value;
$this->Ids = $currentIds;
}
/**
* Returns the number of won matches for the player
*
* @return int
*/
private function noOfWins(): int
{
$wins = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$wins++;
}
}
return $wins;
$newArray = $this->Pairings;
$newArray[] = $pairing;
$this->Pairings = $newArray;
}
/**
@ -224,6 +224,7 @@ class Player
* 0 points are awarded for loss
*
* @param int $round
*
* @return float
*/
public function calculatePoints(int $round = -1): float
@ -238,25 +239,10 @@ class Player
}
}
}
return $points;
}
/**
* Returns the points of a virtual player as described in the Fide Handbook C.02 chapter 13.15.2.
*
* Return the same score for all rounds until $byeround and added with a half point for each subsequent round
*
* @param int $byeround
* @return float
*/
public function calculatePointsForVirtualPlayer(int $byeround): float
{
$points = $this->calculatePoints($byeround);
foreach (array_slice($this->Pairings, $byeround + 1) as $key => $pairing) {
$points += 0.5;
}
return $points;
}
/**
* Returns the points of the player that should be used for tiebreaking systems.
*
@ -278,59 +264,60 @@ class Player
$points = $points + 0.5;
}
}
return $points;
}
/**
* Returns the performance rating of the player
* Returns the points of a virtual player as described in the Fide Handbook C.02 chapter 13.15.2.
*
* WARNING: Calculation currently incorrect. Uses the rule of 400 as temporary solution
* Return the same score for all rounds until $byeround and added with a half point for each subsequent round
*
* @param int $byeround
*
* @param $type
* @param $unratedElo
* @return float
*/
public function Performance(string $type, int $unratedElo): float
public function calculatePointsForVirtualPlayer(int $byeround): float
{
$total = 0;
$opponents = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$opponentElo = $pairing->Opponent->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->Result, Constants::WON) !== false) {
$total += $opponentElo + 400;
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$total += $opponentElo - 400;
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$total += $opponentElo;
}
$opponents++;
}
}
return round($total / $opponents);
$points = $this->calculatePoints($byeround);
foreach (array_slice($this->Pairings, $byeround + 1) as $key => $pairing) {
$points += 0.5;
}
return $points;
}
/**
* Returns the number of played games of the player
* Returns the elo of elotype for the player
*
* @param string $type
*
* @return int
*/
private function playedGames(): int
public function getElo(string $type): int
{
$total = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::PLAYED) !== false) {
$total++;
return $this->Elos[ $type ];
}
}
return $total;
/**
* Returns the identifier of type for the player
*
* Common possible values are Fide or National
*
* @param string $type
*
* @return string
*/
public function getId(string $type): string
{
return $this->Ids[ $type ];
}
/**
* Returns if player has played against all players of the array
*
* @param Player[] $players
*
* @return bool
*/
public function hasPlayedAllPlayersOfArray(array $players): bool
@ -349,6 +336,23 @@ class Player
return $total == count($players);
}
/**
* Returns the number of won matches for the player
*
* @return int
*/
private function noOfWins(): int
{
$wins = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$wins++;
}
}
return $wins;
}
/**
* Returns all opponents of $this
*
@ -356,43 +360,58 @@ class Player
*/
private function opponents()
{
$return = array();
$return = [];
foreach ($this->Pairings as $pairing) {
if (!empty($pairing->Opponent)) {
$return[] = $pairing->Opponent;
}
}
return $return;
}
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
* Returns the number of played games of the player
*
* @param string $key
* @return bool|DateTime|int|string|null
* @return int
*/
public function __get(string $key)
private function playedGames(): int
{
if ($key == 'PlayedGames') {
return $this->playedGames();
} elseif ($key == 'NoOfWins') {
return $this->noOfWins();
} elseif ($key == 'Opponents') {
return $this->opponents();
} elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key];
$total = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::PLAYED) !== false) {
$total++;
}
return null;
}
return $total;
}
/**
* Sets binary data that is read out the pairing file but is not needed immediately
* Sets the elo of elotype for the player
*
* @param string $key
* @param bool|int|DateTime|string $value
* @param string $type
* @param int $value
*/
public function __set(string $key, $value): void
public function setElo(string $type, int $value): void
{
$this->BinaryData[$key] = $value;
$currentElos = $this->Elos;
$currentElos[ $type ] = $value;
$this->Elos = $currentElos;
}
/**
* Sets the identifier of type for the player
*
* Common possible values are Fide or National
*
* @param string $type
* @param string $value
*/
public function setId(string $type, string $value): void
{
$currentIds = $this->Ids;
$currentIds[ $type ] = $value;
$this->Ids = $currentIds;
}
}

View File

@ -13,6 +13,7 @@
namespace JeroenED\Libpairtwo\Readers;
use DateTime;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
@ -26,7 +27,6 @@ use JeroenED\Libpairtwo\Pairing;
use JeroenED\Libpairtwo\Player;
use JeroenED\Libpairtwo\Round;
use JeroenED\Libpairtwo\Tournament;
use DateTime;
/**
* Reader Pairtwo6
@ -40,15 +40,22 @@ use DateTime;
*/
class Pairtwo6 implements ReaderInterface
{
public const COMPATIBLE_VERSIONS = ['6.', '5.'];
public const PT_DAYFACTOR = 32;
public const PT_MONTHFACTOR = 16;
public const PT_YEARFACTOR = 512;
public const PT_PASTOFFSET = 117;
public const COMPATIBLE_VERSIONS = ['6.', '5.'];
public const PT_YEARFACTOR = 512;
/**
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
/**
* Version of Pairtwo this file was created with
@ -64,17 +71,11 @@ class Pairtwo6 implements ReaderInterface
*/
public $Tournament;
/**
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
/**
* Returns binary data that was read out the pairtwo file but was not needed immediately
*
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
@ -82,6 +83,7 @@ class Pairtwo6 implements ReaderInterface
if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
@ -96,10 +98,64 @@ class Pairtwo6 implements ReaderInterface
$this->BinaryData[ $key ] = $value;
}
/**
* Adds the first tiebreak to the tournament
*/
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::KEIZER:
$firstElement = new Tiebreak(Tiebreak::KEIZER);
break;
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
$firstElement = new Tiebreak(Tiebreak::POINTS);
break;
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);
$this->Tournament->Tiebreaks = $tiebreaks;
}
/**
* Converts integer value to a date representation
*
* @param int $date
*
* @return bool|DateTime
*/
private function convertUIntToTimestamp(int $date)
{
$curyear = date('Y');
$yearoffset = $curyear - self::PT_PASTOFFSET;
// Day
$day = $date % self::PT_DAYFACTOR;
if ($day < 1) {
$day = 1;
}
// Month
$month = ($date / self::PT_DAYFACTOR) % self::PT_MONTHFACTOR;
if ($month < 1) {
$month = 1;
}
// Year
$year = ($date / self::PT_YEARFACTOR) + $yearoffset;
$concat = $month . '/' . $day . '/' . intval($year);
$format = 'm/d/Y';
return DateTime::createFromFormat($format, $concat);
}
/**
* Actually reads the Swar-File
*
* @param string $filename
*
* @throws IncompatibleReaderException
*/
public function read(string $filename): void
@ -110,7 +166,6 @@ class Pairtwo6 implements ReaderInterface
$offset = 0;
$length = 4;
$this->Release = $this->readData('String', substr($swscontents, $offset, $length));
$offset += $length;
@ -406,7 +461,8 @@ class Pairtwo6 implements ReaderInterface
$offset += $length;
$length = 1;
$player->Category = $this->Tournament->Categories[$this->readData('Int', substr($swscontents, $offset, $length)) -1];
$player->Category =
$this->Tournament->Categories[ $this->readData('Int', substr($swscontents, $offset, $length)) - 1 ];
$offset += $length;
$length = 1;
@ -759,6 +815,7 @@ class Pairtwo6 implements ReaderInterface
* @param string $type
* @param string $data
* @param mixed $default
*
* @return bool|DateTime|int|string
*/
private function readData(string $type, string $data, $default = null)
@ -769,6 +826,7 @@ class Pairtwo6 implements ReaderInterface
if ($data == '') {
return (is_null($default)) ? '' : $default;
}
return iconv('windows-1252', 'utf-8', $data);
case 'Hex':
case 'Int':
@ -791,16 +849,19 @@ class Pairtwo6 implements ReaderInterface
if ($hex == '00') {
return (is_null($default)) ? '00' : $default;
}
return $hex;
} elseif ($type == 'Int') {
if ($hex == '00') {
return (is_null($default)) ? 0 : $default;
}
return hexdec($hex);
} elseif ($type == 'Date') {
if ($hex == '00') {
return (is_null($default)) ? $this->convertUIntToTimestamp(0) : $default;
}
return $this->convertUIntToTimestamp(hexdec($hex));
} elseif ($type == 'Bool') {
return ($hex == "01");
@ -812,58 +873,4 @@ class Pairtwo6 implements ReaderInterface
return false;
}
/**
* Converts integer value to a date representation
*
* @param int $date
* @return bool|DateTime
*/
private function convertUIntToTimestamp(int $date)
{
$curyear = date('Y');
$yearoffset = $curyear - self::PT_PASTOFFSET;
// Day
$day = $date % self::PT_DAYFACTOR;
if ($day < 1) {
$day = 1;
}
// Month
$month = ($date / self::PT_DAYFACTOR) % self::PT_MONTHFACTOR;
if ($month < 1) {
$month = 1;
}
// Year
$year = ($date / self::PT_YEARFACTOR) + $yearoffset;
$concat = $month . '/' . $day . '/' . intval($year);
$format = 'm/d/Y';
return DateTime::createFromFormat($format, $concat);
}
/**
* Adds the first tiebreak to the tournament
*/
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::KEIZER:
$firstElement = new Tiebreak(Tiebreak::KEIZER);
break;
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
$firstElement = new Tiebreak(Tiebreak::POINTS);
break;
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);
$this->Tournament->Tiebreaks = $tiebreaks;
}
}

View File

@ -13,6 +13,7 @@
namespace JeroenED\Libpairtwo\Readers;
use DateTime;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
@ -26,7 +27,6 @@ use JeroenED\Libpairtwo\Pairing;
use JeroenED\Libpairtwo\Player;
use JeroenED\Libpairtwo\Round;
use JeroenED\Libpairtwo\Tournament;
use DateTime;
/**
* Reader Swar4
@ -40,27 +40,6 @@ use DateTime;
*/
class Swar4 implements ReaderInterface
{
/**
* Version of Pairtwo this file was created with
*
* @var string
*/
public $Release;
/**
* The tournament
*
* @var Tournament
*/
public $Tournament;
/**
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
/**
* @var array
*/
@ -127,6 +106,92 @@ class Swar4 implements ReaderInterface
]
];
/**
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
/**
* Version of Pairtwo this file was created with
*
* @var string
*/
public $Release;
/**
* The tournament
*
* @var Tournament
*/
public $Tournament;
/**
* Returns binary data that was read out the swar file but was not needed immediately
*
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
{
if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
/**
* Sets binary data that is read out the swar file but is not needed immediately
*
* @param string $key
* @param bool|int|DateTime|string $value
*/
public function __set(string $key, $value): void
{
$this->BinaryData[ $key ] = $value;
}
/**
* Adds the first tiebreak to the tournament
*/
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
default:
$firstElement = new Tiebreak(Tiebreak::POINTS);
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);
$this->Tournament->Tiebreaks = $tiebreaks;
}
/**
* Converts a swar-4 string to a \DateTime object
*
* @param string $string
*
* @return DateTime
*/
public function convertStringToDate(string $string): DateTime
{
if (strlen($string) == 10) {
return DateTime::createFromFormat('d/m/Y', $string);
} elseif (strlen($string) == 8) {
return DateTime::createFromFormat('Ymd', $string);
} else {
$default = new DateTime();
$default->setTimestamp(0);
return $default;
}
}
/**
* Actually reads the Swar-File
*
@ -601,68 +666,4 @@ class Swar4 implements ReaderInterface
return false;
}
/**
* Returns binary data that was read out the swar file but was not needed immediately
*
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
{
if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
/**
* Sets binary data that is read out the swar file but is not needed immediately
*
* @param string $key
* @param bool|int|DateTime|string $value
*/
public function __set(string $key, $value): void
{
$this->BinaryData[ $key ] = $value;
}
/**
* Converts a swar-4 string to a \DateTime object
*
* @param string $string
*
* @return DateTime
*/
public function convertStringToDate(string $string): DateTime
{
if (strlen($string) == 10) {
return DateTime::createFromFormat('d/m/Y', $string);
} elseif (strlen($string) == 8) {
return DateTime::createFromFormat('Ymd', $string);
} else {
$default = new DateTime();
$default->setTimestamp(0);
return $default;
}
}
/**
* Adds the first tiebreak to the tournament
*/
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
default:
$firstElement = new Tiebreak(Tiebreak::POINTS);
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);
$this->Tournament->Tiebreaks = $tiebreaks;
}
}

View File

@ -42,6 +42,13 @@ class Round
*/
public $Games = [];
/**
* Array of all pairings for this round
*
* @var Pairing[]
*/
public $Pairings = [];
/**
* Number of the round
*
@ -50,11 +57,44 @@ class Round
public $RoundNo;
/**
* Array of all pairings for this round
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @var Pairing[]
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public $Pairings = [];
public function __get(string $key)
{
if ($key == 'Bye') {
return $this->bye();
} elseif ($key == 'Absent') {
return $this->absent();
} elseif ($key == 'GamesByBoard') {
return $this->gamesByBoard();
} elseif (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
/**
* Returns an array of pairings where the player is absent
*
* @return Pairing[]
*/
private function absent(): array
{
$allPairings = $this->Pairings;
$absentPairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::ABSENT) {
$absentPairings[] = $pairing;
}
}
return $absentPairings;
}
/**
* Adds a game to the round
@ -94,24 +134,8 @@ class Round
$byePairings[] = $pairing;
}
}
return $byePairings;
}
/**
* Returns an array of pairings where the player is absent
*
* @return Pairing[]
*/
private function absent(): array
{
$allPairings = $this->Pairings;
$absentPairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::ABSENT) {
$absentPairings[] = $pairing;
}
}
return $absentPairings;
return $byePairings;
}
/**
@ -122,7 +146,8 @@ class Round
private function gamesByBoard(): array
{
$allGames = $this->Games;
usort($allGames, array($this, 'sortByBoard'));
usort($allGames, [$this, 'sortByBoard']);
return $allGames;
}
@ -131,6 +156,7 @@ class Round
*
* @param Game $a
* @param Game $b
*
* @return int
*/
private function sortByBoard(Game $a, Game $b): int
@ -138,26 +164,7 @@ class Round
if (($a->Board == $b->Board) || ($a->Board === false) || ($b->Board === false)) {
return 0;
}
return ($a->Board > $b->Board) ? +1 : -1;
}
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $key
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
{
if ($key == 'Bye') {
return $this->bye();
} elseif ($key == 'Absent') {
return $this->absent();
} elseif ($key == 'GamesByBoard') {
return $this->gamesByBoard();
} elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key];
}
return null;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
use JeroenED\Libpairtwo\IOFactory;
require_once '../vendor/autoload.php';
@ -30,7 +31,6 @@ require_once '../vendor/autoload.php';
$sws = IOFactory::createReader('Swar-4');
$sws->read('../res/testswar.swar');
echo "Release: " . $sws->Release . PHP_EOL;
echo "Name: " . $sws->Tournament->Name . PHP_EOL;
echo "Organiser: " . $sws->Tournament->Organiser . PHP_EOL;
@ -89,7 +89,9 @@ echo "Tiebreak 5: " . $sws->Tournament->Tiebreaks[4]->getValue() . PHP_EOL;
echo "Tiebreak 6: " . $sws->Tournament->Tiebreaks[ 5 ]->getValue() . PHP_EOL;
echo "Average Elo: " . $sws->Tournament->AverageElo . PHP_EOL;
foreach ($sws->Tournament->RankingForCategory('+2500') as $player) {
echo str_pad($player->Name . '(' . $player->getElo($sws->Tournament->PriorityElo) . ') ', 35) . implode_pad(' ', $player->Tiebreaks, 5, ' ') . PHP_EOL;
echo str_pad($player->Name . '(' . $player->getElo($sws->Tournament->PriorityElo) . ') ', 35) .
implode_pad(' ', $player->Tiebreaks, 5, ' ') .
PHP_EOL;
}
function implode_pad($glue, $collection, $padlength, $padstring): string
@ -98,5 +100,6 @@ function implode_pad($glue, $collection, $padlength, $padstring): string
foreach ($collection as $elem) {
$newarray[] = str_pad($elem, $padlength, $padstring);
}
return implode($glue, $newarray);
}