Compare commits

...

2 Commits

Author SHA1 Message Date
Jeroen De Meerleer d1421e2450 Reading out several tournament fields 2019-01-18 18:11:53 +01:00
Jeroen De Meerleer 6bfa557892 several corrections 2019-01-18 18:10:56 +01:00
3 changed files with 151 additions and 64 deletions

View File

@ -38,6 +38,7 @@ class Tournament
private $OrganiserClub; private $OrganiserClub;
private $OrganiserPlace; private $OrganiserPlace;
private $OrganiserCountry; private $OrganiserCountry;
private $FideHomol;
private $StartDate; private $StartDate;
private $EndDate; private $EndDate;
private $Arbiter; private $Arbiter;
@ -48,7 +49,7 @@ class Tournament
private $System; private $System;
/** /**
* @return mixed * @return string
*/ */
public function getName() public function getName()
{ {
@ -56,7 +57,7 @@ class Tournament
} }
/** /**
* @param mixed $Name * @param string $Name
*/ */
public function setName($Name): void public function setName($Name): void
{ {
@ -64,7 +65,7 @@ class Tournament
} }
/** /**
* @return mixed * @return string
*/ */
public function getOrganiser() public function getOrganiser()
{ {
@ -72,7 +73,7 @@ class Tournament
} }
/** /**
* @param mixed $Organiser * @param string $Organiser
*/ */
public function setOrganiser($Organiser): void public function setOrganiser($Organiser): void
{ {
@ -80,7 +81,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getOrganiserClub() public function getOrganiserClub()
{ {
@ -88,7 +89,7 @@ class Tournament
} }
/** /**
* @param mixed $OrganiserClub * @param integer $OrganiserClub
*/ */
public function setOrganiserClub($OrganiserClub): void public function setOrganiserClub($OrganiserClub): void
{ {
@ -96,7 +97,7 @@ class Tournament
} }
/** /**
* @return mixed * @return string
*/ */
public function getOrganiserPlace() public function getOrganiserPlace()
{ {
@ -104,7 +105,7 @@ class Tournament
} }
/** /**
* @param mixed $OrganiserPlace * @param string $OrganiserPlace
*/ */
public function setOrganiserPlace($OrganiserPlace): void public function setOrganiserPlace($OrganiserPlace): void
{ {
@ -112,7 +113,7 @@ class Tournament
} }
/** /**
* @return mixed * @return string
*/ */
public function getOrganiserCountry() public function getOrganiserCountry()
{ {
@ -120,7 +121,7 @@ class Tournament
} }
/** /**
* @param mixed $OrganiserCountry * @param string $OrganiserCountry
*/ */
public function setOrganiserCountry($OrganiserCountry): void public function setOrganiserCountry($OrganiserCountry): void
{ {
@ -128,7 +129,23 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/
public function getFideHomol()
{
return $this->FideHomol;
}
/**
* @param integer $FideHomol
*/
public function setFideHomol($FideHomol): void
{
$this->FideHomol = $FideHomol;
}
/**
* @return integer
*/ */
public function getStartDate() public function getStartDate()
{ {
@ -136,7 +153,7 @@ class Tournament
} }
/** /**
* @param mixed $StartDate * @param integer $StartDate
*/ */
public function setStartDate($StartDate): void public function setStartDate($StartDate): void
{ {
@ -144,7 +161,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getEndDate() public function getEndDate()
{ {
@ -152,7 +169,7 @@ class Tournament
} }
/** /**
* @param mixed $EndDate * @param integer$EndDate
*/ */
public function setEndDate($EndDate): void public function setEndDate($EndDate): void
{ {
@ -160,7 +177,7 @@ class Tournament
} }
/** /**
* @return mixed * @return string
*/ */
public function getArbiter() public function getArbiter()
{ {
@ -168,7 +185,7 @@ class Tournament
} }
/** /**
* @param mixed $Arbiter * @param string $Arbiter
*/ */
public function setArbiter($Arbiter): void public function setArbiter($Arbiter): void
{ {
@ -176,7 +193,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getRounds() public function getRounds()
{ {
@ -184,7 +201,7 @@ class Tournament
} }
/** /**
* @param mixed $Rounds * @param integer $Rounds
*/ */
public function setRounds($Rounds): void public function setRounds($Rounds): void
{ {
@ -192,7 +209,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getParticipants() public function getParticipants()
{ {
@ -200,7 +217,7 @@ class Tournament
} }
/** /**
* @param mixed $Participants * @param integer $Participants
*/ */
public function setParticipants($Participants): void public function setParticipants($Participants): void
{ {
@ -208,7 +225,7 @@ class Tournament
} }
/** /**
* @return mixed * @return string
*/ */
public function getTempo() public function getTempo()
{ {
@ -216,7 +233,7 @@ class Tournament
} }
/** /**
* @param mixed $Tempo * @param string $Tempo
*/ */
public function setTempo($Tempo): void public function setTempo($Tempo): void
{ {
@ -224,7 +241,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getNonRatedElo() public function getNonRatedElo()
{ {
@ -232,7 +249,7 @@ class Tournament
} }
/** /**
* @param mixed $NonRatedElo * @param integer $NonRatedElo
*/ */
public function setNonRatedElo($NonRatedElo): void public function setNonRatedElo($NonRatedElo): void
{ {
@ -240,7 +257,7 @@ class Tournament
} }
/** /**
* @return mixed * @return integer
*/ */
public function getSystem() public function getSystem()
{ {
@ -248,7 +265,7 @@ class Tournament
} }
/** /**
* @param mixed $System * @param integer $System
*/ */
public function setSystem($System): void public function setSystem($System): void
{ {

View File

@ -36,6 +36,13 @@ use JeroenED\Libpairtwo\Models\Sws as MyModel;
*/ */
class Sws class Sws
{ {
private const PT_DAYFACTOR = 32;
private const PT_MONTHFACTOR = 16;
private const PT_YEARFACTOR = 512;
private const PT_SYSTEMYEAR = 1900;
private const PT_PASTOFFSET = 117;
/** /**
* @param string $swsfile * @param string $swsfile
* @return MyModel * @return MyModel
@ -51,169 +58,169 @@ class Sws
$length = 4; $length = 4;
$sws->setRelease(Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setRelease(self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
$sws->setTournament(new Tournament()); $sws->setTournament(new Tournament());
// UserCountry // UserCountry
$length = 4; $length = 4;
$sws->setBinaryData("UserCountry", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("UserCountry", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// SavedOffset // SavedOffset
$length = 4; $length = 4;
$sws->setBinaryData("SavedOffset", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("SavedOffset", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// NewPlayer // NewPlayer
$length = 4; $length = 4;
$sws->setBinaryData("NewPlayer", hexdec(Self::ReadHexData(substr($swscontents, $offset, $length)))); $sws->setBinaryData("NewPlayer", hexdec(self::ReadHexData(substr($swscontents, $offset, $length))));
$offset += $length; $offset += $length;
// AmericanHandicap // AmericanHandicap
$length = 4; $length = 4;
$sws->setBinaryData("AmericanHandicap", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("AmericanHandicap", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// LowOrder // LowOrder
$length = 4; $length = 4;
$sws->setBinaryData("LowOrder", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("LowOrder", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// PairingMethod // PairingMethod
$length = 4; $length = 4;
$sws->setBinaryData("PairingMethod", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("PairingMethod", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// AmericanPresence // AmericanPresence
$length = 4; $length = 4;
$sws->setBinaryData("AmericanPresence", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("AmericanPresence", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// CheckSameClub // CheckSameClub
$length = 4; $length = 4;
$sws->setBinaryData("CheckSameClub", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("CheckSameClub", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// NoColorCheck // NoColorCheck
$length = 4; $length = 4;
$sws->setBinaryData("NoColorCheck", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("NoColorCheck", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// SeparateCategories // SeparateCategories
$length = 4; $length = 4;
$sws->setBinaryData("SeparateCategories", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("SeparateCategories", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// EloUsed // EloUsed
$length = 4; $length = 4;
$sws->setBinaryData("EloUsed", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("EloUsed", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// AlternateColors // AlternateColors
$length = 4; $length = 4;
$sws->setBinaryData("AlternateColors", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("AlternateColors", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MaxMeetings // MaxMeetings
$length = 4; $length = 4;
$sws->setBinaryData("MaxMeetings", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MaxMeetings", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MaxDistance // MaxDistance
$length = 4; $length = 4;
$sws->setBinaryData("MaxDistance", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MaxDistance", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MinimizeKeizer // MinimizeKeizer
$length = 4; $length = 4;
$sws->setBinaryData("MinimizeKeizer", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MinimizeKeizer", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MinRoundsMeetings // MinRoundsMeetings
$length = 4; $length = 4;
$sws->setBinaryData("MinRoundsMeetings", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MinRoundsMeetings", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MaxRoundsAbsent // MaxRoundsAbsent
$length = 4; $length = 4;
$sws->setBinaryData("MaxRoundsAbsent", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MaxRoundsAbsent", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// SpecialPoints // SpecialPoints
$length = 4 * 6; $length = 4 * 6;
$sws->setBinaryData("SpecialPoints", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("SpecialPoints", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// NewNamePos // NewNamePos
$length = 4; $length = 4;
$sws->setBinaryData("NewNamePos", hexdec(Self::ReadHexData(substr($swscontents, $offset, $length)))); $sws->setBinaryData("NewNamePos", hexdec(self::ReadHexData(substr($swscontents, $offset, $length))));
$offset += $length; $offset += $length;
// CurrentRound // CurrentRound
$length = 4; $length = 4;
$sws->setBinaryData("CurrentRound", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("CurrentRound", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// CreatedRounds // CreatedRounds
$length = 4; $length = 4;
$sws->setBinaryData("CreatedRounds", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("CreatedRounds", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// CreatedPlayers // CreatedPlayers
$length = 4; $length = 4;
$sws->setBinaryData("CreatedPlayers", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("CreatedPlayers", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// MaxSelection // MaxSelection
$length = 4; $length = 4;
$sws->setBinaryData("MaxSelection", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("MaxSelection", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// NumberOfRounds // NumberOfRounds
$length = 4; $length = 4;
$sws->setBinaryData("NumberOfRounds", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("NumberOfRounds", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// NumberOfPairings // NumberOfPairings
$length = 4; $length = 4;
$sws->setBinaryData("NumberOfPairings", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("NumberOfPairings", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// CreatedPairings // CreatedPairings
$length = 4; $length = 4;
$sws->setBinaryData("CreatedPairings", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("CreatedPairings", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// PairingElems // PairingElems
$length = 4; $length = 4;
$sws->setBinaryData("PairingElems", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("PairingElems", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// RandomSeed // RandomSeed
$length = 4; $length = 4;
$sws->setBinaryData("RandomSeed", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("RandomSeed", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// TieOrder // TieOrder
$length = 4 * 5; $length = 4 * 5;
$sws->setBinaryData("TieOrder", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("TieOrder", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// Categorie // Categorie
$length = 4 * 10; $length = 4 * 10;
$sws->setBinaryData("Categorie", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("Categorie", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// ExtraPoints // ExtraPoints
$length = 4 * 20; $length = 4 * 20;
$sws->setBinaryData("ExtraPoints", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("ExtraPoints", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// SelectP // SelectP
$length = 4 * 20; $length = 4 * 20;
$sws->setBinaryData("SelectP", Self::ReadHexData(substr($swscontents, $offset, $length))); $sws->setBinaryData("SelectP", self::ReadHexData(substr($swscontents, $offset, $length)));
$offset += $length; $offset += $length;
// Players // Players
@ -251,13 +258,70 @@ class Sws
$sws->getTournament()->setArbiter(substr($swscontents, $offset, $length)); $sws->getTournament()->setArbiter(substr($swscontents, $offset, $length));
$offset += $length; $offset += $length;
// Rounds
$length = 4;
$sws->getTournament()->setRounds(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// Participants
$length = 4;
$sws->getTournament()->setParticipants(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// Fidehomol
$length = 4;
$sws->getTournament()->setFideHomol(hexdec(substr($swscontents, $offset, $length)));
$offset += $length;
// StartDate
$length = 4;
//echo self::readhexdata(substr($swscontents, $offset, $length));
$sws->getTournament()->setStartDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
// EndDate
$length = 4;
$sws->getTournament()->setEndDate(self::UIntToTimestamp(hexdec(self::readhexdata(substr($swscontents, $offset, $length)))));
$offset += $length;
return $sws; return $sws;
} }
private static function ReadHexData(String $data) private static function ReadHexData(String $data)
{ {
$hex = implode(unpack("H*", $data)); $hex = implode(unpack("H*", $data));
$hex = implode(array_reverse(str_split($hex, 2)));
$hex = str_replace("00", "", $hex); $hex = str_replace("00", "", $hex);
return $hex; return $hex;
} }
private static function UIntToTimestamp($date)
{
//echo $date;
$curyear = date('Y');
$yearoffset = $curyear - self::PT_PASTOFFSET;
//$yearoffset = 100;
// 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';
echo $concat;
return \DateTime::createFromFormat($format, $concat);
}
} }

View File

@ -28,10 +28,16 @@ Use JeroenED\Libpairtwo\Sws;
require_once '../vendor/autoload.php'; require_once '../vendor/autoload.php';
$sws = Sws::readSws('../res/testsws.sws'); $sws = Sws::readSws('../res/testsws.sws');
echo "Name: " . $sws->getTournament()->getName() . "\n"; echo "Name: " . $sws->getTournament()->getName() . "\n";
echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n"; echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n";
echo "Tempo: " . $sws->getTournament()->getTempo() . "\n"; echo "Tempo: " . $sws->getTournament()->getTempo() . "\n";
echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n"; echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n";
echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\n"; echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\n";
echo "Rounds: " . $sws->getTournament()->getRounds() . "\n";
echo "Participants: " . $sws->getTournament()->getRounds() . "\n";
echo "Fidehomol: " . $sws->getTournament()->getFideHomol() . "\n";
echo "Start-Date: " . $sws->getTournament()->getStartDate()->format('d/m/Y') . "\n";
echo "Start-Date: " . $sws->getTournament()->getEndDate()->format('d/m/Y') . "\n";
//echo "Start-Date hex: " . $sws->getBinaryData("startdate") . "\n";
//echo $sws->getBinaryData("Tournament"); //echo $sws->getBinaryData("Tournament");
//echo $sws->getBinaryData("Players"); //echo $sws->getBinaryData("Players");