MDL-12458 fixed gradebook upgrade/update problems when not grades yet in activities
This commit is contained in:
@@ -2147,7 +2147,7 @@ function assignment_update_grades($assignment=null, $userid=0, $nullifnone=true)
|
||||
}
|
||||
assignment_grade_item_update($assignment, $grades);
|
||||
} else {
|
||||
assignment_grade_item_update($assignment, NULL);
|
||||
assignment_grade_item_update($assignment);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
+7
-3
@@ -767,13 +767,16 @@ function data_update_grades($data=null, $userid=0, $nullifnone=true) {
|
||||
|
||||
if ($data != null) {
|
||||
if ($grades = data_get_user_grades($data, $userid)) {
|
||||
grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, $grades);
|
||||
data_grade_item_update($data, $grades);
|
||||
|
||||
} else if ($userid and $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, $grade);
|
||||
data_grade_item_update($data, $grade);
|
||||
|
||||
} else {
|
||||
data_grade_item_update($data);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -782,9 +785,10 @@ function data_update_grades($data=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($data = rs_fetch_next_record($rs)) {
|
||||
data_grade_item_update($data);
|
||||
if ($data->assessed) {
|
||||
data_update_grades($data, 0, false);
|
||||
} else {
|
||||
data_grade_item_update($data);
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
+7
-3
@@ -1123,13 +1123,16 @@ function forum_update_grades($forum=null, $userid=0, $nullifnone=true) {
|
||||
if ($forum != null) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
if ($grades = forum_get_user_grades($forum, $userid)) {
|
||||
grade_update('mod/forum', $forum->course, 'mod', 'forum', $forum->id, 0, $grades);
|
||||
forum_grade_item_update($forum, $grades);
|
||||
|
||||
} else if ($userid and $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
grade_update('mod/forum', $data->course, 'mod', 'forum', $forum->id, 0, $grade);
|
||||
forum_grade_item_update($forum, $grade);
|
||||
|
||||
} else {
|
||||
forum_grade_item_update($forum);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -1138,9 +1141,10 @@ function forum_update_grades($forum=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($forum = rs_fetch_next_record($rs)) {
|
||||
forum_grade_item_update($forum);
|
||||
if ($forum->assessed) {
|
||||
forum_update_grades($forum, 0, false);
|
||||
} else {
|
||||
forum_grade_item_update($forum);
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
@@ -318,13 +318,16 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
|
||||
|
||||
if ($glossary != null) {
|
||||
if ($grades = glossary_get_user_grades($glossary, $userid)) {
|
||||
grade_update('mod/glossary', $glossary->course, 'mod', 'glossary', $glossary->id, 0, $grades);
|
||||
glossary_grade_item_update($glossary, $grades);
|
||||
|
||||
} else if ($userid and $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
grade_update('mod/glossary', $glossary->course, 'mod', 'glossary', $glossary->id, 0, $grade);
|
||||
glossary_grade_item_update($glossary, $grade);
|
||||
|
||||
} else {
|
||||
glossary_grade_item_update($glossary);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -333,9 +336,10 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($glossary = rs_fetch_next_record($rs)) {
|
||||
glossary_grade_item_update($glossary);
|
||||
if ($glossary->assessed) {
|
||||
glossary_update_grades($glossary, 0, false);
|
||||
} else {
|
||||
glossary_grade_item_update($glossary);
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
+8
-5
@@ -1230,13 +1230,16 @@ function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
|
||||
}
|
||||
if ($hotpot) {
|
||||
if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
|
||||
grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, $grades);
|
||||
hotpot_grade_item_update($hotpot, $grades);
|
||||
|
||||
} else if ($userid && $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = null;
|
||||
grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, $grade);
|
||||
hotpot_grade_item_update($hotpot, $grade);
|
||||
|
||||
} else {
|
||||
hotpot_grade_item_update($hotpot);
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT h.*, cm.idnumber as cmidnumber
|
||||
@@ -1244,7 +1247,6 @@ function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($hotpot = rs_fetch_next_record($rs)) {
|
||||
hotpot_grade_item_update($hotpot);
|
||||
hotpot_update_grades($hotpot, 0, false);
|
||||
}
|
||||
rs_close($rs);
|
||||
@@ -1255,9 +1257,10 @@ function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
|
||||
* Update/create grade item for given hotpot
|
||||
*
|
||||
* @param object $hotpot object with extra cmidnumber
|
||||
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
|
||||
* @return object grade_item
|
||||
*/
|
||||
function hotpot_grade_item_update($hotpot) {
|
||||
function hotpot_grade_item_update($hotpot, $grades=NULL) {
|
||||
global $CFG;
|
||||
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
@@ -1278,7 +1281,7 @@ function hotpot_grade_item_update($hotpot) {
|
||||
$params['gradetype'] = GRADE_TYPE_NONE;
|
||||
}
|
||||
|
||||
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, NULL, $params);
|
||||
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, $grades, $params);
|
||||
}
|
||||
/**
|
||||
* Delete grade item for given hotpot
|
||||
|
||||
+7
-3
@@ -378,13 +378,16 @@ function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) {
|
||||
|
||||
if ($lesson != null) {
|
||||
if ($grades = lesson_get_user_grades($lesson, $userid)) {
|
||||
grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, $grades);
|
||||
lesson_grade_item_update($lesson, $grades);
|
||||
|
||||
} else if ($userid and $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, $grade);
|
||||
lesson_grade_item_update($lesson, $grade);
|
||||
|
||||
} else {
|
||||
lesson_grade_item_update($lesson);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -393,9 +396,10 @@ function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($lesson = rs_fetch_next_record($rs)) {
|
||||
lesson_grade_item_update($lesson);
|
||||
if ($lesson->grade != 0) {
|
||||
lesson_update_grades($lesson, 0, false);
|
||||
} else {
|
||||
lesson_grade_item_update($lesson);
|
||||
}
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
@@ -299,6 +299,9 @@ function quiz_update_grades($quiz=null, $userid=0, $nullifnone=true) {
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
quiz_grade_item_update($quiz, $grade);
|
||||
|
||||
} else {
|
||||
quiz_grade_item_update($quiz);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
+5
-3
@@ -461,13 +461,16 @@ function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
|
||||
|
||||
if ($scorm != null) {
|
||||
if ($grades = scorm_get_user_grades($scorm, $userid)) {
|
||||
grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades[$userid]);
|
||||
scorm_grade_item_update($scorm, $grades[$userid]);
|
||||
|
||||
} else if ($userid and $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = NULL;
|
||||
grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grade);
|
||||
scorm_grade_item_update($scorm, $grade);
|
||||
|
||||
} else {
|
||||
scorm_grade_item_update($scorm);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -476,7 +479,6 @@ function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
|
||||
WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($scorm = rs_fetch_next_record($rs)) {
|
||||
scorm_grade_item_update($scorm);
|
||||
scorm_update_grades($scorm, 0, false);
|
||||
}
|
||||
rs_close($rs);
|
||||
|
||||
Reference in New Issue
Block a user