Compare commits

..

No commits in common. "d1421e2450ceb2dbf4d7024bf52588a44a3d776c" and "71d1f2e500b9a5549c6ad039c92e1d47fdc37929" have entirely different histories.

3 changed files with 64 additions and 151 deletions

View File

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

View File

@ -36,13 +36,6 @@ 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
@ -58,169 +51,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
@ -258,70 +251,13 @@ 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,16 +28,10 @@ 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");