MDL-4667, MDL-4112 switching order of columns in course-userid log table index in...
[moodle.git] / mod / assignment / type / offline / assignment.class.php
CommitLineData
b0f2597e 1<?php // $Id$
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() {
5978010d 41 global $CFG, $USER;
42 require_once($CFG->libdir.'/gradelib.php');
16fc2088 43
44 if (!$feedback = data_submitted()) { // No incoming data?
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
5978010d 69 $submission->grade = $feedback->grade;
70 $submission->submissioncomment = $feedback->submissioncomment;
71 $submission->format = $feedback->format;
72 $submission->teacher = $USER->id;
73 $submission->mailed = 0; // Make sure mail goes out (again, even)
74 $submission->timemarked = time();
16fc2088 75
5978010d 76 unset($submission->data1); // Don't need to update this.
77 unset($submission->data2); // Don't need to update this.
16fc2088 78
5978010d 79 if (empty($submission->timemodified)) { // eg for offline assignments
80 $submission->timemodified = time();
81 }
82
83 if (! update_record('assignment_submissions', $submission)) {
84 return false;
85 }
16fc2088 86
5978010d 87 // triger grade event
88 $this->update_grade($submission);
7bddd4b7 89
5978010d 90 add_to_log($this->course->id, 'assignment', 'update grades',
91 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
92 }
45fa3412 93
16fc2088 94 return $submission;
95
96 }
3994ef98 97
b0f2597e 98}
99
100?>