Browse Source

Add contest scoreboard

spaghetti 8 years ago
parent
commit
36f0c43f74

+ 7
- 0
design/privateheader.php View File

@@ -461,6 +461,13 @@ if ($NotificationsManager->is_traditional(NotificationsManager::TORRENTS)) {
461 461
   $NotificationsManager->clear_notifications_array();
462 462
 }
463 463
 
464
+// Contests
465
+if ($ContestSettings = G::$Cache->get_value('contest_settings')) {
466
+  if (time() > $ContestSettings['start'] && time() < $ContestSettings['end']) {
467
+    $Alerts[] = '<a href="/contest.php">A Contest is Underway!</a>';
468
+  }
469
+}
470
+
464 471
 if (check_perms('users_mod')) {
465 472
   $ModBar[] = '<a href="tools.php">Toolbox</a>';
466 473
 }

+ 99
- 0
sections/contest/contest.php View File

@@ -0,0 +1,99 @@
1
+<?
2
+if (!($ContestSettings = $Cache->get_value("contest_settings"))) {
3
+  $DB->query("
4
+  SELECT
5
+    Value,
6
+    Comment
7
+  FROM site_options
8
+  WHERE
9
+    Name='ContestRules'
10
+    OR Name='ContestTimes'
11
+    OR Name='ContestRewards'");
12
+  if ($DB->has_results()) {
13
+    list($QueryPart, $Rules)   = $DB->next_record();
14
+    list($StartTime, $EndTime) = $DB->next_record();
15
+    list($Amount, $Currency)   = $DB->next_record();
16
+  }
17
+  $ContestSettings = array(
18
+    'query'  => html_entity_decode($QueryPart),
19
+    'rules'  => $Rules,
20
+    'start'  => $StartTime,
21
+    'end'    => $EndTime,
22
+    'reward' => ($Amount.' '.$Currency.'/torrent')
23
+  );
24
+  $Cache->cache_value('contest_settings', $ContestSettings);
25
+}
26
+
27
+if (!($Scores = $Cache->get_value("contest_scores"))) {
28
+  $DB->query("
29
+  SELECT
30
+    u.Username,
31
+    u.ID,
32
+    COUNT(*) AS Uploads
33
+  FROM torrents AS t
34
+  LEFT JOIN torrents_group AS tg ON t.groupID=tg.ID
35
+  LEFT JOIN users_main AS u ON t.UserID=u.ID
36
+  WHERE
37
+    $ContestSettings[query]
38
+    AND UNIX_TIMESTAMP(t.Time) > $ContestSettings[start]
39
+    AND UNIX_TIMESTAMP(t.Time) < $ContestSettings[end]
40
+  GROUP BY UserID
41
+  ORDER BY Uploads DESC
42
+  LIMIT 50");
43
+
44
+  $Scores = $DB->to_array();
45
+  $Cache->cache_value('contest_scores', $Scores);
46
+}
47
+
48
+View::show_header('Contest');
49
+
50
+if (time() < $ContestSettings['start']) {
51
+  print '<h2>Future Contest (Starts in '.time_diff($ContestSettings['start'],2,false).')</h2>';
52
+} else if (time() > $ContestSettings['end']) {
53
+  print '<h2>Finished Contest</h2>';
54
+} else {
55
+  print '<h2>Ongoing Contest! ('.time_diff($ContestSettings['end'],2,false).' remaining)</h2>';
56
+}
57
+?>
58
+
59
+<div class="thin flex">
60
+  <div class="box pad grow">
61
+<? if ($Scores) { ?>
62
+    <h2 id="general">Scoreboard</h2>
63
+    <table width="100%" class="contest_scoreboard">
64
+      <tr class="colhead">
65
+        <td>Place</td>
66
+        <td>User</td>
67
+        <td>Score</td>
68
+      </tr>
69
+<?   foreach ($Scores as $Place => $Score) { ?>
70
+  <tr class="row">
71
+    <td><?=($Place+1)?></td>
72
+    <td><a href="/user.php?id=<?=$Score['ID']?>"><?=$Score['Username']?></a></td>
73
+    <td><?=$Score['Uploads']?></td>
74
+  </tr>
75
+<?   } ?>
76
+    </table>
77
+<? } else { ?>
78
+    <h2>No Scores Yet</h2>
79
+<? } ?>
80
+  </div>
81
+  <div class="shrink flex" style="margin-left: 1em; flex-direction: column;">
82
+    <div class="box pad">
83
+      <h2>Qualifications</h2>
84
+      <ul>
85
+<?
86
+  print '<li>'.str_replace('\n', '</li><li>', $ContestSettings['rules']).'</li>'
87
+?>
88
+      </ul>
89
+    </div>
90
+    <div class="box pad">
91
+      <h2>Rewards</h2>
92
+      <ul>
93
+        <li><?=$ContestSettings['reward']?></li>
94
+      </ul>
95
+    </div>
96
+  </div>
97
+</div>
98
+
99
+<? View::show_footer(); ?>

+ 4
- 0
sections/contest/index.php View File

@@ -0,0 +1,4 @@
1
+<?
2
+enforce_login();
3
+include(SERVER_ROOT.'/sections/contest/contest.php');
4
+?>

+ 1
- 0
sections/upload/upload_handle.php View File

@@ -946,6 +946,7 @@ if ($Type == 'Comics') {
946 946
 
947 947
 // Clear cache
948 948
 $Cache->delete_value("torrents_details_$GroupID");
949
+$Cache->delete_value("contest_scores");
949 950
 
950 951
 // Allow deletion of this torrent now
951 952
 $Cache->delete_value("torrent_{$TorrentID}_lock");

+ 10
- 0
static/styles/global.css View File

@@ -853,6 +853,16 @@ div.torrent_artists {
853 853
   width: 100%;
854 854
 }
855 855
 
856
+.flex {
857
+  display: flex;
858
+}
859
+.flex > .grow {
860
+  flex-grow: 1
861
+}
862
+.flex > .shrink {
863
+  flex-shrink: 1
864
+}
865
+
856 866
 input[type="search"] {
857 867
   -webkit-appearance: textfield;
858 868
 }

Loading…
Cancel
Save