-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentwork.php
366 lines (302 loc) · 10.1 KB
/
studentwork.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Prints a particular instance of a problem in the sort module.
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package mod
* @subpackage sort
* @copyright 2011 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/sort_comment_form.php');
$swid = optional_param('id', 0, PARAM_INT); // studentwork ID
$pid = optional_param('pid', 0, PARAM_INT); // pid
$studentwork = $DB->get_record('sort_studentwork',array('id' => $swid));
if ($studentwork) {
$this_studentwork = $studentwork;
$pid = $studentwork->pid;
}
else {
if (!$pid) {
print_error('That student sample or problem does not exist!');
}
}
$studentworks = $DB->get_records('sort_studentwork', array('pid' => $pid), 'name ASC');
$swids = "";
foreach ($studentworks as $studentwork) {
if ($swids == "") $swids = "($studentwork->id";
else $swids.= ",$studentwork->id";
}
$swids.=")";
if (optional_param('pid', 0, PARAM_INT)) {
if ($swids == ")") {
print_error("No " . get_string("samplename_plural","sort") . " have been created yet!");
}
$user_classification = $DB->get_record_select('sort_classification', "uid = $USER->id AND swid IN $swids ",array(),'*',IGNORE_MULTIPLE);
if (!$user_classification) {
redirect("problem.php?id=$pid","You need to sort some " . get_string("samplename_plural","sort") . " before you can examine these results");
}
$this_studentwork = $studentworks[$user_classification->swid];
$swid = $this_studentwork->id;
}
$problem = $DB->get_record('sort_problem',array('id'=>$this_studentwork->pid));
$sort = $DB->get_record('sort', array('id' => $problem->sid));
$course = $DB->get_record('course',array('id' => $sort->course));
if ($course->id) {
$cm = get_coursemodule_from_instance('sort', $sort->id, $course->id, false, MUST_EXIST);
}
else {
error('Could not find the problem sort activity or course!');
}
$has_explain = $sort->has_explain;
// require_login has to come before additional settings to the $PAGE variable, or somethings (like
// pagelayout are lost -- CR
require_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Set the page info
$PAGE->set_url('/mod/sort/studentwork.php', array('id' => $swid));
$PAGE->set_title(format_string("Viewing $this_studentwork->name"));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
$PAGE->add_body_class('sort-student-work-view');
$PAGE->requires->css('/mod/sort/css/jquery-ui.css');
$PAGE->requires->js('/mod/sort/scripts/jquery.min.js');
$PAGE->requires->js('/mod/sort/scripts/sort-comments.js');
$PAGE->requires->css('/mod/sort/css/sort.css');
$PAGE->requires->js('/mod/sort/scripts/jquery-ui.min.js');
sort_set_display_type($sort);
add_to_log($course->id, 'sort', 'view', "studentwork.php?id=$swid", $this_studentwork->name, $cm->id);
// Get categories from sort object.
$categories = sort_get_categories($sort->id, $context);
$arguments = array(
'contextid' => $context->id,
'component' => 'mod_sort',
'filearea' => 'studentwork',
);
$image = $DB->get_record_select('files', "filesize <> 0 AND component = 'mod_sort' AND contextid = '$context->id' AND filearea= 'studentwork' AND itemid = $swid");
$this_classification = $DB->get_record('sort_classification', array('swid' => $swid, 'uid' => $USER->id));
if (!$this_classification) {
print_error('You haven\'t sorted this ' . get_string("samplename","sort") . ' yet!');
}
$mform = new sort_comment_form("studentwork.php?id=$swid", array('classification' => $this_classification));
$classifications = $DB->get_records_select('sort_classification',"uid = $USER->id AND swid IN $swids ", NULL, 'commenttime ASC');
foreach($classifications as $classification) {
$classifications_indexed[$classification->swid] = $classification;
}
$score_totals = unserialize($problem->previous_data);
$uids = array();
$all_classifications = $DB->get_records('sort_classification', array('swid' => $swid));
/* START: prefill code: TO REMOVE */
$prefill = array(
84 => array(
7 => 0,
8 => 7,
9 => 0,
10 => 3,
),
83 => array(
7 => 9,
8 => 0,
9 => 0,
10 => 1,
),
82 => array(
7 => 0,
8 => 0,
9 => 10,
10 => 0,
),
81 => array(
7 => 10,
8 => 0,
9 => 0,
10 => 0,
),
80 => array(
7 => 0,
8 => 0,
9 => 8,
10 => 2,
),
79 => array(
7 => 0,
8 => 10,
9 => 0,
10 => 0,
),
78 => array(
7 => 0,
8 => 8,
9 => 0,
10 => 2,
),
77 => array(
7 => 0,
8 => 0,
9 => 10,
10 => 0,
),
76 => array(
7 => 0,
8 => 0,
9 => 10,
10 => 0,
),
75 => array(
7 => 10,
8 => 0,
9 => 0,
10 => 0,
),
74 => array(
7 => 0,
8 => 0,
9 => 8,
10 => 2,
),
73 => array(
7 => 8,
8 => 0,
9 => 0,
10 => 2,
),
72 => array(
7 => 2,
8 => 0,
9 => 4,
10 => 4,
),
71 => array(
7 => 0,
8 => 7,
9 => 0,
10 => 3,
),
70 => array(
7 => 0,
8 => 0,
9 => 10,
10 => 0,
),
);
/* END: prefill code TO REMOVE */
if ($pid == 6) {
for ($i = 7; $i <= 10; $i++) {
$score_totals[$i] = $prefill[$swid][$i];
}
}
foreach($all_classifications as $classification) {
$score_totals[$classification->category] += 1;
$uids[] = $classification->uid;
}
$all_votes_total = array_sum($score_totals);
foreach ($score_totals as $key=>$total) {
$percentages[$key] = round($total/$all_votes_total * 100);
}
$users = $DB->get_records_list('user','id',$uids);
if ($results = $mform->get_data()) {
$this_classification->commenttext = $results->commenttext['text'];
$this_classification->commenttime = time();
$DB->update_record('sort_classification', $this_classification);
redirect("studentwork.php?id=$swid");
}
echo $OUTPUT->header();
$sw_links = array();
echo "<div class='sort-student-work-pager'>";
echo "<h4>Select a work sample to view</h4>";
echo "<ul>";
foreach ($studentworks as $studentwork) {
if (isset($classifications_indexed[$studentwork->id])) {
$classes = ($studentwork->id == $swid) ? " class='sort-pager-current' " : "";
$sw_links[$studentwork->name] = "<li$classes><a href='studentwork.php?id=$studentwork->id'>$studentwork->name</a></li>";
}
}
ksort($sw_links);
foreach ($sw_links as $link) {
echo $link;
}
echo "</ul>";
echo "</div>";
echo "<div class='sort-student-work-wrapper'>";
echo $OUTPUT->heading("Sample " . $this_studentwork->name);
echo "<div class='sort-work-sample-wrapper'>";
echo "<div class='sort-work-sample'>";
echo "<img src='" . sort_get_image_file_url($image) . "' class='sort-work-sample-image' />";
echo "</div>";
echo "</div>";
echo "<div class='sort-classification-wrapper'>";
echo "<div class='sort-user-classification-wrapper'><div class='sort-user-classification'>";
echo "<h3>How did I sort the work?</h3>";
$cat_index = $this_classification->category;
echo "<p><em>" . $categories[$cat_index]->category . "</em></p>";
echo "</div></div>";
echo "<div class='sort-others-classification-wrapper'><div class='sort-others-classification'>";
echo "<h3>How have others sorted the work?</h3>";
echo "<table class='sort-others-table'>";
foreach ($percentages as $cat_index => $precentage) {
echo "<tr><td><em>" . $categories[$cat_index]->category . "</em></td><td>" . $precentage . "% (" . $score_totals[$cat_index] ." classifications)</td></tr>";
}
echo "</table>";
echo "</div></div>";
echo "</div>";
if ($has_explain) {
/*
echo '<div class="sort-studentwork-comment-form">';
echo "<h3 class='sort-studentwork-comment-form-header'><span class='ui-icon ui-icon-triangle-1-e sort-explanation-triangle'></span><span class='sort-explanation-header'>My Explanation - Give reasons for your classification</span></h3>";
echo "<div class='sort-studentwork-comment-form-body'>";
if (isset($this_classification->commenttime)) unset($this_classification->commenttime);
echo $mform->display();
echo "</div>";
echo "</div>";
*/
echo '<div class="sort-studentwork-comments">';
echo "<h3>Explanations</h3>";
echo "<p>View other participant's explanations.</p>";
echo "<div id='sort-filter-container' >Filter: <select id='sort-comment-filter'>";
echo "<option value='0'>- All -</option>";
foreach ($categories as $cat_id => $category) {
echo "<option value='$cat_id'>$category->category</option>";
}
echo "</select></div>
";
$first = true;
foreach ($all_classifications as $classification) {
if (!is_null($classification->commenttext)) {
$class = "sort-comment-box sort-comment-category-$classification->category";
if ($first) {
$first = false;
$class .= ' sort-comment-first';
}
echo "<div class='$class'>";
//echo "<div class='sort-comment-username'><strong>" . $users[$classification->uid]->username . "</strong> - <em>" . $categories[$classification->category]->category . "</em></div> ";
echo "<div class='sort-comment-username'><em>" . $categories[$classification->category]->category . "</em></div> ";
echo "<div class='sort-comment-body'>" . format_text($classification->commenttext) . "</div>";
echo "</div>";
}
}
echo '</div>';
}
echo "<div class='sort-action-links'>";
echo '<span class="sort-back-problem-link-box"><a href="problem.php?id=' . $problem->id . '">Back to Sort</a></span>';
echo "</div>";
echo "</div>";
// Finish the page
echo $OUTPUT->footer();