diff --git a/mod/assign/feedback/comments/locallib.php b/mod/assign/feedback/comments/locallib.php index dadd2a86680..237a00da4a2 100644 --- a/mod/assign/feedback/comments/locallib.php +++ b/mod/assign/feedback/comments/locallib.php @@ -53,6 +53,77 @@ class assign_feedback_comments extends assign_feedback_plugin { return $DB->get_record('assignfeedback_comments', array('grade'=>$gradeid)); } + /** + * Get quickgrading form elements as html + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param mixed $grade - The grade data - may be null if there are no grades for this user (yet) + * @return mixed - A html string containing the html form elements required for quickgrading + */ + public function get_quickgrading_html($userid, $grade) { + $commenttext = ''; + if ($grade) { + $feedbackcomments = $this->get_feedback_comments($grade->id); + if ($feedbackcomments) { + $commenttext = $feedbackcomments->commenttext; + } + } + + return html_writer::tag('textarea', $commenttext, array('name'=>'quickgrade_comments_' . $userid, + 'class'=>'quickgrade')); + } + + /** + * Has the plugin quickgrading form element been modified in the current form submission? + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param stdClass $grade The grade + * @return boolean - true if the quickgrading form element has been modified + */ + public function is_quickgrading_modified($userid, $grade) { + $commenttext = ''; + if ($grade) { + $feedbackcomments = $this->get_feedback_comments($grade->id); + if ($feedbackcomments) { + $commenttext = $feedbackcomments->commenttext; + } + } + return optional_param('quickgrade_comments_' . $userid, '', PARAM_TEXT) != $commenttext; + } + + + /** + * Override to indicate a plugin supports quickgrading + * + * @return boolean - True if the plugin supports quickgrading + */ + public function supports_quickgrading() { + return true; + } + + /** + * Save quickgrading changes + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param stdClass $grade The grade + * @return boolean - true if the grade changes were saved correctly + */ + public function save_quickgrading_changes($userid, $grade) { + global $DB; + $feedbackcomment = $this->get_feedback_comments($grade->id); + if ($feedbackcomment) { + $feedbackcomment->commenttext = optional_param('quickgrade_comments_' . $userid, '', PARAM_TEXT); + return $DB->update_record('assignfeedback_comments', $feedbackcomment); + } else { + $feedbackcomment = new stdClass(); + $feedbackcomment->commenttext = optional_param('quickgrade_comments_' . $userid, '', PARAM_TEXT); + $feedbackcomment->commentformat = FORMAT_HTML; + $feedbackcomment->grade = $grade->id; + $feedbackcomment->assignment = $this->assignment->get_instance()->id; + return $DB->insert_record('assignfeedback_comments', $feedbackcomment) > 0; + } + } + /** * Get form elements for the grading page * diff --git a/mod/assign/feedbackplugin.php b/mod/assign/feedbackplugin.php index 198900b6e1a..6677e6aec54 100644 --- a/mod/assign/feedbackplugin.php +++ b/mod/assign/feedbackplugin.php @@ -81,4 +81,46 @@ abstract class assign_feedback_plugin extends assign_plugin { return ''; } + /** + * Override to indicate a plugin supports quickgrading + * + * @return boolean - True if the plugin supports quickgrading + */ + public function supports_quickgrading() { + return false; + } + + /** + * Get quickgrading form elements as html + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) + * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading + */ + public function get_quickgrading_html($userid, $grade) { + return false; + } + + /** + * Has the plugin quickgrading form element been modified in the current form submission? + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param stdClass $grade The grade + * @return boolean - true if the quickgrading form element has been modified + */ + public function is_quickgrading_modified($userid, $grade) { + return false; + } + + /** + * Save quickgrading changes + * + * @param int $userid The user id in the table this quickgrading element relates to + * @param stdClass $grade The grade + * @return boolean - true if the grade changes were saved correctly + */ + public function save_quickgrading_changes($userid, $grade) { + return false; + } + } diff --git a/mod/assign/gradingtable.php b/mod/assign/gradingtable.php index 7d2bddcd657..db4432dadea 100644 --- a/mod/assign/gradingtable.php +++ b/mod/assign/gradingtable.php @@ -253,7 +253,7 @@ class assign_grading_table extends table_sql implements renderable { $options = make_grades_menu(-$outcome->scaleid); $options[0] = get_string('nooutcome', 'grades'); - if ($this->quickgrading&& !($outcome->grades[$row->userid]->locked)) { + if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) { $select = '