-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgallery.php
225 lines (197 loc) · 6.53 KB
/
gallery.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
<?php
require_once "../config.php";
use \Tsugi\Blob\BlobUtil;
require_once "peer_util.php";
use \Tsugi\UI\Table;
use \Tsugi\Core\LTIX;
// Sanity checks
$LAUNCH = LTIX::requireData();
$p = $CFG->dbprefix;
$row = loadAssignment();
$assn_json = null;
$assn_id = false;
if ( $row !== false && U::isNotEmpty($row['json']) ) {
$assn_json = json_decode(upgradeSubmission($row['json']));
$assn_id = $row['assn_id'];
}
if ( $assn_id === false ) {
die('Assignment not configured');
}
if ( $assn_json->gallery == 'off' ) {
die('Gallery not enabled for assignment');
}
// Load the assignment data
if ( $USER->instructor || $assn_json->gallery == 'always') {
// It is all good
} else {
$submit_row = loadSubmission($assn_id, $USER->id);
if ( $submit_row === false ) {
die('You have not yet submitted your assignment');
}
}
// Gets counts and max of the submissions
$query_parms = array(":LID" => $LINK->id, ":CUR_USER" => $USER->id);
if ( $USER->instructor ) {
$orderfields = array("S.user_id", "S.rating", "my_rating", "displayname", "email", "S.created_at", "S.updated_at", "user_key", "max_score", "scores", "flagged", "min_score", "inst_points", "S.note");
$searchfields = array("S.user_id", "displayname", "email", "S.created_at", "S.updated_at", "user_key", "S.note");
} else {
$orderfields = array("S.created_at", "S.updated_at", "my_rating", "S.rating");
$searchfields = false;
if ( $assn_json->notepublic == "true" ) {
$orderfields[] = "note";
$searchfields = array("S.note");
}
}
// Load up our data dpending on the kind of assessment we have
$inst_points = $assn_json->instructorpoints > 0 ? "inst_points, " : "";
$max_min_scores = $assn_json->peerpoints > 0 ? "MAX(G.points) as max_score, MIN(G.points) AS min_score," : "";
$ratings = $assn_json->rating > 0 ? "S.rating AS rating," : "0 AS rating,";
$count_scores = $assn_json->maxassess > 0 ? "COUNT(G.points) as scores," : "";
$sql =
"SELECT S.user_id AS user_id, displayname, email, S.json, S.submit_id as _submit_id, S.note AS note,
$max_min_scores
$ratings
$count_scores
$inst_points
G2.rating AS my_rating,
COUNT(DISTINCT flag_id) as flagged,
MAX(G.updated_at) AS updated_at, user_key,
S.created_at
FROM {$p}peer_assn AS A JOIN {$p}peer_submit as S
ON A.assn_id = S.assn_id
LEFT JOIN {$p}peer_grade AS G
ON S.submit_id = G.submit_id
LEFT JOIN {$p}peer_grade AS G2
ON S.submit_id = G2.submit_id AND G2.user_id = :CUR_USER
LEFT JOIN {$p}peer_flag AS F
ON S.submit_id = F.submit_id
JOIN {$p}lti_user AS U
ON S.user_id = U.user_id
WHERE A.link_id = :LID
GROUP BY S.submit_id";
// View
$OUTPUT->header();
?>
<style>
li {padding-top: 0.5em;}
pre {padding-left: 2em;}
.card {
border: 1px solid black;
margin: 5px;
padding: 5px;
}
#loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: white;
margin: 0;
z-index: 100;
}
#XbasicltiDebugToggle {
display: none;
}
</style>
<script>
let html_loads = [];
</script>
<?php
$OUTPUT->bodyStart();
$OUTPUT->topNav();
$OUTPUT->flashMessages();
$OUTPUT->welcomeUserCourse();
// Make us a paged table - leave default sort order "whatever"
$parm = $_GET;
$parm['page_length'] = 40; // Make twice as long
$newsql = Table::pagedQuery($sql, $query_parms, $searchfields, $orderfields, $parm);
$rows = $PDOX->allRowsDie($newsql, $query_parms);
$view = Table::makeUrl("gallery-detail.php",$parm);
if ( $assn_json->galleryformat == 'table' ) {
$newrows = array();
foreach($rows as $row ) {
$newrow = array();
$submit_json = json_decode($row['json']);
$newrow['user_id'] = $row['user_id'];
$note = $submit_json->notes;
if ( U::isEmpty($note) ) $note = "Note missing.";
if ( strlen($note) > 200 ) {
$note = substr($note, 0, 200);
}
$newrow['description']= $note;
$newrow['rating'] = $row['rating'];
$newrow['my_rating'] = $row['my_rating'];
$newrows[] = $newrow;
}
Table::pagedTable($newrows, $searchfields, $orderfields, $view, $parm, array('Exit' => 'index'));
$OUTPUT->footer();
return;
}
Table::pagedHeader($rows, $searchfields, $orderfields, $view, $parm, array('Exit' => 'index'));
echo '<div id="box">'."\n";
if (count($rows) == 0 ) {
echo("<p>No entries to display</p>");
}
foreach($rows as $row ) {
$more = false;
$user_id = $row['user_id']+0;
$submit_json = json_decode($row['json']);
$inline = false;
if ( count($assn_json->parts) == 1 ) {
$part = $assn_json->parts[0];
if ( $part->type == 'content_item' || $part->type == 'url' ) $inline = true;
if ( $part->type == 'image' ) $inline = true;
}
// For now
$inline = false;
if ( count($submit_json->blob_ids) > 0 ) $more = true;
if ( (count($submit_json->content_items) + count($submit_json->urls)) > 1 ) $more = true;
$note = $submit_json->notes;
if ( U::isEmpty($note) ) $note = "Note missing.";
if ( strlen($note) > 200 ) {
$note = substr($note, 0, 200);
$more = true;
}
// Until we have rating inline
if ( $assn_json->rating > 0 ) {
$more = true;
}
echo('<div style="border: 2px, solid, red;" class="card">');
echo("<center>\n");
if ( $inline ) {
showSubmission($assn_json, $submit_json, $assn_id, $user_id);
} else {
if ( $USER->id == $row['user_id'] ) {
echo('<span style="color: green;">'.htmlentities($note)."</span>\n");
} else {
echo(htmlentities($note)."\n");
}
}
$text = "Rate";
if ( $assn_json->rating > 0 ) $text = "More / Rate";
if ( isset($row['rating']) && $row['rating'] > 1 ) {
echo("<br/>Rating: ".$row['rating']."\n");
echo('(<a href="gallery-detail.php?user_id='.$row['user_id'].'">'.$text.'</a>)');
} else if ( $more ) {
echo('(<a href="gallery-detail.php?user_id='.$row['user_id'].'">'.$text.'</a>)');
}
if ( $USER->instructor ) {
echo('<br/>Admin: <a href="gallery-student.php?user_id='.$row['user_id'].'">Detail</a>');
}
echo("</center>\n");
echo("</div>\n");
}
echo("</div>\n");
$OUTPUT->footerStart();
// https://github.com/LinZap/jquery.waterfall
?>
<script type="text/javascript" src="<?= $CFG->staticroot ?>/js/waterfall-light.js"></script>
<script>
$(function(){
$('#box').waterfall({refresh: 0})
});
</script>
<?php
load_htmls();
$OUTPUT->footerEnd();