Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Upravuje data týmu
Zobrazí data týmu

## `POST /player`
**Params**: `first_name`, `last_name`, `birth_date`, `sex`, `[email]`, `[phone]`, `[gdpr_consent]`, `[nationality_id]`, `[personal_identification_number]`
**Params**: `first_name`, `last_name`, `birth_date`, `sex`, `[email]`, `[phone]`, `[gdpr_consent]`, `[nationality_id]`, `[personal_identification_number]`, `[jersey_number]`
**Auth**: token
Vytvoří nového hráče
**`first_name`**: Křestní jméno nového hráče
Expand All @@ -81,10 +81,11 @@ Vytvoří nového hráče
**`phone`**: Telefon na hráče (nepovinné)
**`gdpr_consent`**: Flag zda hráč poskytl souhlas se zpracováním osobních údajů (nepovinné)
**`nationality_id`**: ID národnosti hráče (nepovinné)
**`personal_identification_number`**: Rodné číslo hráče
**`personal_identification_number`**: Rodné číslo hráče
**`jersey_number`**: Číslo dresu

## `POST /player/{id}`
**Params**: `[first_name]`, `[last_name]`, `[birth_date]`, `[sex]`, `[email]`, `[phone]`, `[gdpr_consent]`, `[nationality_id]`, `[personal_identification_number]`
**Params**: `[first_name]`, `[last_name]`, `[birth_date]`, `[sex]`, `[email]`, `[phone]`, `[gdpr_consent]`, `[nationality_id]`, `[personal_identification_number]`, `[jersey_number]`
**Auth**: token, musí být správce týmu
Upraví data hráče
**`first_name`**: Křestní jméno nového hráče
Expand All @@ -96,6 +97,7 @@ Upraví data hráče
**`gdpr_consent`**: Flag zda hráč poskytl souhlas se zpracováním osobních údajů (nepovinné)
**`nationality_id`**: ID národnosti hráče (nepovinné)
**`personal_identification_number`**: Rodné číslo hráče
**`jersey_number`**: Číslo dresu

## `GET /player/{player_id}`
**Auth**: token, musí být správce týmu
Expand Down Expand Up @@ -176,11 +178,12 @@ Změní jméno soupisky pro tým na turnaji
Odstraní soupisku

## `POST /roster/{roster_id}/player/{player_id}`
**Params**: `roster_id`, `player_id`, [`role`]
**Params**: `roster_id`, `player_id`, [`role`], [`jersey_number`]
**Auth**: token, musí být správce soupisek nebo týmu
Přidá hráče na soupisku. Kontroluje duplicity - jeden hráč nemůže na stejné soupisce být víckrát se stejnou rolí, stejně. Stejně tak jeden hráč nemůže být na soupisce žádného jiného týmu na stejném turnaji, bez ohledu na role
Pro účely vyůčtování se ČALD poplatky počítají pouze pro hráče s rolí "player"
**`role`**: role uživatele na soupisce, může být jedna z [player | captain | spirit_captain | medical | coach | other_support ]. Není-li zadáno, je defaultní hodnota "player"
**`jersey_number`**: Číslo dresu (není-li vyplněno, vezme jako default číslo z hráčova profilu)

## `DELETE /roster/{roster_id}/player/{player_id}`
**Params**: `roster_id`, `player_id`, [`role`]
Expand Down
5 changes: 5 additions & 0 deletions data/migrations/deploy/00009_adding_numbers_to_players.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE player
ADD COLUMN jersey_number int(11);

ALTER TABLE player_at_roster
ADD COLUMN jersey_number int(11);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE player_at_roster
DROP COLUMN jersey_number;

ALTER TABLE player
DROP COLUMN jersey_number;
8 changes: 8 additions & 0 deletions src/App/Controller/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function create(\Slim\Http\Request $request, $response, $args)
$gdprConsent = trim($request->getParam("gdpr_consent"));
$nationalityID = trim($request->getParam("nationality_id"));
$personalIdentificationNumber = trim($request->getParam("personal_identification_number"));
$jerseyNumber = trim($request->getParam("jersey_number"));

$user = UserModel::loggedUser($request->getToken());

Expand All @@ -44,6 +45,9 @@ public function create(\Slim\Http\Request $request, $response, $args)
if (!empty($personalIdentificationNumber)) {
$p->setPersonalIdentificationNumber($personalIdentificationNumber);
}
if (!empty($jerseyNumber) && is_numeric($jerseyNumber)) {
$p->setJerseyNumber($jerseyNumber);
}
$p->save();

// Render index view
Expand All @@ -67,6 +71,7 @@ public function update(\Slim\Http\Request $request, $response, $args)
$gdprConsent = trim($request->getParam("gdpr_consent"));
$nationalityID = trim($request->getParam("nationality_id"));
$personalIdentificationNumber = trim($request->getParam("personal_identification_number"));
$jerseyNumber = trim($request->getParam("jersey_number"));

$p = \App\Model\Player::loadById($playerId);
if (!empty($email)) {
Expand Down Expand Up @@ -100,6 +105,9 @@ public function update(\Slim\Http\Request $request, $response, $args)
if (!empty($personalIdentificationNumber)) {
$p->setPersonalIdentificationNumber($personalIdentificationNumber);
}
if (!empty($jerseyNumber) && is_numeric($jerseyNumber)) {
$p->setJerseyNumber($jerseyNumber);
}

$p->save();

Expand Down
3 changes: 2 additions & 1 deletion src/App/Controller/Roster.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function addPlayer(\App\Request $request, $response, $args)
{
list($rosterId, $playerId) = $request->requireParams(['roster_id', 'player_id']);
$role = trim($request->getParam("role", PlayerAtRoster::DEFAULT_ROLE));
$jerseyNumber = trim($request->getParam("jersey_number", null));

$roster = \App\Model\Roster::loadById($rosterId);
if (!$roster) {
Expand All @@ -93,7 +94,7 @@ public function addPlayer(\App\Request $request, $response, $args)
throw new Http400("Player is already on roster of another team");
}

$roster = PlayerAtRoster::create($playerId, $rosterId, $role);
$roster = PlayerAtRoster::create($playerId, $rosterId, $role, $jerseyNumber);
$roster->save();

return $this->container->view->render(
Expand Down
17 changes: 14 additions & 3 deletions src/App/Model/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class Player extends \App\Model
self::SEX_FEMALE,
];

protected static $fields = ["id", "first_name", "last_name", "birth_date", "created_at", "email", "phone", "sex", "state", "nationality_id", "gdpr_consent", "personal_identification_number"];
protected static $fields = [
"id", "first_name", "last_name",
"birth_date", "created_at", "email",
"phone", "sex", "state",
"nationality_id", "gdpr_consent", "personal_identification_number",
"jersey_number"
];

public function getFullName()
{
Expand All @@ -35,8 +41,12 @@ public function getHomeTeam()
{
}

public static function create($firstName, $lastName, $sex, $email = null, $birthDate = null, $phone = null, $state = self::STATE_ACTIVE, $nationalityID = null, $gdprConsent = false, $personalIdentificationNumber = null)
{
public static function create($firstName, $lastName, $sex, $email = null, $birthDate = null, $phone = null, $state = self::STATE_ACTIVE, $nationalityID = null, $gdprConsent = false, $personalIdentificationNumber = null, $jerseyNumber = null)
{
if ($jerseyNumber !== null && $jerseyNumber !== "" && (int)$jerseyNumber <= 0) {
throw new WrongParam("Jersey number '{$this->getJerseyNumber()}' is not valid - it has to be higher than 0");
}

$i = new self();
$i->setFirstName($firstName);
$i->setLastName($lastName);
Expand All @@ -49,6 +59,7 @@ public static function create($firstName, $lastName, $sex, $email = null, $birth
$i->setGdprConsent($gdprConsent);
$i->setCreatedAt(date("Y-m-d H:i:s", time()));
$i->setPersonalIdentificationNumber($personalIdentificationNumber);
$i->setJerseyNumber($jerseyNumber);
return $i;
}

Expand Down
14 changes: 12 additions & 2 deletions src/App/Model/PlayerAtRoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@

class PlayerAtRoster extends \App\Model
{
protected static $fields = ["id", "player_id", "roster_id", "role"];
protected static $fields = ["id", "player_id", "roster_id", "role", "jersey_number"];

protected static $allowedRoles = ["player", "captain", "spirit_captain", "medical", "coach", "other_support"];

const DEFAULT_ROLE = "player";

public static function create($playerId, $rosterId, $role = PlayerAtRoster::DEFAULT_ROLE)
public static function create($playerId, $rosterId, $role = PlayerAtRoster::DEFAULT_ROLE, $jerseyNumber = null)
{
$i = new self();

if (empty($jerseyNumber) || !is_numeric($jerseyNumber)) {
$player = Player::loadById($playerId);
$jerseyNumber = $player->getJerseyNumber();
}

$i->setPlayerId($playerId);
$i->setRosterId($rosterId);
$i->setRole($role);
$i->setJerseyNumber($jerseyNumber);
$i->setSince(date("Y-m-d H:i:s", time()));

return $i;
Expand All @@ -28,6 +35,9 @@ protected function onSaveValidation()
if (!in_array($this->getRole(), self::$allowedRoles)) {
throw new WrongParam("Role {$this->getRole()} does not exist.");
}
if ($this->getJerseyNumber() < 0) {
throw new WrongParam("Jersey number '{$this->getJerseyNumber()}' is not valid - it has to be higher than 0");
}
if (self::exists(["player_id" => $this->getPlayerId(), "roster_id" => $this->getRosterId(), "role" => $this->getRole()])) {
throw new Duplicate("Player is already part of this team with same role");
}
Expand Down