horaire v0.1.0
davvalent

davvalent commited on 2022-05-29 15:41:19
Showing 1 changed files, with 142 additions and 22 deletions.

... ...
@@ -1,52 +1,172 @@
1 1
 <?php
2
-//
2
+
3 3
 try {
4 4
 
5
+  require 'parse-ini.php';
6
+
5 7
   $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
6 8
   $bdd = new PDO(
7
-    'mysql:host=localhost;dbname=ntnlvca_wplbd',
8
-    'david',
9
-    'kt3;Dv2?Wan9f/',
10
-    $pdo_options
9
+    $infos['db_name'],
10
+    $infos['db_user'],
11
+    $infos['db_pwd']
11 12
   );
12 13
 
13 14
   $bdd->exec("SET CHARACTER SET utf8");
14 15
 
15
-  $req = $bdd -> prepare('SELECT post_date, meta_value
16
+  $req = $bdd->prepare('SELECT
17
+      wplg_posts.ID,
18
+      post_date AS date,
19
+      wplg_postmeta.meta_id AS team_meta_id,
20
+      wplg_postmeta.meta_value AS team_id,
21
+      abbrev.meta_value AS team_abbreviation
16 22
     FROM wplg_posts
17
-    INNER JOIN wplg_postmeta ON ID = post_id
23
+    INNER JOIN wplg_postmeta
24
+      ON ID = wplg_postmeta.post_id
25
+    INNER JOIN (SELECT post_id, meta_value
26
+        FROM wplg_postmeta
27
+        WHERE meta_key = "sp_abbreviation") AS abbrev
28
+      ON abbrev.post_id = wplg_postmeta.meta_value
18 29
     WHERE post_type = "sp_event"
19
-      AND DATE_FORMAT(post_date,"%Y-%m-%d") = DATE_FORMAT("2021-09-19","%Y-%m-%d") # CURRENT_DATE()
20
-      AND meta_key IN ("sp_team","sp_results")
21
-    ORDER BY post_date;'
30
+      AND DATE_FORMAT(post_date,"%Y-%m-%d") = DATE_FORMAT(CURRENT_DATE(),"%Y-%m-%d") # CURRENT_DATE()
31
+      AND meta_key IN ("sp_team")
32
+    ORDER BY post_date, meta_id'
22 33
     );
23 34
 
24 35
   $req->execute();
25
-  $results = $req -> fetchAll(PDO::FETCH_ASSOC);
26
-
27
-  $display = ($results)
28
-    ? var_dump($results)
29
-    : "Pas de matchs à l'horaire aujourd'hui.";
30 36
 
31
-  echo $display;
37
+  // tableaux des résultats
38
+  $raw_data_matchs = $req->fetchAll(PDO::FETCH_ASSOC);
32 39
 
33
-  // Boucle pour parcourir la table des résultats
34
-  /*
35
-  while ($donnees = $req_donneesensg -> fetch()) {
40
+  $date = date("Y/m/d");
41
+  $h1_title = ($raw_data_matchs)
42
+    ? "Matchs à l’horaire - " . $date
43
+    : "Pas de matchs à l’horaire aujourd’hui - " . $date;
36 44
 
37
-  }
38
-  */
45
+  if (!$raw_data_matchs)
46
+    $match_informations = [];
39 47
 
40 48
   // Fermeture de la requête et de la base de données
41 49
   $req->closeCursor();
42 50
   $bdd = null;
43 51
 
52
+  foreach ($raw_data_matchs as $i => $a) { // i est un index; a est un array
53
+
54
+    // match_informations sont des valeurs à afficher
55
+    $match_informations[$i]["ID"] = $a["ID"];
56
+    $match_informations[$i]["date"] = date_format(date_create($a["date"]), "md");
57
+    $match_informations[$i]["time"] = date_format(date_create($a["date"]), "Hi");
58
+
59
+    $is_first_index = ($i == 0) ? 1 : false;
60
+    $p_ID = ($is_first_index) ?: $match_informations[$i - 1]["ID"];
61
+
62
+    if ($a["ID"] == $p_ID)
63
+      $match_informations[$i]["away"] = $raw_data_matchs[$i - 1]["team_abbreviation"];
64
+    $match_informations[$i]["home"] = $a["team_abbreviation"];
65
+
44 66
   }
45 67
 
46
-catch(Exception $e) {
68
+  foreach ($match_informations as $key => $value) {
69
+
70
+    if ($key - 1 < 0)
71
+      continue;
72
+
73
+    if ($value["ID"] == $match_informations[$key - 1]["ID"])
74
+      unset($match_informations[$key - 1]);
75
+  }
76
+} catch(Exception $e) {
47 77
 
48 78
   die('Erreur : ' . $e->getMessage());
49 79
 
50 80
 }
51 81
 
52 82
 ?>
83
+<!DOCTYPE html>
84
+<html xmlns="http://www.w3.org/1999/xhtml" lang="fr-CA">
85
+<head>
86
+  <meta charset="utf-8"/>
87
+  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
88
+  <title>Horaire et pointage - LBD</title>
89
+  <style>
90
+    * {
91
+      box-sizing: border-box;
92
+    }
93
+    html {
94
+      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
95
+    }
96
+    body {
97
+      line-height: 1.5;
98
+      background-color: #f9f9f9;
99
+      color: #4a4a4a;
100
+      font-size: 1.5rem;
101
+      margin: 0;
102
+    }
103
+    h1 {
104
+      font-size: 1.5rem;
105
+      padding: 10px;
106
+    }
107
+    table {
108
+      width: 100%;
109
+      border-collapse: collapse;
110
+    }
111
+    tr:nth-child(4n+1),
112
+    tr:nth-child(4n+2) {
113
+      background: #e6e6e6;
114
+    }
115
+    td {
116
+      border: 2px solid grey;
117
+      position: relative;
118
+      font-weight: 700;
119
+    }
120
+    td div {
121
+      width: 100%;
122
+      text-align: center;
123
+    }
124
+    td.date-heure div:first-of-type,
125
+    td.away-home div:first-of-type {
126
+      color: grey;
127
+      top : 0;
128
+      text-align: left;
129
+      padding-left: 4px;
130
+      font-size: 1.15rem;
131
+      font-weight: normal;
132
+    }
133
+    td.date-heure div:first-of-type {
134
+      position: absolute;
135
+    }
136
+     td.away-home div:first-of-type {
137
+      position: relative;
138
+    }
139
+  </style>
140
+</head>
141
+<body>
142
+  <h1><?=$h1_title;?></h1>
143
+  <table>
144
+<?php foreach($match_informations as $mi): ?>
145
+    <tr>
146
+      <td class="away-home">
147
+        <div>Visiteur</div>
148
+        <div><?=$mi["away"];?></div>
149
+      </td>
150
+      <td class="date-heure" rowspan="2">
151
+        <div>Date</div>
152
+        <div><?=$mi["date"];?></div>
153
+      </td>
154
+      <td class="date-heure" rowspan="2">
155
+        <div>Heure</div>
156
+        <div><?=$mi["time"];?></div>
157
+      </td>
158
+    </tr>
159
+    <tr>
160
+      <td class="away-home">
161
+        <div>Domicile</div>
162
+        <div><?=$mi["home"];?></div>
163
+      </td>
164
+    </tr>
165
+<?php endforeach; ?>
166
+  <table>
167
+</body>
168
+</html>
169
+<?php/*
170
+  var_dump($raw_data_matchs);
171
+  var_dump($match_informations);
172
+*/?>
53 173
\ No newline at end of file
54 174