Skip to content

Commit

Permalink
Merge branch 'MDL-29296_m20' of git://github.com/rwijaya/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_20_STABLE
  • Loading branch information
Sam Hemelryk committed Oct 3, 2011
2 parents e93dd0d + 5f32139 commit 77738c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
27 changes: 11 additions & 16 deletions mod/lesson/locallib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ public function get_lastpageid() {
} }


/** /**
* Gets the next page to display after the one that is provided. * Gets the next page id to display after the one that is provided.
* @param int $nextpageid * @param int $nextpageid
* @return bool * @return bool
*/ */
Expand All @@ -1126,19 +1126,19 @@ public function get_next_page($nextpageid) {
$allpages = $this->load_all_pages(); $allpages = $this->load_all_pages();
if ($this->properties->nextpagedefault) { if ($this->properties->nextpagedefault) {
// in Flash Card mode...first get number of retakes // in Flash Card mode...first get number of retakes
$nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$this->properties->id, "userid"=>$USER->id)); $nretakes = $DB->count_records("lesson_grades", array("lessonid" => $this->properties->id, "userid" => $USER->id));
shuffle($allpages); shuffle($allpages);
$found = false; $found = false;
if ($this->properties->nextpagedefault == LESSON_UNSEENPAGE) { if ($this->properties->nextpagedefault == LESSON_UNSEENPAGE) {
foreach ($allpages as $nextpage) { foreach ($allpages as $nextpage) {
if (!$DB->count_records("lesson_attempts", array("pageid"=>$nextpage->id, "userid"=>$USER->id, "retry"=>$nretakes))) { if (!$DB->count_records("lesson_attempts", array("pageid" => $nextpage->id, "userid" => $USER->id, "retry" => $nretakes))) {
$found = true; $found = true;
break; break;
} }
} }
} elseif ($this->properties->nextpagedefault == LESSON_UNANSWEREDPAGE) { } elseif ($this->properties->nextpagedefault == LESSON_UNANSWEREDPAGE) {
foreach ($allpages as $nextpage) { foreach ($allpages as $nextpage) {
if (!$DB->count_records("lesson_attempts", array('pageid'=>$nextpage->id, 'userid'=>$USER->id, 'correct'=>1, 'retry'=>$nretakes))) { if (!$DB->count_records("lesson_attempts", array('pageid' => $nextpage->id, 'userid' => $USER->id, 'correct' => 1, 'retry' => $nretakes))) {
$found = true; $found = true;
break; break;
} }
Expand All @@ -1147,20 +1147,20 @@ public function get_next_page($nextpageid) {
if ($found) { if ($found) {
if ($this->properties->maxpages) { if ($this->properties->maxpages) {
// check number of pages viewed (in the lesson) // check number of pages viewed (in the lesson)
if ($DB->count_records("lesson_attempts", array("lessonid"=>$this->properties->id, "userid"=>$USER->id, "retry"=>$nretakes)) >= $this->properties->maxpages) { if ($DB->count_records("lesson_attempts", array("lessonid" => $this->properties->id, "userid" => $USER->id, "retry" => $nretakes)) >= $this->properties->maxpages) {
return false; return LESSON_EOL;
} }
} }
return $nextpage; return $nextpage->id;
} }
} }
// In a normal lesson mode // In a normal lesson mode
foreach ($allpages as $nextpage) { foreach ($allpages as $nextpage) {
if ((int)$nextpage->id===(int)$nextpageid) { if ((int)$nextpage->id === (int)$nextpageid) {
return $nextpage; return $nextpage->id;
} }
} }
return false; return LESSON_EOL;
} }


/** /**
Expand Down Expand Up @@ -1985,12 +1985,7 @@ final public function record_attempt($context) {
if ($result->newpageid == 0) { if ($result->newpageid == 0) {
$result->newpageid = $this->properties->id; $result->newpageid = $this->properties->id;
} elseif ($result->newpageid == LESSON_NEXTPAGE) { } elseif ($result->newpageid == LESSON_NEXTPAGE) {
$nextpage = $this->lesson->get_next_page($this->properties->nextpageid); $result->newpageid = $this->lesson->get_next_page($this->properties->nextpageid);
if ($nextpage === false) {
$result->newpageid = LESSON_EOL;
} else {
$result->newpageid = $nextpage->id;
}
} }


// Determine default feedback if necessary // Determine default feedback if necessary
Expand Down
5 changes: 1 addition & 4 deletions mod/lesson/view.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@
$data = new stdClass; $data = new stdClass;
$data->id = $PAGE->cm->id; $data->id = $PAGE->cm->id;
$data->pageid = $page->id; $data->pageid = $page->id;
$data->newpageid = LESSON_NEXTPAGE; $data->newpageid = $lesson->get_next_page($page->nextpageid);
if ($nextpage = $lesson->get_next_page($page->nextpageid)) {
$data->newpageid = $nextpage->id;
}


$customdata = array( $customdata = array(
'title' => $page->title, 'title' => $page->title,
Expand Down

0 comments on commit 77738c4

Please sign in to comment.