-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviewdeck.php
More file actions
146 lines (140 loc) · 4.45 KB
/
Copy pathviewdeck.php
File metadata and controls
146 lines (140 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once "php/includes/start.php";
$id = $_GET['id'] ?? null;
$deckQuery = "SELECT
`decks`.`id`,
`decks`.`commander`,
`decks`.`partner`,
`decks`.`background`,
`players`.`id` AS `owner_id`,
`players`.`name`,
COUNT(DISTINCT `won games`.`id`) AS `wins`,
COUNT(DISTINCT `lost games`.`id`) AS `losses`,
COUNT(DISTINCT `won games`.`id`) / (COUNT(DISTINCT `won games`.`id`) + COUNT(DISTINCT `lost games`.`id`)) * 100 AS `win rate`
FROM `decks`
LEFT JOIN `players`
ON `decks`.`owner` = `players`.`id`
LEFT JOIN `game_participation` AS `played games`
ON `decks`.`id` = `played games`.`deck_id`
LEFT JOIN `games` AS `won games`
ON
`played games`.`game_id` = `won games`.`id` AND
`won games`.`winning_deck` = `decks`.`id`
LEFT JOIN `games` AS `lost games`
ON
`played games`.`game_id` = `lost games`.`id` AND
`lost games`.`winning_deck` <> `decks`.`id`
WHERE
`decks`.`id` = ? AND
(
(
`won games`.`date` >= ? AND
`won games`.`date` <= ?
) OR
(
`lost games`.`date` >= ? AND
`lost games`.`date` <= ?
)
)
GROUP BY `decks`.`id`;";
$deck = $pdo->prepare($deckQuery);
$deck->execute([
$id,
$settings['start_date'],
$settings['end_date'],
$settings['start_date'],
$settings['end_date']
]);
$deckData = $deck->fetch();
$gamesQuery = "SELECT `games`.`id` AS `id`, `games`.`date`, `players`.`id` AS `player id`, `players`.`name`, `games`.`winning_deck` FROM `game_participation` LEFT JOIN `games` ON `games`.`id` = `game_participation`.`game_id` LEFT JOIN `players` on `game_participation`.`player_id` = `players`.`id` WHERE `game_participation`.`deck_id` = ? ORDER BY `games`.`date` DESC, `games`.`id` DESC";
$games = $pdo->prepare($gamesQuery);
$games->execute([$id]);
$playerResultsQuery = "SELECT
`all_players`.`id`,
`all_players`.`name`,
COUNT(DISTINCT `won_games`.`id`) AS `wins`,
COUNT(DISTINCT `lost_games`.`id`) AS `losses`,
COUNT(DISTINCT `won_games`.`id`) / (COUNT(DISTINCT `won_games`.`id`) + COUNT(DISTINCT `lost_games`.`id`)) * 100 AS `win rate`
FROM `game_participation` AS `gpA`
LEFT JOIN `game_participation` AS `gp`
ON `gp`.`game_id` = `gpA`.`game_id` AND
`gp`.`deck_id` = ?
LEFT JOIN `players` AS `all_players`
ON `all_players`.`id` = `gp`.`player_id`
LEFT JOIN `games` AS `won_games`
ON `won_games`.`id` = `gp`.`game_id` AND
`won_games`.`winning_player` = `all_players`.`id`
LEFT JOIN `games` AS `lost_games`
ON `lost_games`.`id` = `gp`.`game_id` AND
`lost_games`.`winning_player` <> `all_players`.`id`
WHERE
(`won_games`.`date` >= ? AND
`won_games`.`date` <= ?) OR
(`lost_games`.`date` >= ? AND
`lost_games`.`date` <= ?)
GROUP BY `all_players`.`id`
HAVING `wins` > 0 OR `losses` > 0
ORDER BY `win rate` DESC;";
$playerResults = $pdo->prepare($playerResultsQuery);
$playerResults->execute([
$id,
$settings['start_date'],
$settings['end_date'],
$settings['start_date'],
$settings['end_date']
]);
require_once "php/includes/head.php";
?>
<?php
require_once "php/includes/header.php";
?>
<main>
<div class="left">
<h1><?= $deckData['partner'] != "" ? $deckData['commander']." // ".$deckData['partner'] : $deckData['commander'] ?></h1>
<div><span>By <a href="<?= $pages['viewplayer']['route'].$deckData['owner_id']."/"?>"><?= $deckData['name'] ?></a></span></div>
<div>
<span><?= $deckData['win rate']."% win rate ".$deckData['wins']."–".$deckData['losses'] ?></span>
</div>
</div>
<div class="middle">
<section>
<h2>Played By</h2>
<table>
<tr>
<th>Player</th>
<th>Wins</th>
<th>Losses</th>
<th>Win Rate / %</th>
</tr>
<?php foreach ($playerResults as $result): ?>
<tr>
<td><a href="<?= $pages['viewplayer']['route'].$result['id']."/" ?>"><?= $result['name'] ?></a></td>
<td><?= $result['wins'] ?></td>
<td><?= $result['losses'] ?></td>
<td><?= $result['win rate'] ?></td>
</tr>
<?php endforeach; ?>
</table>
</section>
<section>
<h2>Games Played</h2>
<table>
<tr>
<th>Game #</th>
<th>Date</th>
<th>Player</th>
</tr>
<?php while ($game = $games->fetch()): ?>
<tr class="<?= $game['winning_deck'] == $id ? "winner" : "loser" ?>">
<td><a href="<?= $pages['viewgame']['route'].$game['id']."/" ?>"?><?= $game['id'] ?></a></td>
<td><?= $game['date'] ?></td>
<td><a href="<?= $pages['viewplayer']['route'].$game['player id']."/" ?>"><?= $game['name'] ?></a></td>
</tr>
<?php endwhile; ?>
</table>
</section>
</div>
</main>
<?php require_once "php/includes/footer.php"; ?>