Permalink
Browse files

MDL-33319: Support quickgrading in feedback plugins

  • Loading branch information...
1 parent 4631e39 commit 2c6a3dbfca7ada55b0dd736e6c4c861044b5b6d6 Damyon Wiese committed May 28, 2012
Showing with 154 additions and 11 deletions.
  1. +71 −0 mod/assign/feedback/comments/locallib.php
  2. +42 −0 mod/assign/feedbackplugin.php
  3. +8 −3 mod/assign/gradingtable.php
  4. +33 −8 mod/assign/locallib.php
View
71 mod/assign/feedback/comments/locallib.php
@@ -54,6 +54,77 @@ public function get_feedback_comments($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
*
* @param stdClass|null $grade
View
42 mod/assign/feedbackplugin.php
@@ -81,4 +81,46 @@ public function text_for_gradebook(stdClass $grade) {
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;
+ }
+
}
View
11 mod/assign/gradingtable.php
@@ -253,7 +253,7 @@ function col_outcomes(stdClass $row) {
$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 = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
foreach ($options as $optionindex => $optionvalue) {
$selected = '';
@@ -519,6 +519,7 @@ function col_edit(stdClass $row) {
private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass $item, $returnaction, $returnparams) {
$link = '';
$showviewlink = false;
+
$summary = $plugin->view_summary($item, $showviewlink);
$separator = '';
if ($showviewlink) {
@@ -550,6 +551,7 @@ private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass
function other_cols($colname, $row){
if (($pos = strpos($colname, 'assignsubmission_')) !== false) {
$plugin = $this->assignment->get_submission_plugin_by_type(substr($colname, strlen('assignsubmission_')));
+
if ($plugin->is_visible() && $plugin->is_enabled()) {
if ($row->submissionid) {
$submission = new stdClass();
@@ -558,7 +560,6 @@ function other_cols($colname, $row){
$submission->timemodified = $row->timesubmitted;
$submission->assignment = $this->assignment->get_instance()->id;
$submission->userid = $row->userid;
-
return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
}
}
@@ -567,6 +568,7 @@ function other_cols($colname, $row){
if (($pos = strpos($colname, 'feedback_')) !== false) {
$plugin = $this->assignment->get_feedback_plugin_by_type(substr($colname, strlen('assignfeedback_')));
if ($plugin->is_visible() && $plugin->is_enabled()) {
+ $grade = null;
if ($row->gradeid) {
$grade = new stdClass();
$grade->id = $row->gradeid;
@@ -576,7 +578,10 @@ function other_cols($colname, $row){
$grade->userid = $row->userid;
$grade->grade = $row->grade;
$grade->mailed = $row->mailed;
-
+ }
+ if ($this->quickgrading && $plugin->supports_quickgrading()) {
+ return $plugin->get_quickgrading_html($row->userid, $grade);
+ } else if ($grade) {
return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array());
}
}
View
41 mod/assign/locallib.php
@@ -2531,17 +2531,20 @@ private function process_save_quick_grades() {
$users = array();
// first check all the last modified values
- // Using POST is really unfortunate. A better solution needs to be found here. As we are looking for grades students we could
+ $currentgroup = groups_get_activity_group($this->get_course_module(), true);
+ $participants = $this->list_participants($currentgroup, true);
+
// gets a list of possible users and look for values based upon that.
- foreach ($_POST as $key => $value) {
- if (preg_match('#^grademodified_(\d+)$#', $key, $matches)) {
+ foreach ($participants as $userid => $unused) {
+ $modified = optional_param('grademodified_' . $userid, -1, PARAM_INT);
+ if ($modified >= 0) {
// gather the userid, updated grade and last modified value
$record = new stdClass();
- $record->userid = (int)$matches[1];
- $record->grade = required_param('quickgrade_' . $record->userid, PARAM_INT);
- $record->lastmodified = clean_param($value, PARAM_INT);
- $record->gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($record->userid));
- $users[$record->userid] = $record;
+ $record->userid = $userid;
+ $record->grade = required_param('quickgrade_' . $userid, PARAM_INT);
+ $record->lastmodified = $modified;
+ $record->gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($userid));
+ $users[$userid] = $record;
}
}
if (empty($users)) {
@@ -2561,6 +2564,7 @@ private function process_save_quick_grades() {
$modifiedusers = array();
foreach ($currentgrades as $current) {
$modified = $users[(int)$current->userid];
+ $grade = $this->get_user_grade($userid, false);
// check to see if the outcomes were modified
if ($CFG->enableoutcomes) {
@@ -2575,6 +2579,20 @@ private function process_save_quick_grades() {
}
}
+ // let plugins participate
+ foreach ($this->feedbackplugins as $plugin) {
+ if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->supports_quickgrading()) {
+ if ($plugin->is_quickgrading_modified($modified->userid, $grade)) {
+ if ((int)$current->lastmodified > (int)$modified->lastmodified) {
+ return get_string('errorrecordmodified', 'assign');
+ } else {
+ $modifiedusers[$modified->userid] = $modified;
+ continue;
+ }
+ }
+ }
+ }
+
if (($current->grade < 0 || $current->grade === NULL) &&
($modified->grade < 0 || $modified->grade === NULL)) {
@@ -2602,6 +2620,13 @@ private function process_save_quick_grades() {
$this->update_grade($grade);
+ // save plugins data
+ foreach ($this->feedbackplugins as $plugin) {
+ if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->supports_quickgrading()) {
+ $plugin->save_quickgrading_changes($userid, $grade);
+ }
+ }
+
// save outcomes
if ($CFG->enableoutcomes) {
$data = array();

0 comments on commit 2c6a3db

Please sign in to comment.