mirror of
https://github.com/appen-isen/site-interpromos.git
synced 2026-01-18 16:37:33 +01:00
add function (o get matches for a sport
This commit is contained in:
19
api.php
19
api.php
@@ -86,13 +86,22 @@
|
|||||||
APIErrors::internalError();
|
APIErrors::internalError();
|
||||||
}
|
}
|
||||||
case 'matchs' . 'GET' :
|
case 'matchs' . 'GET' :
|
||||||
$matchs = $db->getAllMatches();
|
if (empty($_GET['sport_id'])){
|
||||||
|
$matchs = $db->getAllMatches();
|
||||||
|
|
||||||
if ($matchs != NULL){
|
if ($matchs != NULL){
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
die(json_encode($matchs));
|
die(json_encode($matchs));
|
||||||
|
}else{
|
||||||
|
APIErrors::internalError();}
|
||||||
}else{
|
}else{
|
||||||
APIErrors::internalError();
|
$matchs = $db->getAllMatchesSport($_GET['sport_id']);
|
||||||
|
|
||||||
|
if ($matchs != NULL){
|
||||||
|
http_response_code(200);
|
||||||
|
die(json_encode($matchs));
|
||||||
|
}else{
|
||||||
|
APIErrors::internalError();}
|
||||||
}
|
}
|
||||||
case 'test' . 'GET' :
|
case 'test' . 'GET' :
|
||||||
|
|
||||||
|
|||||||
@@ -293,6 +293,26 @@ class Database
|
|||||||
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all matches in the bd with their type for a sport
|
||||||
|
*
|
||||||
|
* @param int $sportId
|
||||||
|
*
|
||||||
|
* @return ?array return null is there is no match in the db
|
||||||
|
*/
|
||||||
|
public function getAllMatchesSport(int $sportId): ?array {
|
||||||
|
$request = 'SELECT m.id, type, array_agg(p.team_id) "teams_id" from matches m
|
||||||
|
left join sports s on sport_id = s.id
|
||||||
|
right join participations p on match_id = m.id
|
||||||
|
where sport_id = :id group by m.id, s.name';
|
||||||
|
|
||||||
|
$statement = $this->PDO->prepare($request);
|
||||||
|
$statement->bindParam(":id", $sportId);
|
||||||
|
$statement->execute();
|
||||||
|
|
||||||
|
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all infor of a match
|
* Gets all infor of a match
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user