#34 Prevent invalid course module ID error
This commit is contained in:
parent
6230759d56
commit
3f632d3f5e
1 changed files with 8 additions and 3 deletions
|
@ -285,13 +285,18 @@ class element extends \mod_customcert\element {
|
||||||
* @param int $moduleid
|
* @param int $moduleid
|
||||||
* @param int $gradeformat
|
* @param int $gradeformat
|
||||||
* @param int $userid
|
* @param int $userid
|
||||||
* @return \stdClass the grade information
|
* @return \stdClass|bool the grade information, or false if there is none.
|
||||||
*/
|
*/
|
||||||
public static function get_mod_grade($moduleid, $gradeformat, $userid) {
|
public static function get_mod_grade($moduleid, $gradeformat, $userid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $moduleid), '*', MUST_EXIST);
|
if (!$cm = $DB->get_record('course_modules', array('id' => $moduleid))) {
|
||||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$module = $DB->get_record('modules', array('id' => $cm->module))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
||||||
if (!empty($gradeitem)) {
|
if (!empty($gradeitem)) {
|
||||||
|
|
Loading…
Reference in a new issue