Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added validation to grading form, implemented methods in advanced gra…

…ding to return form contents and process and return the final grade
  • Loading branch information...
commit 18e6298c7b6e2145e96fd5cf937aa3dd41456d2c 1 parent 6abcb0c
@marinaglancy marinaglancy authored
View
10 grade/grading/form/lib.php
@@ -264,6 +264,16 @@ public function prepare_instance($raterid, $itemid) {
}
}
+ /**
+ * Saves non-js data and returns the gradebook grade
+ */
+ abstract public function save_and_get_grade($itemid, $formdata);
+
+ /**
+ * Returns html for form element
+ */
+ abstract public function to_html($elementname, $itemid);
+
////////////////////////////////////////////////////////////////////////////
View
37 grade/grading/form/rubric/lib.php
@@ -226,6 +226,38 @@ public function get_definition_for_editing() {
return $properties;
}
+ /**
+ * Saves non-js data and returns the gradebook grade
+ */
+ public function save_and_get_grade($itemid, $formdata) {
+ // TODO: this function is a patch at the moment!
+ if (is_array($formdata) && array_key_exists('grade', $formdata)) {
+ return $formdata['grade'];
+ }
+ return -1;
+ }
+
+ /**
+ * Returns html for form element
+ */
+ public function to_html($elementname, $submissionid) {
+ // TODO: this function is a patch at the moment!
+
+ //global $PAGE, $USER;
+ //$gradingrenderer = $this->prepare_renderer($PAGE);
+ $output = '';
+ $output .= "assessing submission $submissionid<br />";
+ $output .= html_writer::empty_tag('input', array('type' => 'text', 'name' => $elementname.'[grade]', 'size' => '20'));
+ //$output .= "assessing user $userid on assignment $assignmentid<br>";
+ //TODO find $submissionid from $userid & $assignmentid (may not exist yet, actually)
+ /*$submissionid = null;
+ $gradingwidget = $this->make_grading_widget($USER->id, $submissionid);
+ if ($gradingwidget instanceof renderable) {
+ return $output. $gradingrenderer->render($gradingwidget);
+ }*/
+ return $output;
+ }
+
// TODO the following functions may be moved to parent:
/**
@@ -273,4 +305,9 @@ public function postupdate_definition_data($data) {
// TODO change filearea for embedded files in grading_definition.description
return $data;
}
+
+ public function is_form_available($foruserid = null) {
+ return true;
+ // TODO this is temporary for testing!
+ }
}
View
13 grade/grading/lib.php
@@ -374,6 +374,19 @@ public function get_controller($method) {
return new $classname($this->context, $this->component, $this->area, $this->areacache->id);
}
+ /**
+ * Returns the controller for the active method if it is available
+ */
+ public function get_active_controller() {
+ if ($gradingmethod = $this->get_active_method()) {
+ $controller = $this->get_controller($gradingmethod);
+ if ($controller->is_form_available()) {
+ return $controller;
+ }
+ }
+ return null;
+ }
+
////////////////////////////////////////////////////////////////////////////
/**
View
80 mod/assignment/lib.php
@@ -630,7 +630,10 @@ function submissions($mode) {
switch ($mode) {
case 'grade': // We are in a main window grading
- if ($submission = $this->process_feedback()) {
+ if (!$this->validate_and_preprocess_feedback()) {
+ // validation failed
+ $this->display_submission();
+ } else if ($submission = $this->process_feedback()) {
$this->display_submissions(get_string('changessaved'));
} else {
$this->display_submissions();
@@ -744,7 +747,11 @@ function submissions($mode) {
case 'saveandnext':
///We are in pop up. save the current one and go to the next one.
//first we save the current changes
- if ($submission = $this->process_feedback()) {
+ if (!$this->validate_and_preprocess_feedback()) {
+ // validation failed
+ $this->display_submission();
+ break;
+ } else if ($submission = $this->process_feedback()) {
//print_heading(get_string('changessaved'));
//$extra_javascript = $this->update_main_listing($submission);
}
@@ -1039,7 +1046,7 @@ function display_submission($offset=-1,$userid =-1, $display=true) {
} elseif ($assignment->assignmenttype == 'uploadsingle') {
$mformdata->fileui_options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
}
- $gradingman = get_grading_manager($this->context, 'mod_assignment', 'submission');
+ /*$gradingman = get_grading_manager($this->context, 'mod_assignment', 'submission');
if ($gradingmethod = $gradingman->get_active_method()) {
$controller = $gradingman->get_controller($gradingmethod);
if ($controller->is_form_available()) {
@@ -1067,6 +1074,13 @@ function display_submission($offset=-1,$userid =-1, $display=true) {
} else {
notice(get_string('formnotavailable', 'core_grading'), new moodle_url('/course/view.php', array('id' => $assignment->course)));
}
+ }*/
+ if ($controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) {
+ if (!isset($submission->id)) {
+ // TODO this is a patch if submission id does not exist yet
+ $mformdata->submission = $this->get_submission($user->id, true);
+ }
+ $mformdata->advancedgradingcontroller = $controller;
}
$submitform = new mod_assignment_grading_form( null, $mformdata );
@@ -1074,7 +1088,9 @@ function display_submission($offset=-1,$userid =-1, $display=true) {
if (!$display) {
$ret_data = new stdClass();
$ret_data->mform = $submitform;
- $ret_data->fileui_options = $mformdata->fileui_options;
+ if (isset($mformdata->fileui_options)) {
+ $ret_data->fileui_options = $mformdata->fileui_options;
+ }
return $ret_data;
}
@@ -1575,6 +1591,34 @@ function display_submissions($message='') {
}
/**
+ * Validates the submitted form and returns false if validation did not pass.
+ * If validation passes, preprocess advanced grading (if applicable) and returns true.
+ */
+ function validate_and_preprocess_feedback() {
+ if (!$feedback = data_submitted()) {
+ return true; // No incoming data, nothing to validate
+ }
+ $userid = required_param('userid', PARAM_INT);
+ $offset = required_param('offset', PARAM_INT);
+ $submissiondata = $this->display_submission($offset, $userid, false);
+ $mform = $submissiondata->mform;
+ if ($mform->is_submitted()) {
+ if (!$mform->is_validated()) {
+ return false;
+ }
+ // preprocess advanced grading here
+ if ($controller = $mform->use_advanced_grading()) {
+ $data = $mform->get_data();
+ // TODO find better way to find submission id
+ $submission = $this->get_submission($userid);
+ // TODO replace $_POST['advancedgrading'] with $data->advancedgrading when element type is changed from 'static' to 'grading'
+ $_POST['xgrade'] = $controller->save_and_get_grade($submission->id, $_POST['advancedgrading']);
+ }
+ }
+ return true;
+ }
+
+ /**
* Process teacher feedback submission
*
* This is called by submissions() when a grading even has taken place.
@@ -2252,6 +2296,10 @@ function definition() {
global $OUTPUT;
$mform =& $this->_form;
+ if (isset($this->_customdata->advancedgradingcontroller)) {
+ $this->use_advanced_grading($this->_customdata->advancedgradingcontroller);
+ }
+
$formattr = $mform->getAttributes();
$formattr['id'] = 'submitform';
$mform->setAttributes($formattr);
@@ -2297,6 +2345,19 @@ function definition() {
}
+ private $_advancegradingcontroller;
+ /**
+ * Gets or sets the controller for advanced grading
+ *
+ * @param <type> $controller
+ */
+ public function use_advanced_grading($controller = false) {
+ if ($controller !== false) {
+ $this->_advancegradingcontroller = $controller;
+ }
+ return $this->_advancegradingcontroller;
+ }
+
function add_grades_section() {
global $CFG;
$mform =& $this->_form;
@@ -2307,9 +2368,9 @@ function add_grades_section() {
$mform->addElement('header', 'Grades', get_string('grades', 'grades'));
- if (!empty($this->_customdata->advancedgradingenabled)) {
- $mform->addElement('static', 'advancedgradingwidget', get_string('grade').':', $this->_customdata->advancedgradingwidget);
-
+ if ($controller = $this->use_advanced_grading()) {
+ // TODO what if submission id does not exist yet!
+ $mform->addElement('static', 'advancedgrading', get_string('grade').':', $controller->to_html('advancedgrading', $this->_customdata->submission->id));
} else {
// use simple direct grading
$grademenu = make_grades_menu($this->_customdata->assignment->grade);
@@ -2468,6 +2529,11 @@ public function get_data() {
}
$data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
}
+
+ if ($this->use_advanced_grading() && !isset($data->advancedgrading)) {
+ $data->advancedgrading = null;
+ }
+
return $data;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.