assignment MDL-24106 some assignment changes were left out for offline assignment...
[moodle.git] / mod / assignment / type / offline / assignment.class.php
CommitLineData
e7521559 1<?php
b0f2597e 2
3/**
4 * Extend the base assignment class for offline assignments
5 *
6 */
7class assignment_offline extends assignment_base {
8
7bddd4b7 9 function assignment_offline($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
10 parent::assignment_base($cmid, $assignment, $cm, $course);
0b5a80a1 11 $this->type = 'offline';
b0f2597e 12 }
13
3994ef98 14 function display_lateness($timesubmitted) {
15 return '';
16 }
e768aabe 17 function print_student_answer($studentid){
18 return '';//does nothing!
19 }
45fa3412 20
16fc2088 21 function prepare_new_submission($userid) {
45fa3412 22 $submission = new Object;
16fc2088 23 $submission->assignment = $this->assignment->id;
24 $submission->userid = $userid;
25 $submission->timecreated = time(); // needed for offline assignments
26 $submission->timemodified = $submission->timecreated;
27 $submission->numfiles = 0;
28 $submission->data1 = '';
29 $submission->data2 = '';
30 $submission->grade = -1;
31 $submission->submissioncomment = '';
32 $submission->format = 0;
33 $submission->teacher = 0;
34 $submission->timemarked = 0;
35 $submission->mailed = 0;
36 return $submission;
37 }
45fa3412 38
16fc2088 39 // needed for the timemodified override
40 function process_feedback() {
74d7d735 41 global $CFG, $USER, $DB;
5978010d 42 require_once($CFG->libdir.'/gradelib.php');
16fc2088 43
a19dffc0 44 if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data?
16fc2088 45 return false;
46 }
47
48 ///For save and next, we need to know the userid to save, and the userid to go
49 ///We use a new hidden field in the form, and set it to -1. If it's set, we use this
50 ///as the userid to store
51 if ((int)$feedback->saveuserid !== -1){
52 $feedback->userid = $feedback->saveuserid;
53 }
54
55 if (!empty($feedback->cancel)) { // User hit cancel button
56 return false;
57 }
58
5978010d 59 $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
60
cc03871b 61 // store outcomes if needed
62 $this->process_outcomes($feedback->userid);
63
16fc2088 64 $submission = $this->get_submission($feedback->userid, true); // Get or make one
65
5978010d 66 if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
67 !$grading_info->items[0]->grades[$feedback->userid]->overridden) {
16fc2088 68
b8f037ba
AB
69 $submission->grade = $feedback->xgrade;
70 $submission->submissioncomment = $feedback->submissioncomment_editor['text'];
5978010d 71 $submission->teacher = $USER->id;
2dc5d980 72 $mailinfo = get_user_preferences('assignment_mailinfo', 0);
73 if (!$mailinfo) {
74 $submission->mailed = 1; // treat as already mailed
75 } else {
76 $submission->mailed = 0; // Make sure mail goes out (again, even)
77 }
5978010d 78 $submission->timemarked = time();
16fc2088 79
5978010d 80 unset($submission->data1); // Don't need to update this.
81 unset($submission->data2); // Don't need to update this.
16fc2088 82
5978010d 83 if (empty($submission->timemodified)) { // eg for offline assignments
84 $submission->timemodified = time();
85 }
86
0bcf8b6f 87 $DB->update_record('assignment_submissions', $submission);
16fc2088 88
5978010d 89 // triger grade event
90 $this->update_grade($submission);
7bddd4b7 91
5978010d 92 add_to_log($this->course->id, 'assignment', 'update grades',
93 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
94 }
45fa3412 95
16fc2088 96 return $submission;
97
98 }
3994ef98 99
b0f2597e 100}
101
e7521559 102