40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Core\Auth;
|
|
use App\Core\Database;
|
|
use App\Core\Request;
|
|
use App\Core\Response;
|
|
|
|
final class CatalogController
|
|
{
|
|
public function courts(): void
|
|
{
|
|
Response::json(Database::connection()->query('SELECT * FROM courts ORDER BY name')->fetchAll());
|
|
}
|
|
|
|
public function referees(): void
|
|
{
|
|
Response::json(Database::connection()->query('SELECT * FROM referees ORDER BY name')->fetchAll());
|
|
}
|
|
|
|
public function sanction(array $params): void
|
|
{
|
|
Auth::requireRole(['admin', 'delegate']);
|
|
$data = Request::json();
|
|
$stmt = Database::connection()->prepare(
|
|
'INSERT INTO sanctions (match_id, team_id, player_id, card_type, reason)
|
|
VALUES (:match_id, :team_id, :player_id, :card_type, :reason)'
|
|
);
|
|
$stmt->execute([
|
|
'match_id' => (int) $params['id'],
|
|
'team_id' => $data['team_id'] ?? null,
|
|
'player_id' => $data['player_id'] ?? null,
|
|
'card_type' => $data['card_type'] ?? 'yellow',
|
|
'reason' => $data['reason'] ?? null,
|
|
]);
|
|
Response::json(['created' => true], 201);
|
|
}
|
|
}
|