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
*
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;
+ }
+
}
$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 = '';
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) {
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();
$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());
}
}
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;
$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());
}
}
$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)) {
$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) {
}
}
+ // 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)) {
$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();