From 76dc0848c16cb326d2e0b7f76b9bdf18fb0b3fca Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 23 Jul 2014 18:03:47 +0200 Subject: [PATCH] MDL-46460 Web Services: Invalid check of grades visibility for missing grades --- lib/classes/grades_external.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/classes/grades_external.php b/lib/classes/grades_external.php index 96488db6df1..3bd31c099fe 100644 --- a/lib/classes/grades_external.php +++ b/lib/classes/grades_external.php @@ -169,14 +169,18 @@ class core_grades_external extends external_api { if (!empty($gradeitem->grades)) { foreach ($gradeitem->grades as $studentid => $studentgrade) { - $gradegradeinstance = grade_grade::fetch( - array( - 'userid' => $studentid, - 'itemid' => $gradeiteminstance->id - ) - ); - if (!$canviewhidden && $gradegradeinstance->is_hidden()) { - continue; + if (!$canviewhidden) { + // Need to load the grade_grade object to check visibility. + $gradegradeinstance = grade_grade::fetch( + array( + 'userid' => $studentid, + 'itemid' => $gradeiteminstance->id + ) + ); + // The grade grade may be legitimately missing if the student has no grade. + if (!empty($gradegradeinstance) && $gradegradeinstance->is_hidden()) { + continue; + } } $gradeitemarray['grades'][$studentid] = (array)$studentgrade; // Add the student ID as some WS clients can't access the array key.