From cc03871ba30006b40c638616f8e59d89b99ab307 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 2 Aug 2007 22:38:52 +0000 Subject: [PATCH] MDL-10549 outcomes quickgrading in assignment TODO: fix html and CSS --- lang/en_utf8/grades.php | 1 + lib/grade/grade_item.php | 6 +- mod/assignment/lib.php | 130 ++++++++++++------ .../type/offline/assignment.class.php | 3 + 4 files changed, 93 insertions(+), 47 deletions(-) diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index f17999f55a..6a97320fa4 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -226,6 +226,7 @@ $string['nolettergrade'] = 'No letter grade for'; $string['nomode'] = 'NA'; $string['nonnumericweight'] = 'Received non-numeric value for'; $string['nonweightedpct'] = 'non-weighted %%'; +$string['nooutcome'] = 'No outcome'; $string['noselectedcategories'] = 'no categories were selected.'; $string['noselecteditems'] = 'no items were selected.'; $string['notteachererror'] = 'You must be a teacher to use this feature.'; diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index c1a4092655..106fb352f3 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1257,7 +1257,8 @@ class grade_item extends grade_object { } } - if ($result and !$grade->overridden) { + // no events for overridden items and outcomes + if ($result and !$grade->overridden and $this->itemnumber < 1000) { $this->trigger_raw_updated($grade, $source); } @@ -1354,7 +1355,8 @@ class grade_item extends grade_object { } } - if ($result) { + // no events for outcomes + if ($result and $this->itemnumber < 1000) { $this->trigger_raw_updated($grade, $source); } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index d1922157a0..5bf1043b57 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -503,7 +503,6 @@ class assignment_base { switch ($mode) { case 'grade': // We are in a popup window grading - $this->process_outcomes(); if ($submission = $this->process_feedback()) { //IE needs proper header with encoding print_header(get_string('feedback', 'assignment').':'.format_string($this->assignment->name)); @@ -542,6 +541,9 @@ class assignment_base { foreach ($_POST[$col] as $id => $unusedvalue){ $id = (int)$id; //clean parameter name + + $this->process_outcomes($id); + if (!$submission = $this->get_submission($id)) { $submission = $this->prepare_new_submission($id); $newsubmission = true; @@ -600,6 +602,7 @@ class assignment_base { } } + print_heading(get_string('changessaved')); $this->display_submissions(); break; @@ -616,7 +619,6 @@ class assignment_base { case 'saveandnext': ///We are in pop up. save the current one and go to the next one. //first we save the current changes - $this->process_outcomes(); if ($submission = $this->process_feedback()) { //print_heading(get_string('changessaved')); $extra_javascript = $this->update_main_listing($submission); @@ -688,6 +690,29 @@ class assignment_base { 'grade'.$submission->userid, $buttontext, 450, 700, $buttontext, 'none', true, 'button'.$submission->userid); $output.= 'opener.document.getElementById("up'.$submission->userid.'").innerHTML="'.addslashes_js($button).'";'; } + + if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['outcomes'])) { + // TODO: add some javascript for updating of outcomes here + if ($outcomes_data = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $submission->userid)) { + foreach($outcomes_data as $n=>$data) { + if ($data->locked) { + continue; + } + + if ($quickgrade){ + $output.= 'opener.document.getElementById("outcome_'.$n.'_'.$submission->userid. + '").selectedIndex="'.$data->grade.'";'."\n"; + } else { + $options = make_grades_menu(-$data->scaleid); + $options[0] = get_string('nooutcome', 'grades'); + $output.= 'opener.document.getElementById("outcome_'.$n.'_'.$submission->userid.'").innerHTML="'.$options[$data->grade]."\";\n"; + + } + + } + } + } + $output .= "\n-->\n"; return $output; } @@ -738,6 +763,7 @@ class assignment_base { function display_submission($extra_javascript = '') { global $CFG; + require_once($CFG->libdir.'/gradelib.php'); $userid = required_param('userid', PARAM_INT); $offset = required_param('offset', PARAM_INT);//offset for where to start looking for student. @@ -841,27 +867,27 @@ class assignment_base { echo '
'.userdate($submission->timemarked).'
'; echo ''; } - echo '
'.get_string('grade').':'; + echo '
'; choose_from_menu(make_grades_menu($this->assignment->grade), 'grade', $submission->grade, get_string('nograde'), '', -1); echo '
'; + echo '
'; - require_once($CFG->libdir.'/gradelib.php'); - if ($outcomes = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid)) { + if ($outcomes_data = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid)) { echo '
'; - foreach($outcomes as $n=>$data) { - echo format_string($data->name).':'; + foreach($outcomes_data as $n=>$data) { + echo '
'; $options = make_grades_menu(-$data->scaleid); if ($data->locked) { - $options[0] = get_string('nograde'); + $options[0] = get_string('nooutcome', 'grades'); echo $options[$data->grade]; } else { - choose_from_menu($options, 'outcome_'.$n, $data->grade, get_string('nograde'), '', -1); + choose_from_menu($options, 'outcome_'.$n.'['.$userid.']', $data->grade, get_string('nooutcome', 'grades'), '', 0); } + echo '
'; } echo '
'; } - echo '
'; $this->preprocess_submission($submission); @@ -939,8 +965,8 @@ class assignment_base { * Display all the submissions ready for grading */ function display_submissions() { - global $CFG, $db, $USER; + require_once($CFG->libdir.'/gradelib.php'); /* first we check to see if the form has just been submitted * to request user_preference updates @@ -995,8 +1021,8 @@ class assignment_base { /// Get all ppl that are allowed to submit assignments $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false); - $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status'); - $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status')); + $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', ''); + $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status'), get_string('outcomes', 'grades')); require_once($CFG->libdir.'/tablelib.php'); $table = new flexible_table('mod-assignment-submissions'); @@ -1019,6 +1045,7 @@ class assignment_base { $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); + $table->column_class('outcomes', 'outcomes'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); @@ -1149,11 +1176,28 @@ class assignment_base { } else { ///No more buttons, we use popups ;-). $button = link_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$auser->id.'&mode=single'.'&offset='.$offset++, - 'grade'.$auser->id, $buttontext, 500, 780, $buttontext, 'none', true, 'button'.$auser->id); + 'grade'.$auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button'.$auser->id); $status = '
'.$button.'
'; } - $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status); + + $outcomes = ''; + if ($outcomes_data = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $auser->id)) { + foreach($outcomes_data as $n=>$data) { + $outcomes .= '
'; + $options = make_grades_menu(-$data->scaleid); + if ($data->locked or !$quickgrade) { + $options[0] = get_string('nooutcome', 'grades'); + $outcomes .= ':'.$options[$data->grade].''; + } else { + $outcomes .= choose_from_menu($options, 'outcome_'.$n.'['.$auser->id.']', $data->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_'.$n.'_'.$auser->id); + } + echo '
'; + } + } + + + $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $outcomes); $table->add_data($row); } } @@ -1214,36 +1258,6 @@ class assignment_base { print_footer($this->course); } - /** - * Process teacher outcomes - * - * This is called by submissions() when a grading even has taken place. - * It gets its data from the submitted form. - */ - function process_outcomes() { - global $CFG; - - if (!$formdata = data_submitted()) { // No incoming data? - return; - } - - $userid = $formdata->userid; - - require_once($CFG->libdir.'/gradelib.php'); - $data = array(); - if ($outcomes = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid)) { - foreach($outcomes as $n=>$old) { - $name = 'outcome_'.$n; - if (array_key_exists($name, $formdata)) { - $data[$n] = $formdata->$name; - } - } - } - if (count($data) > 0) { - grade_update_outcomes('mod/assignment', $this->course->id, 'mod', 'assignment', $this->assignment->id, $userid, $data); - } - } - /** * Process teacher feedback submission * @@ -1270,6 +1284,9 @@ class assignment_base { return false; } + // store outcomes if needed + $this->process_outcomes($feedback->userid); + $submission = $this->get_submission($feedback->userid, true); // Get or make one $submission->grade = $feedback->grade; @@ -1300,6 +1317,29 @@ class assignment_base { } + function process_outcomes($userid) { + global $CFG, $USER; + require_once($CFG->libdir.'/gradelib.php'); + + if (!$formdata = data_submitted()) { + return; + } + + $data = array(); + if ($outcomes = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid)) { + foreach($outcomes as $n=>$old) { + $name = 'outcome_'.$n; + if (isset($formdata->{$name}[$userid]) and $old->grade != $formdata->{$name}[$userid]) { + $data[$n] = $formdata->{$name}[$userid]; + } + } + } + if (count($data) > 0) { + grade_update_outcomes('mod/assignment', $this->course->id, 'mod', 'assignment', $this->assignment->id, $userid, $data); + } + + } + /** * Load the submission object for a particular user * diff --git a/mod/assignment/type/offline/assignment.class.php b/mod/assignment/type/offline/assignment.class.php index c92c215d1c..8e86d9133b 100644 --- a/mod/assignment/type/offline/assignment.class.php +++ b/mod/assignment/type/offline/assignment.class.php @@ -55,6 +55,9 @@ class assignment_offline extends assignment_base { return false; } + // store outcomes if needed + $this->process_outcomes($feedback->userid); + $submission = $this->get_submission($feedback->userid, true); // Get or make one $submission->grade = $feedback->grade; -- 2.39.5