2022-03-02 06:24:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Teamtable;
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
use \InvalidArgumentException;
|
|
|
|
|
2022-03-02 06:24:27 +00:00
|
|
|
/**
|
2022-03-13 19:54:34 +00:00
|
|
|
* Represents a record in the teamtable
|
2022-03-02 06:24:27 +00:00
|
|
|
*/
|
|
|
|
class Team
|
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
public int $id;
|
|
|
|
public string $name = 'NN';
|
|
|
|
public string $company = 'NN';
|
|
|
|
public string $cardnumber = 'NN';
|
|
|
|
public string $leader = 'NN';
|
|
|
|
public int $phone = 0;
|
|
|
|
public int $participants = 0;
|
|
|
|
public int $rounds = 0;
|
|
|
|
|
2022-03-09 12:11:12 +00:00
|
|
|
/**
|
|
|
|
* PHP by default does not include multi byte functions. Therefore we use this
|
|
|
|
*/
|
|
|
|
private function count_characters(string $string)
|
|
|
|
{
|
|
|
|
return count(preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if string is longer than length
|
|
|
|
*/
|
|
|
|
private function longerThan(string $string, int $length): bool
|
|
|
|
{
|
|
|
|
if ($this->count_characters($string) > $length)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setName(string $name): Self
|
2022-03-02 13:26:02 +00:00
|
|
|
{
|
2022-03-09 12:11:12 +00:00
|
|
|
if ($this->longerThan($name, 32))
|
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Name is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
2022-03-02 13:26:02 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setCompany(string $company): Self
|
2022-03-02 13:26:02 +00:00
|
|
|
{
|
2022-03-09 12:11:12 +00:00
|
|
|
if ($this->longerThan($company, 32))
|
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Company is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->company = $company;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-03-02 13:26:02 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setCardnumber(string $cardnumber): Self
|
|
|
|
{
|
2022-03-09 12:11:12 +00:00
|
|
|
if ($this->longerThan($cardnumber, 32))
|
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Cardnumber is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->cardnumber = $cardnumber;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-03-02 13:26:02 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setLeader(string $leader): Self
|
|
|
|
{
|
2022-03-09 12:11:12 +00:00
|
|
|
if ($this->longerThan($leader, 32))
|
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Leader is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->leader = $leader;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-03-02 13:26:02 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setPhone(int $phone): Self
|
|
|
|
{
|
2022-03-10 08:38:39 +00:00
|
|
|
if ($this->longerThan((string)$phone, 32))
|
2022-03-09 12:11:12 +00:00
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Phone number is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->phone = $phone;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-03-02 13:26:02 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setParticipants(int $participants): Self
|
|
|
|
{
|
2022-03-10 08:38:39 +00:00
|
|
|
if ($this->longerThan((string)$participants, 32))
|
2022-03-09 12:11:12 +00:00
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Participants is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->participants = $participants;
|
|
|
|
return $this;
|
|
|
|
}
|
2022-03-02 13:26:02 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function setRounds(int $rounds): Self
|
|
|
|
{
|
2022-03-10 08:38:39 +00:00
|
|
|
if ($this->longerThan((string)$rounds, 32))
|
2022-03-09 12:11:12 +00:00
|
|
|
{
|
|
|
|
throw new InvalidArgumentException("Rounds is too long!");
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->rounds = $rounds;
|
|
|
|
return $this;
|
2022-03-02 13:26:02 +00:00
|
|
|
}
|
2022-03-02 06:24:27 +00:00
|
|
|
}
|