assignment MDL-24106 some assignment changes were left out for offline assignment...
[moodle.git] / mod / assignment / type / offline / assignment.class.php
1 <?php
3 /**
4  * Extend the base assignment class for offline assignments
5  *
6  */
7 class assignment_offline extends assignment_base {
9     function assignment_offline($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
10         parent::assignment_base($cmid, $assignment, $cm, $course);
11         $this->type = 'offline';
12     }
14     function display_lateness($timesubmitted) {
15         return '';
16     }
17     function print_student_answer($studentid){
18         return '';//does nothing!
19     }
21     function prepare_new_submission($userid) {
22         $submission = new Object;
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     }
39     // needed for the timemodified override
40     function process_feedback() {
41         global $CFG, $USER, $DB;
42         require_once($CFG->libdir.'/gradelib.php');
44         if (!$feedback = data_submitted() or !confirm_sesskey()) {      // No incoming data?
45             return false;
46         }
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         }
55         if (!empty($feedback->cancel)) {          // User hit cancel button
56             return false;
57         }
59         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
61         // store outcomes if needed
62         $this->process_outcomes($feedback->userid);
64         $submission = $this->get_submission($feedback->userid, true);  // Get or make one
66         if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
67             !$grading_info->items[0]->grades[$feedback->userid]->overridden) {
69             $submission->grade      = $feedback->xgrade;
70             $submission->submissioncomment    = $feedback->submissioncomment_editor['text'];
71             $submission->teacher    = $USER->id;
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             }
78             $submission->timemarked = time();
80             unset($submission->data1);  // Don't need to update this.
81             unset($submission->data2);  // Don't need to update this.
83             if (empty($submission->timemodified)) {   // eg for offline assignments
84                 $submission->timemodified = time();
85             }
87             $DB->update_record('assignment_submissions', $submission);
89             // triger grade event
90             $this->update_grade($submission);
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         }
96         return $submission;
98     }