From 16ca026c4b5a702c89b18e7d8091b475b9b8821e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 28 Mar 2017 10:22:09 +0200 Subject: [PATCH 1/8] MDL-58415 mod_lesson: Force int type for calculated progress Under some circumstances the value returned by the function needs casting. --- mod/lesson/locallib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index fff9f82e672..3f22939853c 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3107,7 +3107,8 @@ class lesson extends lesson_base { } // Progress calculation as a percent. - return round(count($viewedpageids) / count($validpages), 2) * 100; + $progress = round(count($viewedpageids) / count($validpages), 2) * 100; + return (int) $progress; } /** From 0259109fb5b1cf75344f69efc8092d1750bcb4d2 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 28 Mar 2017 10:58:52 +0200 Subject: [PATCH 2/8] MDL-58415 mod_lesson: Avoid API http redirections Deep in the lesson API there are some http redirections in special pages like clusters. We need to handle it via new parameters to avoid redirections. --- mod/lesson/classes/external.php | 76 ++++++++++++++------------- mod/lesson/locallib.php | 16 ++++-- mod/lesson/pagetypes/cluster.php | 6 +-- mod/lesson/pagetypes/endofbranch.php | 14 +++-- mod/lesson/pagetypes/endofcluster.php | 13 +++-- mod/lesson/upgrade.txt | 5 ++ mod/lesson/view.php | 2 +- 7 files changed, 78 insertions(+), 54 deletions(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index fb4c4392656..b3c16ebadee 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -934,7 +934,7 @@ class mod_lesson_external extends external_api { * @return external_single_structure * @since Moodle 3.3 */ - protected static function get_page_structure() { + protected static function get_page_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The id of this lesson page'), @@ -955,7 +955,7 @@ class mod_lesson_external extends external_api { 'typeid' => new external_value(PARAM_INT, 'The unique identifier for the page type'), 'typestring' => new external_value(PARAM_RAW, 'The string that describes this page type'), ), - 'Page fields' + 'Page fields', $required ); } @@ -1257,9 +1257,9 @@ class mod_lesson_external extends external_api { 'returncontents' => $returncontents); $params = self::validate_parameters(self::get_page_data_parameters(), $params); - $warnings = $contentfiles = $answerfiles = $responsefiles = array(); + $warnings = $contentfiles = $answerfiles = $responsefiles = $answers = array(); $pagecontent = $ongoingscore = ''; - $progress = null; + $progress = $pagedata = null; list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); self::validate_attempt($lesson, $params); @@ -1274,42 +1274,44 @@ class mod_lesson_external extends external_api { if ($pageid != LESSON_EOL) { $reviewmode = $lesson->is_in_review_mode(); $lessonoutput = $PAGE->get_renderer('mod_lesson'); - list($page, $pagecontent) = $lesson->prepare_page_and_contents($pageid, $lessonoutput, $reviewmode); - // Page may have changed. - $pageid = $page->id; + // Prepare page contents avoiding redirections. + list($pageid, $page, $pagecontent) = $lesson->prepare_page_and_contents($pageid, $lessonoutput, $reviewmode, false); - $pagedata = self::get_page_fields($page, true); + if ($pageid > 0) { - // Files. - $contentfiles = external_util::get_area_files($context->id, 'mod_lesson', 'page_contents', $page->id); + $pagedata = self::get_page_fields($page, true); - // Answers. - $answers = array(); - $pageanswers = $page->get_answers(); - foreach ($pageanswers as $a) { - $answer = array( - 'id' => $a->id, - 'answerfiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_answers', $a->id), - 'responsefiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_responses', $a->id), - ); - // For managers, return all the information (including correct answers, jumps). - // If the teacher enabled offline attempts, this information will be downloaded too. - if ($lesson->can_manage() || $lesson->allowofflineattempts) { - $extraproperties = array('jumpto', 'grade', 'score', 'flags', 'timecreated', 'timemodified'); - foreach ($extraproperties as $prop) { - $answer[$prop] = $a->{$prop}; + // Files. + $contentfiles = external_util::get_area_files($context->id, 'mod_lesson', 'page_contents', $page->id); + + // Answers. + $answers = array(); + $pageanswers = $page->get_answers(); + foreach ($pageanswers as $a) { + $answer = array( + 'id' => $a->id, + 'answerfiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_answers', $a->id), + 'responsefiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_responses', $a->id), + ); + // For managers, return all the information (including correct answers, jumps). + // If the teacher enabled offline attempts, this information will be downloaded too. + if ($lesson->can_manage() || $lesson->allowofflineattempts) { + $extraproperties = array('jumpto', 'grade', 'score', 'flags', 'timecreated', 'timemodified'); + foreach ($extraproperties as $prop) { + $answer[$prop] = $a->{$prop}; + } } + $answers[] = $answer; } - $answers[] = $answer; - } - // Additional lesson information. - if (!$lesson->can_manage()) { - if ($lesson->ongoing && !$reviewmode) { - $ongoingscore = $lesson->get_ongoing_score_message(); - } - if ($lesson->progressbar) { - $progress = $lesson->calculate_progress(); + // Additional lesson information. + if (!$lesson->can_manage()) { + if ($lesson->ongoing && !$reviewmode) { + $ongoingscore = $lesson->get_ongoing_score_message(); + } + if ($lesson->progressbar) { + $progress = $lesson->calculate_progress(); + } } } } @@ -1317,7 +1319,6 @@ class mod_lesson_external extends external_api { $messages = self::format_lesson_messages($lesson); $result = array( - 'page' => $pagedata, 'newpageid' => $pageid, 'ongoingscore' => $ongoingscore, 'progress' => $progress, @@ -1328,6 +1329,9 @@ class mod_lesson_external extends external_api { 'displaymenu' => !empty(lesson_displayleftif($lesson)), ); + if (!empty($pagedata)) { + $result['page'] = $pagedata; + } if ($params['returncontents']) { $result['pagecontent'] = $pagecontent; // Return the complete page contents rendered. } @@ -1344,7 +1348,7 @@ class mod_lesson_external extends external_api { public static function get_page_data_returns() { return new external_single_structure( array( - 'page' => self::get_page_structure(), + 'page' => self::get_page_structure(VALUE_OPTIONAL), 'newpageid' => new external_value(PARAM_INT, 'New page id (if a jump was made)'), 'pagecontent' => new external_value(PARAM_RAW, 'Page html content', VALUE_OPTIONAL), 'ongoingscore' => new external_value(PARAM_TEXT, 'The ongoing score message'), diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 3f22939853c..5a707a40806 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3117,16 +3117,23 @@ class lesson extends lesson_base { * @param int $pageid the given page id * @param mod_lesson_renderer $lessonoutput the lesson output rendered * @param bool $reviewmode whether we are in review mode or not + * @param bool $redirect Optional, default to true. Set to false to avoid redirection and return the page to redirect. * @return array the page object and contents * @throws moodle_exception * @since Moodle 3.3 */ - public function prepare_page_and_contents($pageid, $lessonoutput, $reviewmode) { + public function prepare_page_and_contents($pageid, $lessonoutput, $reviewmode, $redirect = true) { global $USER, $CFG; $page = $this->load_page($pageid); // Check if the page is of a special type and if so take any nessecary action. - $newpageid = $page->callback_on_view($this->can_manage()); + $newpageid = $page->callback_on_view($this->can_manage(), $redirect); + + // Avoid redirections returning the jump to special page id. + if (!$redirect && is_numeric($newpageid) && $newpageid < 0) { + return array($newpageid, null, null); + } + if (is_numeric($newpageid)) { $page = $this->load_page($newpageid); } @@ -3167,7 +3174,7 @@ class lesson extends lesson_base { ob_end_clean(); } - return array($page, $lessoncontent); + return array($page->id, $page, $lessoncontent); } /** @@ -4155,9 +4162,10 @@ abstract class lesson_page extends lesson_base { * is viewed * * @param bool $canmanage True if the user has the manage cap + * @param bool $redirect Optional, default to true. Set to false to avoid redirection and return the page to redirect. * @return mixed */ - public function callback_on_view($canmanage) { + public function callback_on_view($canmanage, $redirect = true) { return true; } diff --git a/mod/lesson/pagetypes/cluster.php b/mod/lesson/pagetypes/cluster.php index c179913fd55..31c01b3ae59 100644 --- a/mod/lesson/pagetypes/cluster.php +++ b/mod/lesson/pagetypes/cluster.php @@ -55,14 +55,14 @@ class lesson_page_type_cluster extends lesson_page { public function get_grayout() { return 1; } - public function callback_on_view($canmanage) { + public function callback_on_view($canmanage, $redirect = true) { global $USER; if (!$canmanage) { // Get the next page in the lesson cluster jump - return $this->lesson->cluster_jump($this->properties->id); + return (int) $this->lesson->cluster_jump($this->properties->id); } else { // get the next page - return $this->properties->nextpageid; + return (int) $this->properties->nextpageid; } } public function override_next_page() { diff --git a/mod/lesson/pagetypes/endofbranch.php b/mod/lesson/pagetypes/endofbranch.php index 634da76eb26..97a64835331 100644 --- a/mod/lesson/pagetypes/endofbranch.php +++ b/mod/lesson/pagetypes/endofbranch.php @@ -51,12 +51,11 @@ class lesson_page_type_endofbranch extends lesson_page { public function get_idstring() { return $this->typeidstring; } - public function callback_on_view($canmanage) { - $this->redirect_to_first_answer($canmanage); - exit; + public function callback_on_view($canmanage, $redirect = true) { + return (int) $this->redirect_to_first_answer($canmanage, $redirect); } - public function redirect_to_first_answer($canmanage) { + public function redirect_to_first_answer($canmanage, $redirect) { global $USER, $PAGE; $answers = $this->get_answers(); $answer = array_shift($answers); @@ -94,7 +93,12 @@ class lesson_page_type_endofbranch extends lesson_page { $jumpto = $this->properties->prevpageid; } - redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$jumpto))); + + if ($redirect) { + redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $jumpto))); + die; + } + return $jumpto; } public function get_grayout() { return 1; diff --git a/mod/lesson/pagetypes/endofcluster.php b/mod/lesson/pagetypes/endofcluster.php index f5543537053..8a0aaade21d 100644 --- a/mod/lesson/pagetypes/endofcluster.php +++ b/mod/lesson/pagetypes/endofcluster.php @@ -51,18 +51,21 @@ class lesson_page_type_endofcluster extends lesson_page { public function get_idstring() { return $this->typeidstring; } - public function callback_on_view($canmanage) { - $this->redirect_to_next_page($canmanage); - exit; + public function callback_on_view($canmanage, $redirect = true) { + return (int) $this->redirect_to_next_page($canmanage, $redirect); } - public function redirect_to_next_page() { + public function redirect_to_next_page($canmanage, $redirect) { global $PAGE; if ($this->properties->nextpageid == 0) { $nextpageid = LESSON_EOL; } else { $nextpageid = $this->properties->nextpageid; } - redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$nextpageid))); + if ($redirect) { + redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $nextpageid))); + die; + } + return $nextpageid; } public function get_grayout() { return 1; diff --git a/mod/lesson/upgrade.txt b/mod/lesson/upgrade.txt index 31608793a83..79cc01a3578 100644 --- a/mod/lesson/upgrade.txt +++ b/mod/lesson/upgrade.txt @@ -1,5 +1,10 @@ This files describes API changes in the lesson code. +=== 3.3 === + +* lesson::callback_on_view() has an additional optional parameter $redirect default to true. + It can be set to false to avoid redirection and return the page to redirect. + === 3.1 === * Removed the unused file reformat.php * removedoublecr() and importmodifiedaikenstyle() have now been removed. diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 0ca0495cc92..d74eda30693 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -212,7 +212,7 @@ if ($pageid != LESSON_EOL) { } } - list($page, $lessoncontent) = $lesson->prepare_page_and_contents($pageid, $lessonoutput, $reviewmode); + list($newpageid, $page, $lessoncontent) = $lesson->prepare_page_and_contents($pageid, $lessonoutput, $reviewmode); if (($edit != -1) && $PAGE->user_allowed_editing()) { $USER->editing = $edit; From 0fc1f24b12a46b49a3bd750d73c3e5ca6b87d9d5 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 28 Mar 2017 11:01:57 +0200 Subject: [PATCH 3/8] MDL-58415 mod_lesson: Handle correctly review mode --- mod/lesson/classes/external.php | 20 ++++++++++++++------ mod/lesson/lang/en/lesson.php | 1 + mod/lesson/locallib.php | 2 +- mod/lesson/tests/external_test.php | 10 ++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index b3c16ebadee..98afaa08c5c 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -294,12 +294,20 @@ class mod_lesson_external extends external_api { // Check if the user want to review an attempt he just finished. if (!empty($params['review'])) { - // Allow review only for completed attempts during active session time. - if ($timer->completed and ($timer->lessontime + $CFG->sessiontimeout > time()) ) { + // Allow review only for attempts during active session time. + if ($timer->lessontime + $CFG->sessiontimeout > time()) { $ntries = $lesson->count_user_retries($USER->id); - if ($attempts = $lesson->get_attempts($ntries)) { - $lastattempt = end($attempts); - $USER->modattempts[$lesson->id] = $lastattempt->pageid; + $ntries--; // Need to look at the old attempts. + if ($params['pageid'] == LESSON_EOL) { + if ($attempts = $lesson->get_attempts($ntries)) { + $lastattempt = end($attempts); + $USER->modattempts[$lesson->id] = $lastattempt->pageid; + } + } else { + if ($attempts = $lesson->get_attempts($ntries, false, $params['pageid'])) { + $lastattempt = end($attempts); + $USER->modattempts[$lesson->id] = $lastattempt; + } } } @@ -1582,7 +1590,7 @@ class mod_lesson_external extends external_api { $validmessages = array( 'notenoughtimespent', 'numberofpagesviewed', 'youshouldview', 'numberofcorrectanswers', 'displayscorewithessays', 'displayscorewithoutessays', 'yourcurrentgradeisoutof', 'eolstudentoutoftimenoanswers', - 'welldone', 'displayofgrade', 'reviewlesson', 'modattemptsnoteacher', 'progresscompleted'); + 'welldone', 'displayofgrade', 'modattemptsnoteacher', 'progresscompleted'); $data = array(); foreach ($result as $el => $value) { diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index b61512ee5a0..d86b4b320db 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -465,6 +465,7 @@ $string['startlesson'] = 'Start lesson'; $string['studentattemptlesson'] = '{$a->lastname}, {$a->firstname}\'s attempt number {$a->attempt}'; $string['studentname'] = '{$a} Name'; $string['studentoneminwarning'] = 'Warning: You have 1 minute or less to finish the lesson.'; +$string['studentoutoftimeforreview'] = 'Attention: You ran out of time for reviewing this lesson'; $string['studentresponse'] = '{$a}\'s response'; $string['submit'] = 'Submit'; $string['submitname'] = 'Submit name'; diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 5a707a40806..4e9fe4969e1 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3496,7 +3496,7 @@ class lesson extends lesson_base { $url = new moodle_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $pageid)); } - $data->reviewlesson = $url; + $data->reviewlesson = $url->out(false); } else if ($this->properties->modattempts && $canmanage) { $data->modattemptsnoteacher = true; } diff --git a/mod/lesson/tests/external_test.php b/mod/lesson/tests/external_test.php index e8c5052f852..56fc8522f24 100644 --- a/mod/lesson/tests/external_test.php +++ b/mod/lesson/tests/external_test.php @@ -840,7 +840,7 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase { 'pageid' => $this->page2->id, 'userid' => $this->student->id, 'answerid' => 0, - 'retry' => 1, + 'retry' => 0, // First attempt is always 0. 'correct' => 1, 'useranswer' => '1', 'timeseen' => time(), @@ -857,15 +857,9 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase { $DB->insert_record('lesson_grades', (object) $record); unset($SESSION->lesson_messages); - $this->setUser($this->teacher); - $result = mod_lesson_external::launch_attempt($this->lesson->id, '', 1, true); - $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result); - // Everything ok as teacher. - $this->assertCount(0, $result['warnings']); - $this->assertCount(0, $result['messages']); $this->setUser($this->student); - $result = mod_lesson_external::launch_attempt($this->lesson->id, '', 1, true); + $result = mod_lesson_external::launch_attempt($this->lesson->id, '', $this->page2->id, true); $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result); // Everything ok as student. $this->assertCount(0, $result['warnings']); From a33c0e30eb622b86d53af122f9b22ba9602d8e89 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 30 Mar 2017 16:23:39 +0200 Subject: [PATCH 4/8] MDL-58415 mod_lesson: Return always allowofflineattempts We need this field always to be able to display if the lesson is available or not for download --- mod/lesson/classes/external.php | 2 +- mod/lesson/classes/external/lesson_summary_exporter.php | 1 - mod/lesson/tests/external_test.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index 98afaa08c5c..cca45a4f14e 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -65,7 +65,7 @@ class mod_lesson_external extends external_api { 'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback', 'minquestions', 'maxpages', 'timelimit', 'retake', 'mediafile', 'mediaheight', 'mediawidth', 'mediaclose', 'slideshow', 'width', 'height', 'bgcolor', 'displayleft', 'displayleftif', - 'progressbar', 'allowofflineattempts'); + 'progressbar'); foreach ($fields as $field) { unset($lessonrecord->{$field}); diff --git a/mod/lesson/classes/external/lesson_summary_exporter.php b/mod/lesson/classes/external/lesson_summary_exporter.php index 0e9a9cb6e3f..fb262be14db 100644 --- a/mod/lesson/classes/external/lesson_summary_exporter.php +++ b/mod/lesson/classes/external/lesson_summary_exporter.php @@ -249,7 +249,6 @@ class lesson_summary_exporter extends exporter { 'allowofflineattempts' => array( 'type' => PARAM_BOOL, 'description' => 'Whether to allow the lesson to be attempted offline in the mobile app', - 'optional' => true, ), ); } diff --git a/mod/lesson/tests/external_test.php b/mod/lesson/tests/external_test.php index 56fc8522f24..f747614b212 100644 --- a/mod/lesson/tests/external_test.php +++ b/mod/lesson/tests/external_test.php @@ -1304,7 +1304,7 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase { // Lesson not using password. $result = mod_lesson_external::get_lesson($this->lesson->id); $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result); - $this->assertCount(5, $result['lesson']); // Expect just this few fields. + $this->assertCount(6, $result['lesson']); // Expect just this few fields. $this->assertFalse(isset($result['intro'])); } From f1cdd978aa23c3c268cf56a0b90c89777c401d2b Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 6 Apr 2017 10:57:52 +0200 Subject: [PATCH 5/8] MDL-58415 mod_lesson: Out of time should be a string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process_eol_page expects a string, right now we are passing a boolean. We should convert it to the correct string when is set to true, that is ‘normal’ --- mod/lesson/classes/external.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index cca45a4f14e..93f756a2ac3 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -1584,7 +1584,9 @@ class mod_lesson_external extends external_api { throw new moodle_exception(key($validation), 'lesson', '', current($validation)); // Throw first error. } - $result = $lesson->process_eol_page($params['outoftime']); + // Set out of time to normal (it is the only existing mode). + $outoftimemode = $params['outoftime'] ? 'normal' : ''; + $result = $lesson->process_eol_page($outoftimemode); // Return the data. $validmessages = array( From dd60892155fecc48753950c81f574857ae2796f4 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 18 Apr 2017 10:28:38 +0200 Subject: [PATCH 6/8] MDL-58415 mod_lesson: EOL var must be always numeric Otherwise it will break the Web Service return description. --- mod/lesson/locallib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 4e9fe4969e1..ba079b6be14 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -752,7 +752,7 @@ function lesson_get_overview_report_table_and_data(lesson $lesson, $currentgroup $timestart = 0; $timeend = 0; $usergrade = null; - $eol = false; + $eol = 0; // search for the grade record for this try. if not there, the nulls defined above will be used. foreach($grades as $grade) { @@ -805,7 +805,7 @@ function lesson_get_overview_report_table_and_data(lesson $lesson, $currentgroup $timestart = 0; $timeend = 0; $usergrade = null; - $eol = false; + $eol = 0; // Search for the time record for this try. if not there, the nulls defined above will be used. foreach ($times as $time) { // Check to see if the grade matches the correct user. From 9c543014a26aade0c29177ac1790365d3acd0f95 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 18 Apr 2017 10:33:39 +0200 Subject: [PATCH 7/8] MDL-58415 mod_lesson: Add missing answer fields There were a couple of fields missing when returning the complete answer information required for offline usage. --- mod/lesson/classes/external.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index 93f756a2ac3..45ea378ace2 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -1308,6 +1308,11 @@ class mod_lesson_external extends external_api { foreach ($extraproperties as $prop) { $answer[$prop] = $a->{$prop}; } + + list($answer['answer'], $answer['answerformat']) = + external_format_text($a->answer, $a->answerformat, $context->id, 'mod_lesson', 'page_answers', $a->id); + list($answer['response'], $answer['responseformat']) = + external_format_text($a->response, $a->responseformat, $context->id, 'mod_lesson', 'page_responses', $a->id); } $answers[] = $answer; } @@ -1375,6 +1380,10 @@ class mod_lesson_external extends external_api { 'flags' => new external_value(PARAM_INT, 'Used to store options for the answer', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'A timestamp of when the answer was created', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'A timestamp of when the answer was modified', VALUE_OPTIONAL), + 'answer' => new external_value(PARAM_RAW, 'Possible answer text', VALUE_OPTIONAL), + 'answerformat' => new external_format_value('answer', VALUE_OPTIONAL), + 'response' => new external_value(PARAM_RAW, 'Response text for the answer', VALUE_OPTIONAL), + 'responseformat' => new external_format_value('response', VALUE_OPTIONAL), ), 'The page answers' ) From d96d72955eab92546d27024cd3dc20e65b5f1495 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 19 Apr 2017 09:49:59 +0200 Subject: [PATCH 8/8] MDL-58415 mod_lesson: Fix code styles and missing declaration Found by the integrator review: - Some incorrect code style declaration and phpdocs - Missing $USER declaration - Incorrect use of $lesson (should be $this) --- mod/lesson/classes/external.php | 48 ++++++++++++++++----------------- mod/lesson/locallib.php | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index 45ea378ace2..a3abccdc7e4 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -328,7 +328,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_lesson_access_information. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_lesson_access_information_parameters() { @@ -424,7 +424,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for view_lesson. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function view_lesson_parameters() { @@ -440,7 +440,7 @@ class mod_lesson_external extends external_api { * Trigger the course module viewed event and update the module completion status. * * @param int $lessonid lesson instance id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @return array of warnings and status result * @since Moodle 3.3 * @throws moodle_exception @@ -501,7 +501,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_questions_attempts. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_questions_attempts_parameters() { @@ -592,7 +592,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_user_grade. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_user_grade_parameters() { @@ -700,7 +700,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_user_attempt_grade. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_user_attempt_grade_parameters() { @@ -771,7 +771,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_content_pages_viewed. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_content_pages_viewed_parameters() { @@ -857,7 +857,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_user_timers. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_user_timers_parameters() { @@ -1003,7 +1003,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_pages. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_pages_parameters() { @@ -1019,7 +1019,7 @@ class mod_lesson_external extends external_api { * Return the list of pages in a lesson (based on the user permissions). * * @param int $lessonid lesson instance id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @return array of warnings and status result * @since Moodle 3.3 * @throws moodle_exception @@ -1106,7 +1106,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for launch_attempt. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function launch_attempt_parameters() { @@ -1160,7 +1160,7 @@ class mod_lesson_external extends external_api { * Starts a new attempt or continues an existing one. * * @param int $lessonid lesson instance id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @param int $pageid page id to continue from (only when continuing an attempt) * @param bool $review if we want to review just after finishing * @return array of warnings and status result @@ -1229,7 +1229,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_page_data. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_page_data_parameters() { @@ -1251,7 +1251,7 @@ class mod_lesson_external extends external_api { * * @param int $lessonid lesson instance id * @param int $pageid page id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @param bool $review if we want to review just after finishing (1 hour margin) * @param bool $returncontents if we must return the complete page contents once rendered * @return array of warnings and status result @@ -1259,7 +1259,7 @@ class mod_lesson_external extends external_api { * @throws moodle_exception */ public static function get_page_data($lessonid, $pageid, $password = '', $review = false, $returncontents = false) { - global $PAGE; + global $PAGE, $USER; $params = array('lessonid' => $lessonid, 'password' => $password, 'pageid' => $pageid, 'review' => $review, 'returncontents' => $returncontents); @@ -1398,7 +1398,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for process_page. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function process_page_parameters() { @@ -1427,7 +1427,7 @@ class mod_lesson_external extends external_api { * @param int $lessonid lesson instance id * @param int $pageid page id * @param array $data the data to be saved - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @param bool $review if we want to review just after finishing (1 hour margin) * @return array of warnings and status result * @since Moodle 3.3 @@ -1540,7 +1540,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for finish_attempt. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function finish_attempt_parameters() { @@ -1559,7 +1559,7 @@ class mod_lesson_external extends external_api { * Finishes the current attempt. * * @param int $lessonid lesson instance id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @param bool $outoftime optional if the user run out of time * @param bool $review if we want to review just after finishing (1 hour margin) * @return array of warnings and information about the finished attempt @@ -1655,7 +1655,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_attempts_overview. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_attempts_overview_parameters() { @@ -1766,7 +1766,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_user_attempt. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_user_attempt_parameters() { @@ -1869,7 +1869,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_pages_possible_jumps. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_pages_possible_jumps_parameters() { @@ -1964,7 +1964,7 @@ class mod_lesson_external extends external_api { /** * Describes the parameters for get_lesson. * - * @return external_external_function_parameters + * @return external_function_parameters * @since Moodle 3.3 */ public static function get_lesson_parameters() { @@ -1980,7 +1980,7 @@ class mod_lesson_external extends external_api { * Return information of a given lesson. * * @param int $lessonid lesson instance id - * @param str $password optional password (the lesson may be protected) + * @param string $password optional password (the lesson may be protected) * @return array of warnings and status result * @since Moodle 3.3 * @throws moodle_exception diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index ba079b6be14..c2c64eaa050 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3305,7 +3305,7 @@ class lesson extends lesson_base { } // Inform teacher that s/he will not see the timer. if ($this->properties->timelimit) { - $lesson->add_message(get_string("teachertimerwarning", "lesson")); + $this->add_message(get_string("teachertimerwarning", "lesson")); } } // Report attempts remaining.