Merge branch 'MDL-59133-master' of git://github.com/jleyva/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 12 Jun 2017 23:25:52 +0000 (01:25 +0200)
committerDan Poltawski <dan@moodle.com>
Wed, 14 Jun 2017 11:30:42 +0000 (12:30 +0100)
mod/lesson/classes/external.php
mod/lesson/locallib.php
mod/lesson/tests/external_test.php
mod/lesson/upgrade.txt

index 7763d6e..1e53c1c 100644 (file)
@@ -1814,6 +1814,10 @@ class mod_lesson_external extends external_api {
         }
 
         list($answerpages, $userstats) = lesson_get_user_detailed_report_data($lesson, $userid, $params['lessonattempt']);
+        // Convert page object to page record.
+        foreach ($answerpages as $answerp) {
+            $answerp->page = self::get_page_fields($answerp->page);
+        }
 
         $result = array(
             'answerpages' => $answerpages,
@@ -1835,6 +1839,7 @@ class mod_lesson_external extends external_api {
                 'answerpages' => new external_multiple_structure(
                     new external_single_structure(
                         array(
+                            'page' => self::get_page_structure(VALUE_OPTIONAL),
                             'title' => new external_value(PARAM_RAW, 'Page title.'),
                             'contents' => new external_value(PARAM_RAW, 'Page contents.'),
                             'qtype' => new external_value(PARAM_TEXT, 'Identifies the page type of this page.'),
index 8c32a2d..e0b143b 100644 (file)
@@ -1078,6 +1078,8 @@ function lesson_get_user_detailed_report_data(lesson $lesson, $userid, $attempt)
     while ($pageid != 0) { // EOL
         $page = $lessonpages[$pageid];
         $answerpage = new stdClass;
+        // Keep the original page object.
+        $answerpage->page = $page;
         $data ='';
 
         $answerdata = new stdClass;
index 3131639..64c5be9 100644 (file)
@@ -1217,6 +1217,14 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals(1, $result['userstats']['gradeinfo']['total']);     // Total correct answers.
         $this->assertEquals(100, $result['userstats']['gradeinfo']['grade']);   // Correct answer.
 
+        // Check page object contains the lesson pages answered.
+        $pagesanswered = array();
+        foreach ($result['answerpages'] as $answerp) {
+            $pagesanswered[] = $answerp['page']['id'];
+        }
+        sort($pagesanswered);
+        $this->assertEquals(array($this->page1->id, $this->page2->id), $pagesanswered);
+
         // Test second attempt unfinished.
         $result = mod_lesson_external::get_user_attempt($this->lesson->id, $this->student->id, 1);
         $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
index 79cc01a..9372654 100644 (file)
@@ -1,5 +1,9 @@
 This files describes API changes in the lesson code.
 
+=== 3.4 ===
+
+* External function mod_lesson_external::get_user_attempt() now returns the full page object inside each answerpages.
+
 === 3.3 ===
 
 * lesson::callback_on_view() has an additional optional parameter $redirect default to true.