This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/lib/App/Teamtable/Team.php

111 lines
2.7 KiB
PHP
Raw Permalink Normal View History

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-04-14 20:59:42 +00:00
public int $id;
public string $name = 'NN';
public string $company = 'NN';
public string $cardnumber = 'NN';
public string $leader = 'NN';
public string $phone = 'NN';
public int $participants = 0;
public int $rounds = 0;
public ?int $best_time = NULL;
2022-03-07 06:13:17 +00:00
2022-03-09 12:11:12 +00:00
/**
* PHP by default does not include multi byte functions. Therefore we use this
*/
2022-03-14 09:00:19 +00:00
private function count_characters(string $string): int
2022-03-09 12:11:12 +00:00
{
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-04-12 22:52:10 +00:00
public function setPhone(string $phone): Self
2022-03-07 06:13:17 +00:00
{
2022-04-12 22:52:10 +00:00
if ($this->longerThan($phone, 20))
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-04-12 22:52:10 +00:00
if ($participants > 9999)
2022-03-09 12:11:12 +00:00
{
2022-04-12 22:52:10 +00:00
throw new InvalidArgumentException("Too many participants!");
2022-03-09 12:11:12 +00:00
}
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-04-27 14:32:20 +00:00
if ($rounds > 99999)
2022-03-09 12:11:12 +00:00
{
2022-04-12 22:52:10 +00:00
throw new InvalidArgumentException("Too many rounds!");
2022-03-09 12:11:12 +00:00
}
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
}