|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once(dirname(__FILE__) . '/../../config.php'); 00028 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 00029 require_once($CFG->dirroot.'/mod/lesson/view_form.php'); 00030 require_once($CFG->libdir . '/completionlib.php'); 00031 00032 $id = required_param('id', PARAM_INT); // Course Module ID 00033 $pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID 00034 $edit = optional_param('edit', -1, PARAM_BOOL); 00035 $userpassword = optional_param('userpassword','',PARAM_RAW); 00036 $backtocourse = optional_param('backtocourse', false, PARAM_RAW); 00037 00038 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);; 00039 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00040 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); 00041 00042 require_login($course, false, $cm); 00043 00044 if ($backtocourse) { 00045 redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); 00046 } 00047 00048 // Mark as viewed 00049 $completion = new completion_info($course); 00050 $completion->set_module_viewed($cm); 00051 00052 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$id)); 00053 if ($pageid !== null) { 00054 $url->param('pageid', $pageid); 00055 } 00056 $PAGE->set_url($url); 00057 00058 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00059 $canmanage = has_capability('mod/lesson:manage', $context); 00060 00061 $lessonoutput = $PAGE->get_renderer('mod_lesson'); 00062 00063 $reviewmode = false; 00064 $userhasgrade = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00065 if ($userhasgrade && !$lesson->retake) { 00066 $reviewmode = true; 00067 } 00068 00074 if (!$canmanage) { 00075 if (!$lesson->is_accessible()) { // Deadline restrictions 00076 echo $lessonoutput->header($lesson, $cm); 00077 if ($lesson->deadline != 0 && time() > $lesson->deadline) { 00078 echo $lessonoutput->lesson_inaccessible(get_string('lessonclosed', 'lesson', userdate($lesson->deadline))); 00079 } else { 00080 echo $lessonoutput->lesson_inaccessible(get_string('lessonopen', 'lesson', userdate($lesson->available))); 00081 } 00082 echo $lessonoutput->footer(); 00083 exit(); 00084 } else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code 00085 $correctpass = false; 00086 if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) { 00087 // with or without md5 for backward compatibility (MDL-11090) 00088 $USER->lessonloggedin[$lesson->id] = true; 00089 if ($lesson->highscores) { 00090 // Logged in - redirect so we go through all of these checks before starting the lesson. 00091 redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id"); 00092 } 00093 } else { 00094 echo $lessonoutput->header($lesson, $cm); 00095 echo $lessonoutput->login_prompt($lesson, $userpassword !== ''); 00096 echo $lessonoutput->footer(); 00097 exit(); 00098 } 00099 } else if ($lesson->dependency) { // check for dependencies 00100 if ($dependentlesson = $DB->get_record('lesson', array('id' => $lesson->dependency))) { 00101 // lesson exists, so we can proceed 00102 $conditions = unserialize($lesson->conditions); 00103 // assume false for all 00104 $errors = array(); 00105 00106 // check for the timespent condition 00107 if ($conditions->timespent) { 00108 $timespent = false; 00109 if ($attempttimes = $DB->get_records('lesson_timer', array("userid"=>$USER->id, "lessonid"=>$dependentlesson->id))) { 00110 // go through all the times and test to see if any of them satisfy the condition 00111 foreach($attempttimes as $attempttime) { 00112 $duration = $attempttime->lessontime - $attempttime->starttime; 00113 if ($conditions->timespent < $duration/60) { 00114 $timespent = true; 00115 } 00116 } 00117 } 00118 if (!$timespent) { 00119 $errors[] = get_string('timespenterror', 'lesson', $conditions->timespent); 00120 } 00121 } 00122 00123 // check for the gradebetterthan condition 00124 if($conditions->gradebetterthan) { 00125 $gradebetterthan = false; 00126 if ($studentgrades = $DB->get_records('lesson_grades', array("userid"=>$USER->id, "lessonid"=>$dependentlesson->id))) { 00127 // go through all the grades and test to see if any of them satisfy the condition 00128 foreach($studentgrades as $studentgrade) { 00129 if ($studentgrade->grade >= $conditions->gradebetterthan) { 00130 $gradebetterthan = true; 00131 } 00132 } 00133 } 00134 if (!$gradebetterthan) { 00135 $errors[] = get_string('gradebetterthanerror', 'lesson', $conditions->gradebetterthan); 00136 } 00137 } 00138 00139 // check for the completed condition 00140 if ($conditions->completed) { 00141 if (!$DB->count_records('lesson_grades', array('userid'=>$USER->id, 'lessonid'=>$dependentlesson->id))) { 00142 $errors[] = get_string('completederror', 'lesson'); 00143 } 00144 } 00145 00146 if (!empty($errors)) { // print out the errors if any 00147 echo $lessonoutput->header($lesson, $cm); 00148 echo $lessonoutput->dependancy_errors($dependentlesson, $errors); 00149 echo $lessonoutput->footer(); 00150 exit(); 00151 } 00152 } 00153 } else if ($lesson->highscores && !$lesson->practice && !optional_param('viewed', 0, PARAM_INT) && empty($pageid)) { 00154 // Display high scores before starting lesson 00155 redirect(new moodle_url('/mod/lesson/highscores.php', array("id"=>$cm->id))); 00156 } 00157 } 00158 00159 // this is called if a student leaves during a lesson 00160 if ($pageid == LESSON_UNSEENBRANCHPAGE) { 00161 $pageid = lesson_unseen_question_jump($lesson, $USER->id, $pageid); 00162 } 00163 00164 // display individual pages and their sets of answers 00165 // if pageid is EOL then the end of the lesson has been reached 00166 // for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down 00167 $attemptflag = false; 00168 if (empty($pageid)) { 00169 // make sure there are pages to view 00170 if (!$DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { 00171 if (!$canmanage) { 00172 $lesson->add_message(get_string('lessonnotready2', 'lesson')); // a nice message to the student 00173 } else { 00174 if (!$DB->count_records('lesson_pages', array('lessonid'=>$lesson->id))) { 00175 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); // no pages - redirect to add pages 00176 } else { 00177 $lesson->add_message(get_string('lessonpagelinkingbroken', 'lesson')); // ok, bad mojo 00178 } 00179 } 00180 } 00181 00182 add_to_log($course->id, 'lesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id); 00183 00184 // if no pageid given see if the lesson has been started 00185 $retries = $DB->count_records('lesson_grades', array("lessonid" => $lesson->id, "userid" => $USER->id)); 00186 if ($retries > 0) { 00187 $attemptflag = true; 00188 } 00189 00190 if (isset($USER->modattempts[$lesson->id])) { 00191 unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing 00192 } 00193 00194 // if there are any questions have been answered correctly in this attempt 00195 $corrrectattempts = $lesson->get_attempts($retries, true); 00196 if ($corrrectattempts>0) { 00197 foreach ($corrrectattempts as $attempt) { 00198 $jumpto = $DB->get_field('lesson_answers', 'jumpto', array('id' => $attempt->answerid)); 00199 // convert the jumpto to a proper page id 00200 if ($jumpto == 0) { // unlikely value! 00201 $lastpageseen = $attempt->pageid; 00202 } elseif ($jumpto == LESSON_NEXTPAGE) { 00203 if (!$lastpageseen = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $attempt->pageid))) { 00204 // no nextpage go to end of lesson 00205 $lastpageseen = LESSON_EOL; 00206 } 00207 } else { 00208 $lastpageseen = $jumpto; 00209 } 00210 break; // only look at the latest correct attempt 00211 } 00212 } 00213 00214 if ($branchtables = $DB->get_records('lesson_branch', array("lessonid"=>$lesson->id, "userid"=>$USER->id, "retry"=>$retries), 'timeseen DESC')) { 00215 // in here, user has viewed a branch table 00216 $lastbranchtable = current($branchtables); 00217 if (count($corrrectattempts)>0) { 00218 foreach($corrrectattempts as $attempt) { 00219 if ($lastbranchtable->timeseen > $attempt->timeseen) { 00220 // branch table was viewed later than the last attempt 00221 $lastpageseen = $lastbranchtable->pageid; 00222 } 00223 break; 00224 } 00225 } else { 00226 // hasnt answered any questions but has viewed a branch table 00227 $lastpageseen = $lastbranchtable->pageid; 00228 } 00229 } 00230 if (isset($lastpageseen) && $DB->count_records('lesson_attempts', array('lessonid'=>$lesson->id, 'userid'=>$USER->id, 'retry'=>$retries)) > 0) { 00231 echo $lessonoutput->header($lesson, $cm); 00232 if ($lesson->timed) { 00233 if ($lesson->retake) { 00234 $continuelink = new single_button(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id, 'pageid'=>$lesson->firstpageid, 'startlastseen'=>'no')), get_string('continue', 'lesson'), 'get'); 00235 echo '<div class="center leftduring">'.$lessonoutput->message(get_string('leftduringtimed', 'lesson'), $continuelink).'</div>'; 00236 } else { 00237 $courselink = new single_button(new moodle_url('/course/view.php', array('id'=>$PAGE->course->id)), get_string('returntocourse', 'lesson'), 'get'); 00238 echo '<div class="center leftduring">'.$lessonoutput->message(get_string('leftduringtimednoretake', 'lesson'), $courselink).'</div>'; 00239 } 00240 } else { 00241 echo $lessonoutput->continue_links($lesson, $lastpageseen); 00242 } 00243 echo $lessonoutput->footer(); 00244 exit(); 00245 } 00246 00247 if ($attemptflag) { 00248 if (!$lesson->retake) { 00249 echo $lessonoutput->header($lesson, $cm, 'view'); 00250 $courselink = new single_button(new moodle_url('/course/view.php', array('id'=>$PAGE->course->id)), get_string('returntocourse', 'lesson'), 'get'); 00251 echo $lessonoutput->message(get_string("noretake", "lesson"), $courselink); 00252 echo $lessonoutput->footer(); 00253 exit(); 00254 } 00255 } 00256 // start at the first page 00257 if (!$pageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { 00258 print_error('cannotfindfirstpage', 'lesson'); 00259 } 00261 if(!isset($USER->startlesson[$lesson->id]) && !$canmanage) { 00262 $lesson->start_timer(); 00263 } 00264 } 00265 00266 $currenttab = 'view'; 00267 $extraeditbuttons = false; 00268 $lessonpageid = null; 00269 $timer = null; 00270 00271 if ($pageid != LESSON_EOL) { 00273 $startlastseen = optional_param('startlastseen', '', PARAM_ALPHA); 00274 if ($startlastseen == 'no') { 00275 // this deletes old records not totally sure if this is necessary anymore 00276 $retries = $DB->count_records('lesson_grades', array('lessonid'=>$lesson->id, 'userid'=>$USER->id)); 00277 $DB->delete_records('lesson_attempts', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries)); 00278 $DB->delete_records('lesson_branch', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries)); 00279 } 00280 00281 $page = $lesson->load_page($pageid); 00282 // Check if the page is of a special type and if so take any nessecary action 00283 $newpageid = $page->callback_on_view($canmanage); 00284 if (is_numeric($newpageid)) { 00285 $page = $lesson->load_page($newpageid); 00286 } 00287 00288 add_to_log($PAGE->course->id, 'lesson', 'view', 'view.php?id='. $PAGE->cm->id, $page->id, $PAGE->cm->id); 00289 00290 // This is where several messages (usually warnings) are displayed 00291 // all of this is displayed above the actual page 00292 00293 // check to see if the user can see the left menu 00294 if (!$canmanage) { 00295 $lesson->displayleft = lesson_displayleftif($lesson); 00296 00297 $continue = ($startlastseen !== ''); 00298 $restart = ($continue && $startlastseen == 'yes'); 00299 $timer = $lesson->update_timer($continue, $restart); 00300 00301 if ($lesson->timed) { 00302 $timeleft = ($timer->starttime + $lesson->maxtime * 60) - time(); 00303 if ($timeleft <= 0) { 00304 // Out of time 00305 $lesson->add_message(get_string('eolstudentoutoftime', 'lesson')); 00306 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$cm->id,'pageid'=>LESSON_EOL, 'outoftime'=>'normal'))); 00307 die; // Shouldn't be reached, but make sure 00308 } else if ($timeleft < 60) { 00309 // One minute warning 00310 $lesson->add_message(get_string('studentoneminwarning', 'lesson')); 00311 } 00312 } 00313 00314 if ($page->qtype == LESSON_PAGE_BRANCHTABLE && $lesson->minquestions) { 00315 // tell student how many questions they have seen, how many are required and their grade 00316 $ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00317 $gradeinfo = lesson_grade($lesson, $ntries); 00318 if ($gradeinfo->attempts) { 00319 if ($gradeinfo->nquestions < $lesson->minquestions) { 00320 $a = new stdClass; 00321 $a->nquestions = $gradeinfo->nquestions; 00322 $a->minquestions = $lesson->minquestions; 00323 $lesson->add_message(get_string('numberofpagesviewednotice', 'lesson', $a)); 00324 } 00325 00326 $a = new stdClass; 00327 $a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1); 00328 $a->total = $lesson->grade; 00329 if (!$reviewmode && !$lesson->retake){ 00330 $lesson->add_message(get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned), 'notify'); 00331 $lesson->add_message(get_string('yourcurrentgradeisoutof', 'lesson', $a), 'notify'); 00332 } 00333 } 00334 } 00335 } else { 00336 $timer = null; 00337 if ($lesson->timed) { 00338 $lesson->add_message(get_string('teachertimerwarning', 'lesson')); 00339 } 00340 if (lesson_display_teacher_warning($lesson)) { 00341 // This is the warning msg for teachers to inform them that cluster 00342 // and unseen does not work while logged in as a teacher 00343 $warningvars->cluster = get_string('clusterjump', 'lesson'); 00344 $warningvars->unseen = get_string('unseenpageinbranch', 'lesson'); 00345 $lesson->add_message(get_string('teacherjumpwarning', 'lesson', $warningvars)); 00346 } 00347 } 00348 00349 $PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); 00350 $PAGE->set_subpage($page->id); 00351 $currenttab = 'view'; 00352 $extraeditbuttons = true; 00353 $lessonpageid = $page->id; 00354 00355 if (($edit != -1) && $PAGE->user_allowed_editing()) { 00356 $USER->editing = $edit; 00357 } 00358 00359 if (is_array($page->answers) && count($page->answers)>0) { 00360 // this is for modattempts option. Find the users previous answer to this page, 00361 // and then display it below in answer processing 00362 if (isset($USER->modattempts[$lesson->id])) { 00363 $retries = $DB->count_records('lesson_grades', array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00364 if (!$attempts = $lesson->get_attempts($retries-1, false, $page->id)) { 00365 print_error('cannotfindpreattempt', 'lesson'); 00366 } 00367 $attempt = end($attempts); 00368 $USER->modattempts[$lesson->id] = $attempt; 00369 } else { 00370 $attempt = false; 00371 } 00372 $lessoncontent = $lessonoutput->display_page($lesson, $page, $attempt); 00373 } else { 00374 $data = new stdClass; 00375 $data->id = $PAGE->cm->id; 00376 $data->pageid = $page->id; 00377 $data->newpageid = $lesson->get_next_page($page->nextpageid); 00378 00379 $customdata = array( 00380 'title' => $page->title, 00381 'contents' => $page->get_contents() 00382 ); 00383 $mform = new lesson_page_without_answers($CFG->wwwroot.'/mod/lesson/continue.php', $customdata); 00384 $mform->set_data($data); 00385 ob_start(); 00386 $mform->display(); 00387 $lessoncontent = ob_get_contents(); 00388 ob_end_clean(); 00389 } 00390 00391 lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer); 00392 echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid); 00393 if ($attemptflag) { 00394 // We are using level 3 header because attempt heading is a sub-heading of lesson title (MDL-30911). 00395 echo $OUTPUT->heading(get_string('attempt', 'lesson', $retries), 3); 00396 } 00398 if ($lesson->ongoing && !empty($pageid) && !$reviewmode) { 00399 echo $lessonoutput->ongoing_score($lesson); 00400 } 00401 if ($lesson->displayleft) { 00402 echo '<a name="maincontent" id="maincontent" title="' . get_string('anchortitle', 'lesson') . '"></a>'; 00403 } 00404 echo $lessoncontent; 00405 echo $lessonoutput->slideshow_end(); 00406 echo $lessonoutput->progress_bar($lesson); 00407 echo $lessonoutput->footer(); 00408 00409 } else { 00410 00411 $lessoncontent = ''; 00412 // end of lesson reached work out grade 00413 // Used to check to see if the student ran out of time 00414 $outoftime = optional_param('outoftime', '', PARAM_ALPHA); 00415 00416 // Update the clock / get time information for this user 00417 add_to_log($course->id, "lesson", "end", "view.php?id=".$PAGE->cm->id, "$lesson->id", $PAGE->cm->id); 00418 00419 // We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911). 00420 $lessoncontent .= $OUTPUT->heading(get_string("congratulations", "lesson"), 3); 00421 $lessoncontent .= $OUTPUT->box_start('generalbox boxaligncenter'); 00422 $ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); 00423 if (isset($USER->modattempts[$lesson->id])) { 00424 $ntries--; // need to look at the old attempts :) 00425 } 00426 if (!$canmanage) { 00427 $lesson->stop_timer(); 00428 $gradeinfo = lesson_grade($lesson, $ntries); 00429 00430 if ($gradeinfo->attempts) { 00431 if (!$lesson->custom) { 00432 $lessoncontent .= $lessonoutput->paragraph(get_string("numberofpagesviewed", "lesson", $gradeinfo->nquestions), 'center'); 00433 if ($lesson->minquestions) { 00434 if ($gradeinfo->nquestions < $lesson->minquestions) { 00435 // print a warning and set nviewed to minquestions 00436 $lessoncontent .= $lessonoutput->paragraph(get_string("youshouldview", "lesson", $lesson->minquestions), 'center'); 00437 } 00438 } 00439 $lessoncontent .= $lessonoutput->paragraph(get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned), 'center'); 00440 } 00441 $a = new stdClass; 00442 $a->score = $gradeinfo->earned; 00443 $a->grade = $gradeinfo->total; 00444 if ($gradeinfo->nmanual) { 00445 $a->tempmaxgrade = $gradeinfo->total - $gradeinfo->manualpoints; 00446 $a->essayquestions = $gradeinfo->nmanual; 00447 $lessoncontent .= $OUTPUT->box(get_string("displayscorewithessays", "lesson", $a), 'center'); 00448 } else { 00449 $lessoncontent .= $OUTPUT->box(get_string("displayscorewithoutessays", "lesson", $a), 'center'); 00450 } 00451 $a = new stdClass; 00452 $a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1); 00453 $a->total = $lesson->grade; 00454 $lessoncontent .= $lessonoutput->paragraph(get_string("yourcurrentgradeisoutof", "lesson", $a), 'center'); 00455 00456 $grade = new stdClass(); 00457 $grade->lessonid = $lesson->id; 00458 $grade->userid = $USER->id; 00459 $grade->grade = $gradeinfo->grade; 00460 $grade->completed = time(); 00461 if (!$lesson->practice) { 00462 if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record 00463 if (!$grades = $DB->get_records("lesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id), "completed DESC", '*', 0, 1)) { 00464 print_error('cannotfindgrade', 'lesson'); 00465 } 00466 $oldgrade = array_shift($grades); 00467 $grade->id = $oldgrade->id; 00468 $DB->update_record("lesson_grades", $grade); 00469 } else { 00470 $newgradeid = $DB->insert_record("lesson_grades", $grade); 00471 } 00472 } else { 00473 $DB->delete_records("lesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries)); 00474 } 00475 } else { 00476 if ($lesson->timed) { 00477 if ($outoftime == 'normal') { 00478 $grade = new stdClass();; 00479 $grade->lessonid = $lesson->id; 00480 $grade->userid = $USER->id; 00481 $grade->grade = 0; 00482 $grade->completed = time(); 00483 if (!$lesson->practice) { 00484 $newgradeid = $DB->insert_record("lesson_grades", $grade); 00485 } 00486 $lessoncontent .= get_string("eolstudentoutoftimenoanswers", "lesson"); 00487 } 00488 } else { 00489 $lessoncontent .= get_string("welldone", "lesson"); 00490 } 00491 } 00492 00493 // update central gradebook 00494 lesson_update_grades($lesson, $USER->id); 00495 00496 } else { 00497 // display for teacher 00498 $lessoncontent .= $lessonoutput->paragraph(get_string("displayofgrade", "lesson"), 'center'); 00499 } 00500 $lessoncontent .= $OUTPUT->box_end(); //End of Lesson button to Continue. 00501 00502 // after all the grade processing, check to see if "Show Grades" is off for the course 00503 // if yes, redirect to the course page 00504 if (!$course->showgrades) { 00505 redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); 00506 } 00507 00508 // high scores code 00509 if ($lesson->highscores && !$canmanage && !$lesson->practice) { 00510 $lessoncontent .= $OUTPUT->box_start('center'); 00511 if ($grades = $DB->get_records("lesson_grades", array("lessonid" => $lesson->id), "completed")) { 00512 $madeit = false; 00513 if ($highscores = $DB->get_records("lesson_high_scores", array("lessonid" => $lesson->id))) { 00514 // get all the high scores into an array 00515 $topscores = array(); 00516 $uniquescores = array(); 00517 foreach ($highscores as $highscore) { 00518 $grade = $grades[$highscore->gradeid]->grade; 00519 $topscores[] = $grade; 00520 $uniquescores[$grade] = 1; 00521 } 00522 // sort to find the lowest score 00523 sort($topscores); 00524 $lowscore = $topscores[0]; 00525 00526 if ($gradeinfo->grade >= $lowscore || count($uniquescores) <= $lesson->maxhighscores) { 00527 $madeit = true; 00528 } 00529 } 00530 if (!$highscores or $madeit) { 00531 $lessoncontent .= $lessonoutput->paragraph(get_string("youmadehighscore", "lesson", $lesson->maxhighscores), 'center'); 00532 $aurl = new moodle_url('/mod/lesson/highscores.php', array('id'=>$PAGE->cm->id, 'sesskey'=>sesskey())); 00533 $lessoncontent .= $OUTPUT->single_button($aurl, get_string('clicktopost', 'lesson')); 00534 } else { 00535 $lessoncontent .= get_string("nothighscore", "lesson", $lesson->maxhighscores)."<br />"; 00536 } 00537 } 00538 $url = new moodle_url('/mod/lesson/highscores.php', array('id'=>$PAGE->cm->id, 'link'=>'1')); 00539 $lessoncontent .= html_writer::link($url, get_string('viewhighscores', 'lesson'), array('class'=>'centerpadded lessonbutton standardbutton')); 00540 $lessoncontent .= $OUTPUT->box_end(); 00541 } 00542 00543 if ($lesson->modattempts && !$canmanage) { 00544 // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time 00545 // look at the attempt records to find the first QUESTION page that the user answered, then use that page id 00546 // to pass to view again. This is slick cause it wont call the empty($pageid) code 00547 // $ntries is decremented above 00548 if (!$attempts = $lesson->get_attempts($ntries)) { 00549 $attempts = array(); 00550 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id)); 00551 } else { 00552 $firstattempt = current($attempts); 00553 $pageid = $firstattempt->pageid; 00554 // IF the student wishes to review, need to know the last question page that the student answered. This will help to make 00555 // sure that the student can leave the lesson via pushing the continue button. 00556 $lastattempt = end($attempts); 00557 $USER->modattempts[$lesson->id] = $lastattempt->pageid; 00558 00559 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id, 'pageid'=>$pageid)); 00560 } 00561 $lessoncontent .= html_writer::link($url, get_string('reviewlesson', 'lesson'), array('class' => 'centerpadded lessonbutton standardbutton')); 00562 } elseif ($lesson->modattempts && $canmanage) { 00563 $lessoncontent .= $lessonoutput->paragraph(get_string("modattemptsnoteacher", "lesson"), 'centerpadded'); 00564 } 00565 00566 if ($lesson->activitylink) { 00567 $lessoncontent .= $lesson->link_for_activitylink(); 00568 } 00569 00570 $url = new moodle_url('/course/view.php', array('id'=>$course->id)); 00571 $lessoncontent .= html_writer::link($url, get_string('returnto', 'lesson', format_string($course->fullname, true)), array('class'=>'centerpadded lessonbutton standardbutton')); 00572 00573 $url = new moodle_url('/grade/index.php', array('id'=>$course->id)); 00574 $lessoncontent .= html_writer::link($url, get_string('viewgrades', 'lesson'), array('class'=>'centerpadded lessonbutton standardbutton')); 00575 00576 lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer); 00577 echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid); 00578 echo $lessoncontent; 00579 echo $lessonoutput->footer(); 00580 }