mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-32933: Add outcomes to mod_assign and upgrade tool
This commit is contained in:
parent
71d7bc34a8
commit
a769a00157
@ -171,6 +171,13 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
$columns[] = 'finalgrade';
|
||||
$headers[] = get_string('finalgrade', 'grades');
|
||||
|
||||
// load the grading info for all users
|
||||
$this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
|
||||
|
||||
if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
|
||||
$columns[] = 'outcomes';
|
||||
$headers[] = get_string('outcomes', 'grades');
|
||||
}
|
||||
|
||||
|
||||
// set the columns
|
||||
@ -179,6 +186,8 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
$this->no_sorting('finalgrade');
|
||||
$this->no_sorting('edit');
|
||||
$this->no_sorting('select');
|
||||
$this->no_sorting('outcomes');
|
||||
|
||||
foreach ($this->assignment->get_submission_plugins() as $plugin) {
|
||||
if ($plugin->is_visible() && $plugin->is_enabled()) {
|
||||
$this->no_sorting('assignsubmission_' . $plugin->get_type());
|
||||
@ -190,8 +199,6 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
// load the grading info for all users
|
||||
$this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,6 +235,25 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a list of outcomes
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return string
|
||||
*/
|
||||
function col_outcomes(stdClass $row) {
|
||||
$outcomes = '';
|
||||
foreach($this->gradinginfo->outcomes as $index=>$outcome) {
|
||||
$options = make_grades_menu(-$outcome->scaleid);
|
||||
|
||||
$options[0] = get_string('nooutcome', 'grades');
|
||||
$outcomes .= $this->output->container($outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade], 'outcome');
|
||||
}
|
||||
|
||||
return $outcomes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a user picture for display (and update rownum as a sideeffect)
|
||||
*
|
||||
|
@ -560,7 +560,7 @@ class assign {
|
||||
if ($this->adminconfig) {
|
||||
return $this->adminconfig;
|
||||
}
|
||||
$this->adminconfig = get_config('mod_assign');
|
||||
$this->adminconfig = get_config('assign');
|
||||
return $this->adminconfig;
|
||||
}
|
||||
|
||||
@ -2487,8 +2487,30 @@ class assign {
|
||||
}
|
||||
}
|
||||
}
|
||||
$mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist))));
|
||||
|
||||
$gradinginfo = grade_get_grades($this->get_course()->id,
|
||||
'mod',
|
||||
'assign',
|
||||
$this->get_instance()->id,
|
||||
$userid);
|
||||
if (!empty($CFG->enableoutcomes)) {
|
||||
foreach($gradinginfo->outcomes as $index=>$outcome) {
|
||||
$options = make_grades_menu(-$outcome->scaleid);
|
||||
if ($outcome->grades[$userid]->locked) {
|
||||
$options[0] = get_string('nooutcome', 'grades');
|
||||
$mform->addElement('static', 'outcome_'.$index.'['.$userid.']', $outcome->name.':',
|
||||
$options[$outcome->grades[$userid]->grade]);
|
||||
} else {
|
||||
$options[''] = get_string('nooutcome', 'grades');
|
||||
$attributes = array('id' => 'menuoutcome_'.$index );
|
||||
$mform->addElement('select', 'outcome_'.$index.'['.$userid.']', $outcome->name.':', $options, $attributes );
|
||||
$mform->setType('outcome_'.$index.'['.$userid.']', PARAM_INT);
|
||||
$mform->setDefault('outcome_'.$index.'['.$userid.']', $outcome->grades[$userid]->grade );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist))));
|
||||
|
||||
// plugins
|
||||
$this->add_plugin_grade_elements($grade, $mform, $data);
|
||||
@ -2701,6 +2723,43 @@ class assign {
|
||||
$this->add_to_log('unlock submission', get_string('unlocksubmissionforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user))));
|
||||
}
|
||||
|
||||
/**
|
||||
* save outcomes submitted from grading form
|
||||
*
|
||||
* @param int $userid
|
||||
* @param stdClass $formdata
|
||||
*/
|
||||
private function process_outcomes($userid, $formdata) {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (empty($CFG->enableoutcomes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
$data = array();
|
||||
$gradinginfo = grade_get_grades($this->get_course()->id,
|
||||
'mod',
|
||||
'assign',
|
||||
$this->get_instance()->id,
|
||||
$userid);
|
||||
|
||||
if (!empty($gradinginfo->outcomes)) {
|
||||
foreach($gradinginfo->outcomes as $index=>$oldoutcome) {
|
||||
$name = 'outcome_'.$index;
|
||||
if (isset($formdata->{$name}[$userid]) and $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$userid]) {
|
||||
$data[$index] = $formdata->{$name}[$userid];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($data) > 0) {
|
||||
grade_update_outcomes('mod/assign', $this->course->id, 'mod', 'assign', $this->get_instance()->id, $userid, $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* save grade
|
||||
*
|
||||
@ -2763,6 +2822,7 @@ class assign {
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->process_outcomes($userid, $formdata);
|
||||
$this->update_grade($grade);
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
||||
|
@ -105,6 +105,7 @@ class assign_upgrade_manager {
|
||||
$gradingdefinitions = null;
|
||||
$gradeidmap = array();
|
||||
$completiondone = false;
|
||||
$gradesdone = false;
|
||||
|
||||
// from this point we want to rollback on failure
|
||||
$rollback = false;
|
||||
@ -213,7 +214,9 @@ class assign_upgrade_manager {
|
||||
$newassignment->update_gradebook(false,$newcoursemodule->id);
|
||||
|
||||
// copy the grades from the old assignment to the new one
|
||||
$this->copy_grades_for_upgrade($oldassignment, $newassignment);
|
||||
$DB->set_field('grade_items', 'itemmodule', 'assign', array('iteminstance'=>$oldassignment->id));
|
||||
$DB->set_field('grade_items', 'iteminstance', $newassignment->get_instance()->id, array('iteminstance'=>$oldassignment->id));
|
||||
$gradesdone = true;
|
||||
|
||||
} catch (Exception $exception) {
|
||||
$rollback = true;
|
||||
@ -221,6 +224,12 @@ class assign_upgrade_manager {
|
||||
}
|
||||
|
||||
if ($rollback) {
|
||||
// roll back the grades changes
|
||||
if ($gradesdone) {
|
||||
// copy the grades from the old assignment to the new one
|
||||
$DB->set_field('grade_items', 'itemmodule', 'assignment', array('iteminstance'=>$newassignment->get_instance()->id));
|
||||
$DB->set_field('grade_items', 'iteminstance', $oldassignment->id, array('iteminstance'=>$newassignment->get_instance()->id));
|
||||
}
|
||||
// roll back the completion changes
|
||||
if ($completiondone) {
|
||||
$DB->set_field('course_modules_completion', 'coursemoduleid', $oldcoursemodule->id, array('coursemoduleid'=>$newcoursemodule->id));
|
||||
@ -363,44 +372,4 @@ class assign_upgrade_manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function copies the grades from the old assignment module to this one.
|
||||
*
|
||||
* @param stdClass $oldassignment old assignment data record
|
||||
* @param assign $newassignment the new assign class
|
||||
* @return bool true or false
|
||||
*/
|
||||
public function copy_grades_for_upgrade($oldassignment, $newassignment) {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
// get the old and new grade items
|
||||
$oldgradeitems = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>'assignment', 'iteminstance'=>$oldassignment->id));
|
||||
if (!$oldgradeitems) {
|
||||
return false;
|
||||
}
|
||||
$oldgradeitem = array_pop($oldgradeitems);
|
||||
if (!$oldgradeitem) {
|
||||
return false;
|
||||
}
|
||||
$newgradeitems = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>'assign', 'iteminstance'=>$newassignment->get_instance()->id));
|
||||
if (!$newgradeitems) {
|
||||
return false;
|
||||
}
|
||||
$newgradeitem = array_pop($newgradeitems);
|
||||
if (!$newgradeitem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gradegrades = grade_grade::fetch_all(array('itemid'=>$oldgradeitem->id));
|
||||
if ($gradegrades) {
|
||||
foreach ($gradegrades as $gradeid=>$grade) {
|
||||
$grade->itemid = $newgradeitem->id;
|
||||
grade_update('mod/assign', $newassignment->get_course()->id, 'mod', 'assign', $newassignment->get_instance()->id, 0, $grade, NULL);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user