mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-10544 basic support for outcomes grading in modules - implemented in assignment popup grading (TODO: fix html and css there)
This commit is contained in:
parent
56c28adb97
commit
3a5ae6602b
3 changed files with 128 additions and 19 deletions
|
@ -988,14 +988,14 @@ class grade_item extends grade_object {
|
|||
* @param int $userid
|
||||
* @return object grade_grade object instance
|
||||
*/
|
||||
function get_grade($userid) {
|
||||
function get_grade($userid, $create=true) {
|
||||
if (empty($this->id)) {
|
||||
debugging('Can not use before insert');
|
||||
return false;
|
||||
}
|
||||
|
||||
$grade = new grade_grade(array('userid'=>$userid, 'itemid'=>$this->id));
|
||||
if (empty($grade->id)) {
|
||||
if (empty($grade->id) and $create) {
|
||||
$grade->insert();
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ require_once($CFG->libdir . '/grade/grade_grade_text.php');
|
|||
*
|
||||
* @param string $source source of the grade such as 'mod/assignment', often used to prevent infinite loops when processing grade_updated events
|
||||
* @param int $courseid id of course
|
||||
* @param string $itemtype type of grade item - mod, block, gradecategory, calculated
|
||||
* @param string $itemtype type of grade item - mod, block
|
||||
* @param string $itemmodule more specific then $itemtype - assignment, forum, etc.; maybe NULL for some item types
|
||||
* @param int $iteminstance instance it of graded subject
|
||||
* @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
|
||||
|
@ -262,22 +262,21 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
|
|||
|
||||
|
||||
/**
|
||||
* Tells a module whether a grade (or grade_item if $userid is not given) is currently locked or not.
|
||||
* This is a combination of the actual settings in the grade tables and a check on moodle/course:editgradeswhenlocked.
|
||||
* If it's locked to the current use then the module can print a nice message or prevent editing in the module.
|
||||
* If no $userid is given, the method will always return the grade_item's locked state.
|
||||
* If a $userid is given, the method will first check the grade_item's locked state (the column). If it is locked,
|
||||
* the method will return true no matter the locked state of the specific grade being checked. If unlocked, it will
|
||||
* return the locked state of the specific grade.
|
||||
*
|
||||
* @param int $courseid id of course
|
||||
* @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc
|
||||
* @param string $itemmodule 'forum, 'quiz', 'csv' etc
|
||||
* @param int $iteminstance id of the item module
|
||||
* @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
|
||||
* @param int $userid ID of the graded user
|
||||
* @return boolean Whether the grade is locked or not
|
||||
*/
|
||||
* Tells a module whether a grade (or grade_item if $userid is not given) is currently locked or not.
|
||||
* If it's locked to the current use then the module can print a nice message or prevent editing in the module.
|
||||
* If no $userid is given, the method will always return the grade_item's locked state.
|
||||
* If a $userid is given, the method will first check the grade_item's locked state (the column). If it is locked,
|
||||
* the method will return true no matter the locked state of the specific grade being checked. If unlocked, it will
|
||||
* return the locked state of the specific grade.
|
||||
*
|
||||
* @param int $courseid id of course
|
||||
* @param string $itemtype 'mod', 'block'
|
||||
* @param string $itemmodule 'forum, 'quiz', etc.
|
||||
* @param int $iteminstance id of the item module
|
||||
* @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
|
||||
* @param int $userid ID of the graded user
|
||||
* @return boolean Whether the grade is locked or not
|
||||
*/
|
||||
function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $userid=NULL) {
|
||||
|
||||
if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
|
||||
|
@ -298,6 +297,67 @@ function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $item
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of outcomes used in course together with current outcomes for this user
|
||||
* @param int $courseid id of course
|
||||
* @param string $itemtype 'mod', 'block'
|
||||
* @param string $itemmodule 'forum, 'quiz', etc.
|
||||
* @param int $iteminstance id of the item module
|
||||
* @param int $userid ID of the graded user
|
||||
* @return array of outcome information objects (scaleid, name, grade and locked status) indexed with itemnumbers
|
||||
*/
|
||||
function grade_get_outcomes($courseid, $itemtype, $itemmodule, $iteminstance, $userid) {
|
||||
$result = array();
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
|
||||
foreach ($items as $item) {
|
||||
if (empty($item->outcomeid)) {
|
||||
continue;
|
||||
}
|
||||
if (!$outcome = grade_outcome::fetch(array('id'=>$item->outcomeid))) {
|
||||
debugging('Incorect outcomeid found');
|
||||
continue;
|
||||
}
|
||||
// prepare outcome info with user grade
|
||||
$o = new object();
|
||||
$o->scaleid = $outcome->scaleid;
|
||||
$o->name = $outcome->fullname;
|
||||
|
||||
if ($grade = $item->get_grade($userid,false)) {
|
||||
$o->grade = $grade->finalgrade;
|
||||
$o->locked = $grade->is_locked();
|
||||
} else {
|
||||
$o->grade = null;
|
||||
$o->locked = $item->is_locked();
|
||||
}
|
||||
$o->grade = intval($o->grade); // 0 means no grade, int for scales
|
||||
|
||||
$result[$item->itemnumber] = $o;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates outcomes of user
|
||||
* @param int $courseid id of course
|
||||
* @param string $itemtype 'mod', 'block'
|
||||
* @param string $itemmodule 'forum, 'quiz', etc.
|
||||
* @param int $iteminstance id of the item module
|
||||
* @param int $userid ID of the graded user
|
||||
*/
|
||||
function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $iteminstance, $userid, $data) {
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
|
||||
foreach ($items as $item) {
|
||||
if (!array_key_exists($item->itemnumber, $data)) {
|
||||
continue;
|
||||
}
|
||||
$grade = $data[$item->itemnumber] < 1 ? null : $data[$item->itemnumber];
|
||||
$item->update_final_grade($userid, $grade, $source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***** END OF PUBLIC API *****/
|
||||
|
||||
function grade_force_full_regrading($courseid) {
|
||||
|
|
|
@ -503,6 +503,7 @@ 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));
|
||||
|
@ -615,6 +616,7 @@ 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);
|
||||
|
@ -842,6 +844,23 @@ class assignment_base {
|
|||
echo '<div class="grade">'.get_string('grade').':';
|
||||
choose_from_menu(make_grades_menu($this->assignment->grade), 'grade', $submission->grade, get_string('nograde'), '', -1);
|
||||
echo '</div>';
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
if ($outcomes = grade_get_outcomes($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid)) {
|
||||
echo '<div class="outcomes">';
|
||||
foreach($outcomes as $n=>$data) {
|
||||
echo format_string($data->name).':';
|
||||
$options = make_grades_menu(-$data->scaleid);
|
||||
if ($data->locked) {
|
||||
$options[0] = get_string('nograde');
|
||||
echo $options[$data->grade];
|
||||
} else {
|
||||
choose_from_menu($options, 'outcome_'.$n, $data->grade, get_string('nograde'), '', -1);
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div class="clearer"></div>';
|
||||
|
||||
$this->preprocess_submission($submission);
|
||||
|
@ -1195,6 +1214,36 @@ 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
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue