diff --git a/grade/report/grader/edit_grade.php b/grade/report/grader/edit_grade.php index 37d4a06755a..beef3575b6b 100644 --- a/grade/report/grader/edit_grade.php +++ b/grade/report/grader/edit_grade.php @@ -24,8 +24,9 @@ $mform = new edit_grade_form(qualified_me(), array('id'=>$id)); if ($grade_grades = get_record('grade_grades', 'id', $id)) { if ($grade_text = get_record('grade_grades_text', 'gradeid', $id)) { $mform->set_data($grade_text); - } + } + $grade_grades->courseid = $courseid; $mform->set_data($grade_grades); } else { $mform->set_data(array('courseid'=>$course->id, 'id' => $id)); @@ -35,17 +36,18 @@ if ($mform->is_cancelled()) { redirect($returnurl); // form processing } else if ($data = $mform->get_data()) { - $data->gradeid = $data->id; - unset($data->id); - - $grade_text = new grade_grades_text(array('gradeid'=>$id)); - grade_grades_text::set_properties($grade_text, $data); - if (empty($grade_text->id)) { - $grade_text->insert(); - - } else { - $grade_text->update(); - } + + $grade_grades = new grade_grades(array('id'=>$id)); + $grade_item = new grade_item(array('id'=>$grade_grades->itemid)); + $grade_item->update_final_grade($grade_grades->userid, $data->finalgrade, NULL, NULL, $data->feedback); + + // set locked + $grade_grades->set_locked($data->locked); + // set hidden + $grade_grades->set_hidden($data->hidden); + + // set locktime + $grade_grades->set_locktime($data->locktime); redirect($returnurl, get_string('feedbacksaved', 'grades'), 1); } @@ -112,30 +114,8 @@ if (!empty($extra_info->course_module) && !empty($extra_info->itemmodule)) { . '/view.php?id=' . $extra_info->course_module->id . "&courseid=$courseid\">$extra_info->itemname

"; } -// Final grade and link to scale if applicable -if (!empty($extra_info->finalgrade)) { - $openlink = ''; - $closelink = ''; - - if (!empty($extra_info->scaleid)) { - $openlink = ''; - $closelink = ''; - } - echo "

$strgrade: " . $extra_info->finalgrade . "$openlink $stronascaleof $closelink

"; -} - // Form if in edit or add modes $mform->display(); -/* -if ($action != 'view') { - $mform->display(); -} else { // Feedback string and Back button if in View mode - echo $feedback; - echo "'; -} -*/ print_simple_box_end(); diff --git a/grade/report/grader/edit_grade_form.php b/grade/report/grader/edit_grade_form.php index a66d7019c09..31d2f637dd5 100755 --- a/grade/report/grader/edit_grade_form.php +++ b/grade/report/grader/edit_grade_form.php @@ -19,9 +19,11 @@ class edit_grade_form extends moodleform { // scale grade $scaleopt[-1] = get_string('nograde'); + $i = 1; if ($scale = get_record('scale', 'id', $gradeitem->scaleid)) { foreach (split(",", $scale->scale) as $option) { - $scaleopt[] = $option; + $scaleopt[$i] = $option; + $i++; } } diff --git a/lib/grade/grade_grades.php b/lib/grade/grade_grades.php index f205df3625a..e6db1f0603c 100644 --- a/lib/grade/grade_grades.php +++ b/lib/grade/grade_grades.php @@ -214,6 +214,45 @@ class grade_grades extends grade_object { } } + + /** + * Set the locktime for this grade. + * + * @param int $locktime timestamp for lock to activate + * @return boolean true if sucessful, false if can not set new lock state for grade + */ + function set_locktime($locktime) { + + if ($locktime) { + // if current locktime is before, no need to reset + + if ($this->locktime && $this->locktime <= $locktime) { + return true; + } + + /* + if ($this->grade_item->needsupdate) { + //can not lock grade if final not calculated! + return false; + } + */ + + $this->locktime = $locktime; + $this->update(); + + return true; + + } else { + + // remove the locktime timestamp + $this->locktime = 0; + + $this->update(); + + return true; + } + } + /** * Check grade lock status. Uses both grade item lock and grade lock. * Internally any date in hidden field (including future ones) means hidden, diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 2c7ba0a667e..737c2c97e68 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -457,6 +457,44 @@ class grade_item extends grade_object { } } + + /** + * Set the locktime for this grade. + * + * @param int $locktime timestamp for lock to activate + * @return boolean true if sucessful, false if can not set new lock state for grade + */ + function set_locktime($locktime) { + + if ($locktime) { + // if current locktime is before, no need to reset + + if ($this->locktime && $this->locktime <= $locktime) { + return true; + } + + /* + if ($this->grade_item->needsupdate) { + //can not lock grade if final not calculated! + return false; + } + */ + + $this->locktime = $locktime; + $this->update(); + + return true; + + } else { + + // remove the locktime timestamp + $this->locktime = 0; + + $this->update(); + + return true; + } + } /** * Returns the hidden state of this grade_item (if the grade_item is hidden OR no specific