String are being trimmed now

And added default values as well
This commit is contained in:
Jeroen De Meerleer 2019-02-12 14:10:50 +01:00
parent 53b6316d89
commit 97d5abec62

View File

@ -455,7 +455,7 @@ class Sws extends SwsModel
// Organising club no // Organising club no
$length = 4; $length = 4;
$sws->getTournament()->setOrganiserClubNo(self::ReadData('String', substr($swscontents, $offset, $length))); $sws->getTournament()->setOrganiserClubNo(self::ReadData('String', substr($swscontents, $offset, $length), 0));
$offset += $length; $offset += $length;
// Organising club // Organising club
@ -512,13 +512,17 @@ class Sws extends SwsModel
/** /**
* @param string $type * @param string $type
* @param string $data * @param string $data
* @param mixed $default
* @return bool|DateTime|int|string * @return bool|DateTime|int|string
*/ */
private static function ReadData(string $type, string $data) private static function ReadData(string $type, string $data, $default = null)
{ {
switch ($type) { switch ($type) {
case 'String': case 'String':
return $data; if (trim($data) == '') {
return (is_null($default)) ? '' : $default;
}
return trim($data);
break; break;
case 'Hex': case 'Hex':
case 'Int': case 'Int':
@ -538,10 +542,19 @@ class Sws extends SwsModel
$hex = implode($hex); $hex = implode($hex);
$hex = ($hex == "") ? "00" : $hex; $hex = ($hex == "") ? "00" : $hex;
if ($type == 'Hex') { if ($type == 'Hex') {
if ($hex == '00') {
return (is_null($default)) ? '00' : $default;
}
return $hex; return $hex;
} elseif ($type == 'Int') { } elseif ($type == 'Int') {
if ($hex == '00') {
return (is_null($default)) ? 0 : $default;
}
return hexdec($hex); return hexdec($hex);
} elseif ($type == 'Date') { } elseif ($type == 'Date') {
if ($hex == '00') {
return (is_null($default)) ? self::UIntToTimestamp(0) : $default;
}
return self::UIntToTimestamp(hexdec($hex)); return self::UIntToTimestamp(hexdec($hex));
} elseif ($type == 'Bool') { } elseif ($type == 'Bool') {
return ($hex == "01") ? true : false; return ($hex == "01") ? true : false;