-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathladder.php
105 lines (80 loc) · 2.42 KB
/
ladder.php
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
<?php
/*
* LADDER.PHP
* ==========
*
* Shows ladder of the best users.
*/
require_once "mysqlStuff.php";
/**
* Gets info from DB about users and their xp points.
*
* @return array, where each item consists of array:
* [0] = login of user
* [1] = user's ID
* [2] = amount of xp
* sorted descendent by xp
*/
function getUsersAndXp() {
$con = db_connect();
// pom je pomocný sloupec, který dovoluje více stejně ohodnocených příkladů
// a disk. příspěvků, aby prošly UNIONem; musí v něm být pokaždé jiná hodnota
$query = "SELECT login, userid, xp
FROM
(SELECT userid, SUM(xp) as xp
FROM
(SELECT userid, xp, 1223*discussionid AS pom
FROM discussion
UNION
SELECT userid, xp, 1229*problemid AS pom
FROM problemsolve NATURAL JOIN problem
) AS BTABLE
GROUP BY userid
) AS CTABLE
NATURAL JOIN user
WHERE xp > 0
ORDER BY xp DESC, login ASC"; // je to prasárna, já vim, ale funguje to.
$resultSet = $con->query($query);
while ($row = $resultSet->fetch_array()) {
$result[] = array($row["login"], $row["userid"], $row["xp"]);
}
$con->close();
return $result;
}
?>
<center>
<h1>Žebříček uživatelů</h1>
<?php
$usersAndXp = getUsersAndXp();
if(! $usersAndXp) {
showFrame("V žebříčku se zatím nikdo neumístil.", false);
} else {
?>
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th>Místo</th>
<th>Uživatel</th>
<th>Počet xp</th>
</tr>
<?php
$place = 0; // current place in ladder
$currentXp = 10000000; // currently highest xp, max possible at the beginning
foreach ($usersAndXp as $item) {
if($item[2] != $currentXp) { //next user has lower place in ladder
$place++;
$currentXp = $item[2];
}
?>
<tr>
<td><?php echo $place ?>.</td>
<td><a href="index.php?page=profile&userid=<?php echo $item[1] ?>"><?php echo $item[0] ?></a></td>
<td><?php echo $item[2] ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</center>