Skip to content

Commit

Permalink
Merge branch 'MDL-58415-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Apr 20, 2017
2 parents 10e5071 + d96d729 commit c1e9178
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 104 deletions.
165 changes: 94 additions & 71 deletions mod/lesson/classes/external.php

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion mod/lesson/classes/external/lesson_summary_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ protected static function define_properties() {
'allowofflineattempts' => array(
'type' => PARAM_BOOL,
'description' => 'Whether to allow the lesson to be attempted offline in the mobile app',
'optional' => true,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions mod/lesson/lang/en/lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@
$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';
Expand Down
27 changes: 18 additions & 9 deletions mod/lesson/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -3107,7 +3107,8 @@ public function calculate_progress() {
}

// Progress calculation as a percent.
return round(count($viewedpageids) / count($validpages), 2) * 100;
$progress = round(count($viewedpageids) / count($validpages), 2) * 100;
return (int) $progress;
}

/**
Expand All @@ -3116,16 +3117,23 @@ public function calculate_progress() {
* @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);
}
Expand Down Expand Up @@ -3166,7 +3174,7 @@ public function prepare_page_and_contents($pageid, $lessonoutput, $reviewmode) {
ob_end_clean();
}

return array($page, $lessoncontent);
return array($page->id, $page, $lessoncontent);
}

/**
Expand Down Expand Up @@ -3297,7 +3305,7 @@ public function add_messages_on_page_process(lesson_page $page, $result, $review
}
// 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.
Expand Down Expand Up @@ -3488,7 +3496,7 @@ public function process_eol_page($outoftime) {

$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;
}
Expand Down Expand Up @@ -4154,9 +4162,10 @@ public function earned_score($answers, $attempt) {
* 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;
}

Expand Down
6 changes: 3 additions & 3 deletions mod/lesson/pagetypes/cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function get_idstring() {
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() {
Expand Down
14 changes: 9 additions & 5 deletions mod/lesson/pagetypes/endofbranch.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ public function get_typestring() {
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);
Expand Down Expand Up @@ -94,7 +93,12 @@ public function redirect_to_first_answer($canmanage) {
$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;
Expand Down
13 changes: 8 additions & 5 deletions mod/lesson/pagetypes/endofcluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ public function get_typestring() {
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;
Expand Down
12 changes: 3 additions & 9 deletions mod/lesson/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public function test_launch_attempt_just_finished_in_review_mode() {
'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(),
Expand All @@ -857,15 +857,9 @@ public function test_launch_attempt_just_finished_in_review_mode() {
$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']);
Expand Down Expand Up @@ -1310,7 +1304,7 @@ public function test_get_lesson_user_student_with_missing_password() {
// 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']));
}

Expand Down
5 changes: 5 additions & 0 deletions mod/lesson/upgrade.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
}
}

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;
Expand Down

0 comments on commit c1e9178

Please sign in to comment.