-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranked.php
230 lines (188 loc) · 7.66 KB
/
ranked.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/*
Copyright (C) 2008-2009 Gilles Dubuc (www.kouiskas.com - [email protected])
Display the HOF entries ordered by rank
*/
require_once(dirname(__FILE__).'/entities/community.php');
require_once(dirname(__FILE__).'/entities/communitymoderator.php');
require_once(dirname(__FILE__).'/entities/competition.php');
require_once(dirname(__FILE__).'/entities/competitionlist.php');
require_once(dirname(__FILE__).'/entities/entry.php');
require_once(dirname(__FILE__).'/entities/entrylist.php');
require_once(dirname(__FILE__).'/entities/entryvotelist.php');
require_once(dirname(__FILE__).'/entities/theme.php');
require_once(dirname(__FILE__).'/entities/user.php');
require_once(dirname(__FILE__).'/utilities/page.php');
require_once(dirname(__FILE__).'/utilities/string.php');
require_once(dirname(__FILE__).'/utilities/token.php');
require_once(dirname(__FILE__).'/utilities/ui.php');
require_once(dirname(__FILE__).'/constants.php');
require_once(dirname(__FILE__).'/settings.php');
$user = User::getSessionUser();
$uid = $user->getUid();
$cid = isset($_REQUEST['cid'])?$_REQUEST['cid']:null;
if ($cid === null) {
header('Location: '.$PAGE['HALL_OF_FAME'].'?lid='.$user->getLid());
exit(0);
}
try {
$competition = Competition::get($cid);
} catch (CompetitionException $e) {
header('Location: '.$PAGE['HALL_OF_FAME'].'?lid='.$user->getLid());
exit(0);
}
if ($competition->getStatus() != $COMPETITION_STATUS['CLOSED']) {
header('Location: '.$PAGE['VOTE'].'?lid='.$user->getLid());
exit(0);
}
try {
$community = Community::get($competition->getXid());
} catch (CommunityException $e) {
header('Location: '.$PAGE['HALL_OF_FAME'].'?lid='.$user->getLid());
exit(0);
}
$theme = Theme::get($competition->getTid());
$page = new Page('HALL_OF_FAME', 'COMPETITIONS', $user);
$page->setTitle('<translate id="RANKED_PAGE_TITLE">Rankings in the "<string value="'.String::fromaform($theme->getTitle()).'"/>" competition of the <string value="'.String::fromaform($community->getName()).'"/> community on inspi.re</translate>');
$page->startHTML();
$page->addStyle('GRID');
$page->addRSS($RSS['COMPETITION'].'?cid='.$cid.'&uid='.$uid);
echo UI::RenderCompetitionShortDescription($user, $competition, $PAGE['GRID'].'?cid='.$cid, true);
$entrylist = Entrylist::getByCidAndStatusRandomized($uid, $cid, $ENTRY_STATUS['POSTED']);
$entrylist = array_merge($entrylist, Entrylist::getByCidAndStatusRandomized($uid, $cid, $ENTRY_STATUS['DELETED']));
if ($user->getStatus() == $USER_STATUS['BANNED']) {
$entrylist = array_merge($entrylist, array_values(Entrylist::getByCidAndStatus($cid, $ENTRY_STATUS['BANNED'])));
$bannedranks = $competition->getBannedRanks();
$entriesamount = count($entrylist);
} else $entriesamount = $competition->getEntriesCount();
if (empty($entrylist)) {
echo '<div class="listing_item">',
'<div class="listing_header">',
'<translate id="GRID_VOTE_NO_ENTRIES">',
'There were no entries in this competition. Nothing to vote on, unfortunately!',
'</translate>',
'</div> <!-- listing_header -->',
'</div> <!-- listing_item -->';
} else {
$rankedlist = array();
$unorderedlist = array();
$entry = array();
$author = array();
foreach ($entrylist as $author_uid => $eid) {
try {
$entry[$eid] = Entry::get($eid);
try {
$author[$eid] = User::get($entry[$eid]->getUid());
} catch (UserException $e) {
$author[$eid] = null;
}
if ($user->getStatus() == $USER_STATUS['BANNED']) $rank = $bannedranks[$eid];
else $rank = $entry[$eid]->getRank();
if ($author[$eid] == null || $rank < 4 || $author[$eid]->getDisplayRank()) {
$rankedlist[$eid] = $rank;
} else $unorderedlist[]= $eid;
} catch (EntryException $e) {}
}
if (!empty($rankedlist)) {
echo '<div class="hint">',
'<div class="hint_title">',
'<translate id="RANKED_ORDERED_TITLE">',
'Ordered entries',
'</translate>',
'</div> <!-- hint_title -->',
'<translate id="RANKED_ORDERED_BODY">',
'The rank of these artworks is public. They either ranked in the top 3 or their author decided to share their rank publicly.',
'</translate>',
'</div> <!-- hint -->',
'<div id="ordered_list">';
asort($rankedlist);
foreach ($rankedlist as $eid => $rank) {
$pid = $entry[$eid]->getPid();
$author_uid = $entry[$eid]->getUid();
$votes = EntryVoteList::getByEidAndStatus($eid, $ENTRY_VOTE_STATUS['CAST']);
$own_vote = 0;
try {
$own_vote = EntryVote::get($eid, $uid);
$own_vote = $own_vote->getPoints();
} catch (EntryVoteException $e) {}
$amount = count($votes);
$score = array_sum($votes);
echo '<div class="ranked_item_container">',
'<picture class="ranked_picture clearboth" href="',$PAGE['ENTRY'],'?lid='.$user->getLid().'#eid='.$eid.'" '.($pid === null?'':'pid="'.$pid.'"').' size="small"/>',
'<div class="rank"><rank value="',$rank,'"/></div>',
'<profile_picture class="ranked_picture" uid="',$author_uid,'" size="small"/>',
'<div class="listing_item ranked_item">',
'<div class="listing_header">',
'<translate id="RANKED_AUTHOR_HEADER">',
'<user_name uid="',$author_uid,'"/> entered this artwork into the competition',
'</translate>',
'</div> <!-- listing_header -->',
'<div class="ranked_content">',
'<translate id="RANKED_SCORE_DETAILS">',
'It ranked <rank value="',$rank,'"/> out of <integer value="',$entriesamount,'"/>, thanks to <integer value="',$amount,'"/> vote(s) totalling <integer value="',$score,'"/> point(s).',
'</translate> ';
if ($own_vote == 0) {
echo '<translate id="RANKED_SCORE_DETAILS_OWN_VOTE_NULL">',
'You didn\'t vote on it.',
'</translate>';
} else {
echo '<translate id="RANKED_SCORE_DETAILS_OWN_VOTE">',
'You gave it <integer value="',$own_vote,'"/> star(s).',
'</translate>';
}
echo '</div> <!-- ranked_content -->',
'</div> <!-- listing_item -->',
'</div> <!-- ranked_item_container -->';
}
echo '</div> <!-- ordered_list -->';
}
if (!empty($unorderedlist)) {
echo '<div class="hint hintmargin">',
'<div class="hint_title">',
'<translate id="RANKED_UNORDERED_TITLE">',
'Unordered entries',
'</translate>',
'</div> <!-- hint_title -->',
'<translate id="RANKED_UNORDERED_BODY">',
'The rank of these artworks hasn\'t been made public',
'</translate>',
'</div> <!-- hint -->',
'<div class="small_grid">';
foreach ($unorderedlist as $eid) {
$pid = $entry[$eid]->getPid();
echo '<picture href="'.$PAGE['ENTRY'].'?lid='.$user->getLid().'#eid='.$eid.'" class="picture_grid" '.($pid === null?'':'pid="'.$pid.'"').' size="small"/>';
}
echo '</div> <!-- small_grid -->';
}
try {
$moderator = CommunityModerator::get($competition->getXid(), $uid);
$ismoderator = true;
} catch (CommunityModeratorException $e) {
$ismoderator = false;
}
// Show the disqualified entries if we have the right to disqualify/requalify them
if ($uid == $community->getUid() || $ismoderator) {
$entrylist = Entrylist::getByCidAndStatus($cid, $ENTRY_STATUS['DISQUALIFIED']);
if (!empty($entrylist)) {
echo '<div class="hint hintmargin">',
'<div class="hint_title">',
'<translate id="GRID_DISQUALIFIED">',
'Disqualified entries',
'</translate>',
'</div> <!-- hint_title -->',
'</div> <!-- hint -->',
'<div class="small_grid">';
foreach ($entrylist as $uid => $eid) try {
$entry = Entry::get($eid);
$pid = $entry->getPid();
echo '<picture href="',$PAGE['ENTRY'],'?lid=',$user->getLid(),'#eid=',$eid,'" class="picture_grid" ',($pid === null?'':'pid="'.$pid.'"'),' size="small"/>';
} catch (EntryException $e) {}
echo '</div> <!-- small_grid -->';
}
}
}
?>
<?php
$page->endHTML();
$page->render();
?>