+
+
\ No newline at end of file
diff --git a/public_html/css/styleList.css b/public_html/css/styleList.css
new file mode 100644
index 0000000..d368e19
--- /dev/null
+++ b/public_html/css/styleList.css
@@ -0,0 +1,27 @@
+.match_list {
+ display: flex;
+ justify-content: space-around;
+ margin-top: 5%;
+}
+
+.list {
+ margin-right: 5%;
+ width: 30%;
+}
+
+.capTeam {
+ margin: 1%;
+ align-items: center;
+ display: flex;
+ flex-direction: column;
+}
+
+.capsule {
+ display: flex;
+ justify-content: space-between;
+ margin: 5%;
+}
+
+.capTeam > h4 {
+ margin-top: 15%;
+}
\ No newline at end of file
diff --git a/public_html/js/script_direct.js b/public_html/js/script_direct.js
new file mode 100644
index 0000000..6afd4b4
--- /dev/null
+++ b/public_html/js/script_direct.js
@@ -0,0 +1,54 @@
+function parseISOLocal(s) {
+ var b = s.split(/\D/);
+ return new Date(b[0], b[1]+2, b[2], b[3], b[4], b[5]);
+}
+
+function getDirect() {
+ $.ajax({
+ method: "GET",
+ url: "api.php/matchs"
+ }).done((matchs) => {
+ aspect(matchs)
+ })
+}
+
+function aspect(matchs) {
+ $("#nextMatch").empty()
+ $("#nowMatch").empty()
+
+ matchs.forEach(match => {
+ let date = parseISOLocal(match['date'])
+ //show next matches with a gap of 20 min
+ if(date > Date.now() && date < (Date.now() + 1200000)){
+ let tname = JSON.parse(match['teams_name'])
+
+ let cap = "
"+
+ "
"+
+ "
"+ tname[0] +"
"+
+ "
"+
+ "
"+ tname[1] +"
"+
+ match['sport_name'] +"
";
+
+ $("#nextMatch").append(cap);
+ }
+ //show direct match with a gap of 20 min
+ if(date < Date.now() && date > (Date.now() - 1200000)){
+ let tname = JSON.parse(match['teams_name'])
+ let tscore = JSON.parse(match['scores'])
+
+ let cap = "
"+
+ "
"+
+ "
"+ tname[0] +"
"+
+ "
"+ tscore[0] + "
"+
+ "
"+
+ "
"+ tname[1] +"
"+
+ "
"+ tscore[1] +"
"+
+ match['sport_name'] +"
";
+
+ $("#nowMatch").append(cap);
+ }
+ });
+}
+
+getDirect();
+setInterval(getDirect, 5000 );
\ No newline at end of file
diff --git a/resources/database.php b/resources/database.php
index ae12be6..aa50bec 100644
--- a/resources/database.php
+++ b/resources/database.php
@@ -295,15 +295,16 @@ class Database
}
/**
- * Gets all matches in the db with their type
+ * Gets all matches in the database
*
* @return ?array return null if there is no match in the db
*/
public function getAllMatches(): ?array {
- $request = 'SELECT m.id, sport_id, s.name "sport_name", 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
- group by m.id, s.name';
+ $request = 'SELECT m.id "id", m.type "type", s.name "sport_name", ARRAY_TO_JSON(ARRAY_AGG(t.name ORDER BY p.team_id)) "teams_name", ARRAY_TO_JSON(ARRAY_AGG(p.score ORDER BY p.team_id)) "scores", m.date "date"
+ FROM matches m
+ LEFT JOIN sports s ON m.sport_id = s.id
+ INNER JOIN participations p ON m.id = p.match_id
+ INNER JOIN teams t ON t.id = p.team_id GROUP BY m.id, s.name ORDER BY m.date';
$statement = $this->PDO->prepare($request);
$statement->execute();