From 0c61a163aec8ccf71d76bc45914bbff8ae522930 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 19 Apr 2017 16:12:09 +0200 Subject: [PATCH] MDL-58628 mod_quiz: Return missing fields in get_quizzes_by_courses These fields must be returned always (even if the quiz is closed). Those fields are required to display data to users that, for example, finished a timed quiz. --- mod/quiz/classes/external.php | 16 ++++++++-------- mod/quiz/tests/external_test.php | 13 +++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/mod/quiz/classes/external.php b/mod/quiz/classes/external.php index d38a9070701..a9926c80896 100644 --- a/mod/quiz/classes/external.php +++ b/mod/quiz/classes/external.php @@ -109,7 +109,11 @@ class mod_quiz_external extends external_api { $quiz->introformat, $context->id, 'mod_quiz', 'intro', null); $viewablefields = array('timeopen', 'timeclose', 'grademethod', 'section', 'visible', 'groupmode', - 'groupingid'); + 'groupingid', 'attempts', 'timelimit', 'grademethod', 'decimalpoints', + 'questiondecimalpoints', 'sumgrades', 'grade', 'preferredbehaviour'); + // Some times this function returns just empty. + $hasfeedback = quiz_has_feedback($quiz); + $quizdetails['hasfeedback'] = (!empty($hasfeedback)) ? 1 : 0; $timenow = time(); $quizobj = quiz::create($quiz->id, $USER->id); @@ -118,19 +122,15 @@ class mod_quiz_external extends external_api { // Fields the user could see if have access to the quiz. if (!$accessmanager->prevent_access()) { - // Some times this function returns just empty. - $hasfeedback = quiz_has_feedback($quiz); - $quizdetails['hasfeedback'] = (!empty($hasfeedback)) ? 1 : 0; $quizdetails['hasquestions'] = (int) $quizobj->has_questions(); $quizdetails['autosaveperiod'] = get_config('quiz', 'autosaveperiod'); - $additionalfields = array('timelimit', 'attempts', 'attemptonlast', 'grademethod', 'decimalpoints', - 'questiondecimalpoints', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', + $additionalfields = array('attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', 'reviewspecificfeedback', 'reviewgeneralfeedback', 'reviewrightanswer', - 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'sumgrades', 'grade', + 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'browsersecurity', 'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'completionpass', 'overduehandling', - 'graceperiod', 'preferredbehaviour', 'canredoquestions'); + 'graceperiod', 'canredoquestions'); $viewablefields = array_merge($viewablefields, $additionalfields); } diff --git a/mod/quiz/tests/external_test.php b/mod/quiz/tests/external_test.php index a62bb95ce65..38b8681fe72 100644 --- a/mod/quiz/tests/external_test.php +++ b/mod/quiz/tests/external_test.php @@ -189,15 +189,16 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase { // Create what we expect to be returned when querying the two courses. // First for the student user. - $allusersfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'timeopen', 'timeclose', - 'grademethod', 'section', 'visible', 'groupmode', 'groupingid'); - $userswithaccessfields = array('timelimit', 'attempts', 'attemptonlast', 'grademethod', 'decimalpoints', - 'questiondecimalpoints', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', + $allusersfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'timeopen', + 'timeclose', 'grademethod', 'section', 'visible', 'groupmode', 'groupingid', + 'attempts', 'timelimit', 'grademethod', 'decimalpoints', 'questiondecimalpoints', 'sumgrades', + 'grade', 'preferredbehaviour', 'hasfeedback'); + $userswithaccessfields = array('attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', 'reviewspecificfeedback', 'reviewgeneralfeedback', 'reviewrightanswer', - 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'sumgrades', 'grade', + 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'browsersecurity', 'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'completionpass', 'autosaveperiod', 'hasquestions', - 'hasfeedback', 'overduehandling', 'graceperiod', 'preferredbehaviour', 'canredoquestions'); + 'overduehandling', 'graceperiod', 'canredoquestions'); $managerfields = array('shuffleanswers', 'timecreated', 'timemodified', 'password', 'subnet'); // Add expected coursemodule and other data.