Merge branch 'MDL-33319' of git://github.com/netspotau/moodle-mod_assign

This commit is contained in:
Dan Poltawski 2012-06-05 12:03:56 +08:00
commit ac0ad29c6f
4 changed files with 154 additions and 11 deletions

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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 = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
foreach ($options as $optionindex => $optionvalue) {
$selected = '';
@ -519,6 +519,7 @@ class assign_grading_table extends table_sql implements renderable {
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 @@ class assign_grading_table extends table_sql implements renderable {
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 @@ class assign_grading_table extends table_sql implements renderable {
$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 @@ class assign_grading_table extends table_sql implements renderable {
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 @@ class assign_grading_table extends table_sql implements renderable {
$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 File

@ -2531,17 +2531,20 @@ class assign {
$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 @@ class assign {
$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 @@ class assign {
}
}
// 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 @@ class assign {
$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();