diff --git a/grade/edit/edit_grade.php b/grade/edit/edit_grade.php
index dd083b98859..6e2dc156b66 100644
--- a/grade/edit/edit_grade.php
+++ b/grade/edit/edit_grade.php
@@ -21,12 +21,21 @@ require_capability('gradereport/grader:manage', $context);
//TODO: implement proper return support
$returnurl = $CFG->wwwroot.'/grade/report.php?report=grader&id='.$course->id;
+// TODO: add proper check that grade is editable
+
$grade_grades = get_record('grade_grades', 'id', $id);
$gradeitem = get_record('grade_items', 'id', $grade_grades->itemid);
$mform = new edit_grade_form(qualified_me(), array('gradeitem'=>$gradeitem));
if ($grade_grades = get_record('grade_grades', 'id', $id)) {
if ($grade_text = get_record('grade_grades_text', 'gradeid', $id)) {
+ if (can_use_html_editor()) {
+ $options = new object();
+ $options->smiley = false;
+ $options->filter = false;
+ $grade_text->feedback = format_text($grade_text->feedback, $grade_text->feedbackformat, $options);
+ $grade_text->feedbackformat = FORMAT_HTML;
+ }
$mform->set_data($grade_text);
}
@@ -45,7 +54,7 @@ if ($mform->is_cancelled()) {
$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);
+ $grade_item->update_final_grade($grade_grades->userid, $data->finalgrade, NULL, NULL, $data->feedback, $data->feedbackformat);
// set locked
$grade_grades->set_locked($data->locked);
diff --git a/grade/edit/edit_grade_form.php b/grade/edit/edit_grade_form.php
index 43d73db3a0a..d22883551d8 100755
--- a/grade/edit/edit_grade_form.php
+++ b/grade/edit/edit_grade_form.php
@@ -11,10 +11,11 @@ class edit_grade_form extends moodleform {
$gradeitem = $this->_customdata['gradeitem'];
/// actual grade - numeric or scale
- if ($gradeitem->gradetype == 1) {
+ if ($gradeitem->gradetype == GRADE_TYPE_VALUE) {
// numeric grade
$mform->addElement('text', 'finalgrade', get_string('finalgrade', 'grades'));
- } else if ($gradeitem->gradetype == 2) {
+
+ } else if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
// scale grade
$scaleopt[-1] = get_string('nograde');
@@ -38,21 +39,13 @@ class edit_grade_form extends moodleform {
/// locktime
$mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
- /// hidden/visible
- /// feedback
- $feedbackformat = get_user_preferences('grade_report_feedbackformat', $CFG->grade_report_feedbackformat);
-
- // visible elements
- // User preference determines the format
- if ($CFG->htmleditor && $USER->htmleditor && $feedbackformat == GRADER_REPORT_FEEDBACK_FORMAT_HTML) {
- $mform->addElement('htmleditor', 'feedback', get_string('feedback', 'grades'),
- array('rows'=> '15', 'course' => $gradeitem->courseid, 'cols'=>'45'));
- } else {
- $mform->addElement('textarea', 'feedback', get_string('feedback', 'grades'));
- }
-
- //TODO: add other elements
+ // Feedback format is automatically converted to html if user has enabled editor
+ $mform->addElement('htmleditor', 'feedback', get_string('feedback', 'grades'),
+ array('rows'=> '15', 'course' => $gradeitem->courseid, 'cols'=>'45'));
+ $mform->setType('text', PARAM_RAW); // to be cleaned before display
+ $mform->addElement('format', 'feedbackformat', get_string('format'));
+ $mform->setHelpButton('feedbackformat', array('textformat', get_string('helpformatting')));
// hidden params
$mform->addElement('hidden', 'id', 0);
diff --git a/grade/report/grader/grader_report.php b/grade/report/grader/grader_report.php
index 1b5935f4359..42914dd2798 100644
--- a/grade/report/grader/grader_report.php
+++ b/grade/report/grader/grader_report.php
@@ -10,8 +10,6 @@ define('GRADER_REPORT_AGGREGATION_VIEW_FULL', 0);
define('GRADER_REPORT_AGGREGATION_VIEW_COMPACT', 1);
define('GRADER_REPORT_GRADE_DISPLAY_TYPE_RAW', 0);
define('GRADER_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE', 1);
-define('GRADER_REPORT_FEEDBACK_FORMAT_TEXT', 0);
-define('GRADER_REPORT_FEEDBACK_FORMAT_HTML', 1);
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/gradelib.php');
@@ -218,10 +216,9 @@ class grade_report_grader {
$note = false; // TODO implement note??
// skip, not a grade nor feedback
- $data_type = '';
- if (strstr($varname, 'grade')) {
+ if (strpos($varname, 'grade') === 0) {
$data_type = 'grade';
- } elseif (strstr($varname, 'feedback')) {
+ } else if (strpos($varname, 'feedback') === 0) {
$data_type = 'feedback';
} else {
continue;
@@ -238,7 +235,6 @@ class grade_report_grader {
// Pre-process grade
if ($data_type == 'grade') {
-
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
if ($postedvalue == -1) { // -1 means no grade
$finalgrade = null;
@@ -258,25 +254,37 @@ class grade_report_grader {
// another possiblity is to use bounded number instead
continue;
}
+
+ } else if ($data_type == 'feedback') {
+ $trimmed = trim($postedvalue);
+ if (empty($trimmed)) {
+ $postedvalue = NULL;
+ }
}
// Get the grade object to compare old value with new value
if ($grade = grade_grades::fetch(array('userid'=>$userid, 'itemid'=>$grade_item->id))) {
if ($data_type == 'feedback') {
$finalgrade = false;
- $text = $grade->load_text();
- if ($text != s($postedvalue)) {
- $feedback = s($postedvalue);
- $feedbackformat = GRADER_REPORT_FEEDBACK_FORMAT_TEXT;
- $needsupdate = true;
+ if ($text = $grade->load_text()) {
+ if ($text->feedback !== $postedvalue) {
+ $feedback = $postedvalue;
+ $feedbackformat = $text->feedbackformat; // keep original format or else we would have to do proper conversion (but it is not always possible)
+ $needsupdate = true;
+ }
+ } else {
+ $feedback = $postedvalue;
+ $feedbackformat = MOODLE_FORMAT; // this is the default format option everywhere else
+ $needsupdate = true;
}
- } elseif ($data_type == 'grade') {
+
+ } else if ($data_type == 'grade') {
$feedback = false;
$feedbackformat = false;
if (!is_null($grade->finalgrade)) {
$grade->finalgrade = (float)$grade->finalgrade;
}
- if ($grade->finalgrade === $finalgrade) {
+ if ($grade->finalgrade !== $finalgrade) {
$needsupdate = true;
}
}
@@ -731,6 +739,7 @@ class grade_report_grader {
$element = array ('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade');
// Do not show any icons if no grade (no record in DB to match)
+ // TODO: change edit/hide/etc. links to use itemid and userid to allow creating of new grade objects
if (!empty($grade->id)) {
$studentshtml .= $this->get_icons($element);
}
@@ -753,7 +762,7 @@ class grade_report_grader {
$scaleopt[$i] = $scaleoption;
}
- if ($this->get_user_pref('quickgrading')) {
+ if ($this->get_user_pref('quickgrading') and $grade->is_editable()) {
$studentshtml .= choose_from_menu($scaleopt, 'grade_'.$userid.'_'.$item->id,
$gradeval, get_string('nograde'), '', -1, true);
} elseif ($scale = get_record('scale', 'id', $item->scaleid)) {
@@ -769,8 +778,9 @@ class grade_report_grader {
// no such scale, throw error?
}
}
- } else {
- if ($this->get_user_pref('quickgrading')) {
+
+ } else if ($item->gradetype != GRADE_TYPE_TEXT) {
+ if ($this->get_user_pref('quickgrading') and $grade->is_editable()) {
$studentshtml .= '';
} else {
@@ -780,7 +790,7 @@ class grade_report_grader {
// If quickfeedback is on, print an input element
- if ($this->get_user_pref('quickfeedback')) {
+ if ($this->get_user_pref('quickfeedback') and $grade->is_editable()) {
if ($this->get_user_pref('quickgrading')) {
$studentshtml .= '
';
}
@@ -788,7 +798,6 @@ class grade_report_grader {
. s($grade->feedback) . '"/>';
}
- $studentshtml .= '