Permalink
Browse files

MDL-32933: Add outcomes to mod_assign and upgrade tool

  • Loading branch information...
1 parent 71d7bc3 commit a769a00157717262deae4a63f1dc3696f18b777e Damyon Wiese committed May 11, 2012
Showing with 100 additions and 45 deletions.
  1. +28 −2 mod/assign/gradingtable.php
  2. +62 −2 mod/assign/locallib.php
  3. +10 −41 mod/assign/upgradelib.php
@@ -171,6 +171,13 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
$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 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
$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 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset=0) {
}
}
- // 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);
}
/**
@@ -229,6 +236,25 @@ function display_grade($grade) {
}
/**
+ * 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)
*
* @param stdClass $row
@@ -560,7 +560,7 @@ public function get_admin_config() {
if ($this->adminconfig) {
return $this->adminconfig;
}
- $this->adminconfig = get_config('mod_assign');
+ $this->adminconfig = get_config('assign');
return $this->adminconfig;
}
@@ -2487,8 +2487,30 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
}
}
}
- $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);
@@ -2702,6 +2724,43 @@ private function process_unlock($userid = 0) {
}
/**
+ * 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
*
* @param moodleform $mform
@@ -2763,6 +2822,7 @@ private function process_save_grade(&$mform) {
}
}
}
+ $this->process_outcomes($userid, $formdata);
$this->update_grade($grade);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
@@ -105,6 +105,7 @@ public function upgrade_assignment($oldassignmentid, & $log) {
$gradingdefinitions = null;
$gradeidmap = array();
$completiondone = false;
+ $gradesdone = false;
// from this point we want to rollback on failure
$rollback = false;
@@ -213,14 +214,22 @@ public function upgrade_assignment($oldassignmentid, & $log) {
$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;
$log .= get_string('conversionexception', 'mod_assign', $exception->getMessage());
}
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 @@ private function delete_course_module($cm) {
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;
- }
-
}

0 comments on commit a769a00

Please sign in to comment.