-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathassignment.class.php
More file actions
397 lines (325 loc) · 13 KB
/
assignment.class.php
File metadata and controls
397 lines (325 loc) · 13 KB
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php
// This file is part of the Sloodle project (www.sloodle.org)
/**
* This file defines the "Sloodle Object" assignment sub-type.
* It allows students to submit 3d objects in Second Life as Moodle assignments.
*
* @package sloodleprimdrop
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
*
* @contributor (various Moodle guys!)
* @contributor Peter R. Bloomfield
*/
/** Attempt to include the Sloodle configuration. */
require_once($CFG->dirroot.'/mod/sloodle/sl_config.php');
/** Include the general Sloodle functions. */
require_once($CFG->dirroot.'/mod/sloodle/lib/general.php');
/** Include the base assignment class, if necessary. */
require_once($CFG->dirroot.'/mod/assignment/lib.php');
// The assignment plugin seems to be calling this with require or include rather than require_once or include_once.
// Check if the class exists in case we've already defined it.
// mod/assignment/view.php?id=21
if ( !class_exists( 'assignment_sloodleobject' ) ) {
/**
* Extend the base assignment class for assignments where you submit an SL object in-world.
* This has been modified from the "assignment_online" type.
* @package sloodle
*/
class assignment_sloodleobject extends assignment_base {
function assignment_sloodleobject($cmid=0, $assignment=NULL, $cm=NULL, $course=NULL) {
parent::assignment_base($cmid, $assignment, $cm, $course);
$this->type = 'sloodleobject';
}
function view() {
// Bring in the global user data
global $USER;
// Check that this user can view assignments
$context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
require_capability('mod/assignment:view', $context);
// Fetch the submission data
$submission = $this->get_submission();
$sloodle_submission = new assignment_sloodleobject_submission();
$sloodle_submission->load_submission($submission);
$this->view_header();
$this->view_intro();
$this->view_dates();
// Display a texture summary of the submission
$this->print_box_start_compat('center', '70%', '', 0, 'generalbox', 'online');
$sloodle_submission->text_summary(false);
$this->print_box_end_compat();
$this->view_feedback();
$this->view_footer();
}
/*
* Display the assignment dates
*/
function view_dates() {
// Bring in the global user and configuration data
global $USER, $CFG;
// Make sure the time available and time due dates are set
if (!$this->assignment->timeavailable && !$this->assignment->timedue) {
return;
}
// Start a display box
$this->print_box_start_compat('center', '', '', 0, 'generalbox', 'dates');
echo '<table>';
// Display the time the assignment is available from
if ($this->assignment->timeavailable) {
echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>';
echo ' <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>';
}
// Display the time the assignment is due by
if ($this->assignment->timedue) {
echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
echo ' <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>';
}
// Is there a submission by this user?
$submission = $this->get_submission($USER->id);
if ($submission) {
// Convert the submission to a Sloodle assignment object
$sloodle_submission = new assignment_sloodleobject_submission();
$sloodle_submission->load_submission($submission);
// Display the date it was last updated
echo '<tr><td class="c0">'.get_string('lastedited').':</td>';
echo ' <td class="c1">'.userdate($submission->timemodified);
// Display the number of prims in the submission
$num_prims = $sloodle_submission->num_prims;
if ($num_prims == 0) $num_prims = '?';
echo ' ('.get_string('numprims', 'sloodle', $num_prims).')</td></tr>';
}
echo '</table>';
$this->print_box_end_compat();
}
/**
* Update the submission with the provided data.
* @param int $userid Integer ID of the user making the submission
* @param assignment_sloodleobject_submission $data A structure containing data about the Sloodle assignment submission
* @return bool True if successful, or false otherwise.
*/
function update_submission($userid, $data)
{
$submission = $this->get_submission($userid, true);
$update = new object();
$update->id = $submission->id;
$update->data1 = "{$data->obj_name}|{$data->num_prims}";
$update->data2 = "{$data->primdrop_name}|{$data->primdrop_uuid}|{$data->primdrop_region}|{$data->primdrop_pos}";
$update->timemodified = time();
return sloodle_update_record('assignment_submissions', $update);
}
function print_student_answer($userid, $return=true){
global $CFG;
$text = '';
if (!($submission = $this->get_submission($userid))) {
$text = '';
} else {
// Output the Submission data
$sloodle_submission = new assignment_sloodleobject_submission();
$sloodle_submission->load_submission($submission);
//$text = '<b>'.shorten_text(trim(strip_tags($sloodle_submission->obj_name)), 20).'</b><br>';
$text = '<div class="files">'.
'<img src="'.$CFG->pixpath.'/f/html.gif" class="icon" alt="html" />'.
link_to_popup_window ($CFG->wwwroot.'/mod/assignment/type/sloodleobject/file.php?id='.$this->cm->id.'&userid='.
$submission->userid, 'file'.$userid, shorten_text(trim(strip_tags($sloodle_submission->obj_name)), 20), 450, 580,
get_string('submission', 'assignment'), 'none', true).
'</div>';
}
if ($return) return $text;
echo $text;
}
function print_user_files($userid, $return=false) {
global $CFG;
if (!$submission = $this->get_submission($userid)) {
return '';
}
// Construct a Sloodle submission object
$sloodle_submission = new assignment_sloodleobject_submission();
$sloodle_submission->load_submission($submission);
// Display the number of prims
$num_prims = $sloodle_submission->num_prims;
if ($num_prims == 0) $num_prims = '?';
$this->print_box_start_compat('center', '', '', 0, 'generalbox', 'wordcount');
echo ' ('.get_string('numprims', 'sloodle', $num_prims).')';
$this->print_box_end_compat();
// Display the text summary of this submission
$this->print_box_compat($sloodle_submission->text_summary());
}
function preprocess_submission(&$submission) {
}
function setup_elements(&$mform) {
global $CFG, $COURSE;
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
$mform->addElement('select', 'resubmit', get_string("allowresubmit", "assignment"), $ynoptions);
//$mform->setHelpButton('resubmit', array('resubmit', get_string('allowresubmit', 'assignment'), 'assignment'));
$mform->setDefault('resubmit', 0);
$mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions);
//$mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment'));
$mform->setDefault('emailteachers', 0);
}
function print_box_compat($message) {
global $OUTPUT;
if ($OUTPUT && method_exists($OUTPUT, 'box')) {
print $OUTPUT->box($message);
} else {
print_simple_box($message);
}
}
function print_box_start_compat($p1, $p2, $p3, $p4, $p5, $p6) {
global $OUTPUT;
if ($OUTPUT && method_exists($OUTPUT, 'box_start')) {
print $OUTPUT->box_start();
} else {
print_simple_box_start($p1, $p2, $p3, $p4, $p5, $p6);
}
}
function print_box_end_compat() {
global $OUTPUT;
if ($OUTPUT && method_exists($OUTPUT, 'box_end')) {
print $OUTPUT->box_end();
} else {
print_simple_box_end();
}
}
}
/**
* Defines a submission for a Sloodle assignment.
* @package sloodle
*/
class assignment_sloodleobject_submission
{
/**
* Indicates whether or not a submission is loaded
* @var bool
* @access public
*/
var $is_loaded = false;
/**
* Name of the object which has been submitted.
* @var string
* @access public
*/
var $obj_name = '';
/**
* Number of prims in the object which has been submitted
* @var int
* @access public
*/
var $num_prims = 0;
/**
* Name of the PrimDrop object into which this object was submitted.
* @var string
* @access public
*/
var $primdrop_name = '';
/**
* UUID of the PrimDrop object into which this object was submitted.
* @var string
* @access public
*/
var $primdrop_uuid = '';
/**
* Name of the region where this object was submitted
* @var string
* @access public
*/
var $primdrop_region = '';
/**
* Position where this object was submitted (as a vector, "<x,y,z>")
* @var string
* @access public
*/
var $primdrop_pos = '';
/**
* Parses the data from a Submission database record object.
* @var object $submission The submission database record object.
*/
function load_submission($submission)
{
// Make sure the submission is valid
$this->is_loaded = false;
if ($submission == false || $submission == null) return;
// Parse the data lines
$object_data = explode('|', $submission->data1);
$primdrop_data = explode('|', $submission->data2);
// Make sure there's enough data in both
if (count($object_data) < 2 || count($primdrop_data) < 4) return;
// Extract the data items
$this->obj_name = $object_data[0];
$this->num_prims = (int)$object_data[1];
$this->primdrop_name = $primdrop_data[0];
$this->primdrop_uuid = $primdrop_data[1];
$this->primdrop_region = $primdrop_data[2];
$this->primdrop_pos = $primdrop_data[3];
$this->is_loaded = true;
}
/**
* Sets the position as 3 components.
* @param float x The X coordinate
* @param float y The Y coordinate
* @param float z The Z coordinate
*/
function set_pos($x, $y, $z)
{
$this->primdrop_pos = "<$x,$y,$z>";
}
/**
* Gets the X coordinate of the position
* @return float The X coordinate of the position
*/
function get_x()
{
$arr = sloodle_vector_to_array($this->primdrop_pos);
if (!$arr) return 0.0;
return (float)$arr['x'];
}
/**
* Gets the Y coordinate of the position
* @return float The Y coordinate of the position
*/
function get_y()
{
$arr = sloodle_vector_to_array($this->primdrop_pos);
if (!$arr) return 0.0;
return (float)$arr['y'];
}
/**
* Gets the Z coordinate of the position
* @return float The Z coordinate of the position
*/
function get_z()
{
$arr = sloodle_vector_to_array($this->primdrop_pos);
if (!$arr) return 0.0;
return (float)$arr['z'];
}
/**
* Construct a text summary of this submission.
* @param bool $return If TRUE (default) then the text will be submitted instead of printed.
* @return string If parameter $return was TRUE, then it returns the string. Otherwise, an empty string.
*/
function text_summary($return = true)
{
// Make sure something is loaded
if (!$this->is_loaded) {
$text = get_string('emptysubmission', 'assignment');
} else {
$text = "Object name: <b>{$this->obj_name}</b><br><br>";
$text .= "Submitted to: {$this->primdrop_name}<br>";
$text .= " <i>({$this->primdrop_uuid})</i><br><br>";
$arr = sloodle_vector_to_array($this->primdrop_pos);
if (!$arr) $arr = array('x'=>0, 'y'=>0, 'z'=>0);
else {
$arr['x'] = round($arr['x']);
$arr['y'] = round($arr['y']);
$arr['z'] = round($arr['z']);
}
$loc = "secondlife://{$this->primdrop_region}/{$arr['x']}/{$arr['y']}/{$arr['z']}";
$text .= "<b><a href=\"$loc\">$loc</a></b><br>";
}
if ($return) return $text;
echo $text;
return '';
}
}
}
?>