fb99b73d318f7b8016ad8ec127c154845e522543
[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->grade;
70             $submission->submissioncomment    = $feedback->submissioncomment;
71             $submission->format     = $feedback->format;
72             $submission->teacher    = $USER->id;
73             $mailinfo = get_user_preferences('assignment_mailinfo', 0);
74             if (!$mailinfo) {
75                 $submission->mailed = 1;       // treat as already mailed
76             } else {
77                 $submission->mailed = 0;       // Make sure mail goes out (again, even)
78             }
79             $submission->timemarked = time();
81             unset($submission->data1);  // Don't need to update this.
82             unset($submission->data2);  // Don't need to update this.
84             if (empty($submission->timemodified)) {   // eg for offline assignments
85                 $submission->timemodified = time();
86             }
88             $DB->update_record('assignment_submissions', $submission);
90             // triger grade event
91             $this->update_grade($submission);
93             add_to_log($this->course->id, 'assignment', 'update grades',
94                        'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
95         }
97         return $submission;
99     }