MDL-11515:
[moodle-linuxchix.git] / mod / assignment / type / offline / assignment.class.php
blob9e3f0564b23bab0cf733262a1f3a89dd9959292b
1 <?php // $Id$
3 /**
4 * Extend the base assignment class for offline assignments
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);
13 function display_lateness($timesubmitted) {
14 return '';
16 function print_student_answer($studentid){
17 return '';//does nothing!
20 function prepare_new_submission($userid) {
21 $submission = new Object;
22 $submission->assignment = $this->assignment->id;
23 $submission->userid = $userid;
24 $submission->timecreated = time(); // needed for offline assignments
25 $submission->timemodified = $submission->timecreated;
26 $submission->numfiles = 0;
27 $submission->data1 = '';
28 $submission->data2 = '';
29 $submission->grade = -1;
30 $submission->submissioncomment = '';
31 $submission->format = 0;
32 $submission->teacher = 0;
33 $submission->timemarked = 0;
34 $submission->mailed = 0;
35 return $submission;
38 // needed for the timemodified override
39 function process_feedback() {
40 global $CFG, $USER;
41 require_once($CFG->libdir.'/gradelib.php');
43 if (!$feedback = data_submitted()) { // No incoming data?
44 return false;
47 ///For save and next, we need to know the userid to save, and the userid to go
48 ///We use a new hidden field in the form, and set it to -1. If it's set, we use this
49 ///as the userid to store
50 if ((int)$feedback->saveuserid !== -1){
51 $feedback->userid = $feedback->saveuserid;
54 if (!empty($feedback->cancel)) { // User hit cancel button
55 return false;
58 $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
60 // store outcomes if needed
61 $this->process_outcomes($feedback->userid);
63 $submission = $this->get_submission($feedback->userid, true); // Get or make one
65 if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
66 !$grading_info->items[0]->grades[$feedback->userid]->overridden) {
68 $submission->grade = $feedback->grade;
69 $submission->submissioncomment = $feedback->submissioncomment;
70 $submission->format = $feedback->format;
71 $submission->teacher = $USER->id;
72 $submission->mailed = 0; // Make sure mail goes out (again, even)
73 $submission->timemarked = time();
75 unset($submission->data1); // Don't need to update this.
76 unset($submission->data2); // Don't need to update this.
78 if (empty($submission->timemodified)) { // eg for offline assignments
79 $submission->timemodified = time();
82 if (! update_record('assignment_submissions', $submission)) {
83 return false;
86 // triger grade event
87 $this->update_grade($submission);
89 add_to_log($this->course->id, 'assignment', 'update grades',
90 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
93 return $submission;