|
@@ -177,7 +177,7 @@ function gradeimporter_grade_item_update ($submission, $grades = null) {
|
|
|
$params['gradetype'] = GRADE_TYPE_NONE;
|
|
|
} else {
|
|
|
$params['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
- $params['grademax'] = 10;
|
|
|
+ $params['grademax'] = $submission->maxgrade;
|
|
|
$params['grademin'] = 0;
|
|
|
}
|
|
|
|
|
@@ -203,16 +203,19 @@ function gradeimporter_update_grades ($submission, $userid = 0, $nullifnone = tr
|
|
|
if ($grades = gradeimporter_get_user_grades($submission, $userid)) {
|
|
|
// Gets student grade from gradeimporter_feedback table
|
|
|
gradeimporter_grade_item_update($submission, $grades);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- } else if ($userid and $nullifnone) {
|
|
|
+ if ($userid and $nullifnone) {
|
|
|
$grade = new stdClass();
|
|
|
$grade->userid = $userid;
|
|
|
$grade->rawgrade = null;
|
|
|
gradeimporter_grade_item_update($submission, $grade);
|
|
|
-
|
|
|
- } else {
|
|
|
- gradeimporter_grade_item_update($submission);
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ gradeimporter_grade_item_update($submission);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function gradeimporter_reset_gradebook ($courseid, $type = '') {
|
|
@@ -221,19 +224,92 @@ function gradeimporter_reset_gradebook ($courseid, $type = '') {
|
|
|
}
|
|
|
|
|
|
function gradeimporter_get_user_grades($submission, $userid) {
|
|
|
- global $DB;
|
|
|
+ global $DB, $CFG;
|
|
|
$grade = new stdClass();
|
|
|
$grade->userid = $userid;
|
|
|
|
|
|
- $feedback = $DB->get_record('gradeimporter_feedback',
|
|
|
- ['submissionid' => $submission->id, 'studendit' => $userid],
|
|
|
- ['grade']
|
|
|
- );
|
|
|
-
|
|
|
- if ($feedback) {
|
|
|
- $grade->rawgrade = $feedback->grade;
|
|
|
+ $tp = $CFG->prefix;
|
|
|
+ $sql = "SELECT gf.id, gf.grade as grade
|
|
|
+ FROM {$tp}gradeimporter_feedback as gf
|
|
|
+ JOIN {$tp}gradeimporter_submission as gs
|
|
|
+ ON gs.id = gf.submissionid
|
|
|
+ JOIN {$tp}gradeimporter as gi
|
|
|
+ ON gi.id = gs.gradeimporterid
|
|
|
+ WHERE gf.studentid = $userid
|
|
|
+ AND gi.id = $submission->gradeimporterid
|
|
|
+ AND gs.gradebook = 1
|
|
|
+ AND gs.visibility = 1";
|
|
|
+ $feedbacks = $DB->get_records_sql($sql);
|
|
|
+
|
|
|
+ if ($feedbacks) {
|
|
|
+ $grade->rawgrade = sum_property($feedbacks, 'grade');
|
|
|
return $grade;
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+function sum_property ($array, $property) {
|
|
|
+ $sum = 0;
|
|
|
+ foreach ($array as $object) {
|
|
|
+ $sum += $object->$property;
|
|
|
+ }
|
|
|
+ return $sum;
|
|
|
+}
|
|
|
+
|
|
|
+function create_grade_item($submission) {
|
|
|
+ global $CFG, $COURSE;
|
|
|
+
|
|
|
+ require_once("{$CFG->libdir}/gradelib.php");
|
|
|
+
|
|
|
+ $gradeitem = new grade_item(array('id' => 0, 'courseid' => $COURSE->id));
|
|
|
+ $data = new stdClass();
|
|
|
+ $data->itemname = $submission->name;
|
|
|
+ $data->iteminfo = $submission->intro;
|
|
|
+ // Blank [idnumer] for now
|
|
|
+ $data->outcomeid = $submission->gradeimporterid;
|
|
|
+ $data->cmid = $submission->gradeimporterid;
|
|
|
+ $data->id = 0;
|
|
|
+ $data->courseid = $COURSE->id;
|
|
|
+ $data->aggregationcoef = 0;
|
|
|
+ $data->itemtype = 'gradeimporter';
|
|
|
+
|
|
|
+ grade_item::set_properties($gradeitem, $data);
|
|
|
+
|
|
|
+ $gradeitem->itemnumber = $submission->id;
|
|
|
+
|
|
|
+ $outcome = grade_outcome::fetch(array('id' => $submission->gradeimporterid));
|
|
|
+ $gradeitem->gradetype = GRADE_TYPE_SCALE;
|
|
|
+ $gradeitem->scaleid = $outcome->scaleid;
|
|
|
+
|
|
|
+ $gradeitem->insert();
|
|
|
+
|
|
|
+ if ($item = grade_item::fetch(array('itemtype' => 'gradeimporter', 'itemmodule' => $gradeitem->itemmodule,
|
|
|
+ 'iteminstance' => $gradeitem->iteminstance, 'itemnumber' => 0, 'courseid' => $COURSE->id))) {
|
|
|
+ $gradeitem->set_parent($item->categoryid);
|
|
|
+ $gradeitem->move_after_sortorder($item->sortorder);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function insert_grade_outcome($submission, $userid) {
|
|
|
+ global $CFG, $DB, $COURSE;
|
|
|
+ echo "abdesg";
|
|
|
+ if (empty($CFG->enableoutcomes)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ echo "abc";
|
|
|
+ require_once("$CFG->libdir/gradelib.php");
|
|
|
+
|
|
|
+ $data = array();
|
|
|
+ $gradinginfo = grade_get_grades($COURSE->id, 'mod', 'gradeimporter', $submission->gradeimporterid, $userid);
|
|
|
+
|
|
|
+ if (!empty($gradinginfo->outcomes)) {
|
|
|
+ foreach ($gradinginfo->outcomes as $n => $old) {
|
|
|
+ $data[$n] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count($data) > 0) {
|
|
|
+ grade_update_outcomes('mod/gradeimporter', $COURSE->id, 'mod', 'gradeimporter', $submission->gradeimporterid, $userid, $data);
|
|
|
+ }
|
|
|
+}
|