-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
581 lines (524 loc) · 28.3 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page prints a particular instance of lesson
*
* @package mod
* @subpackage customlesson
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @copyright 2012-2013 Silecs et Institut Mines-Télécom
* @notice customlesson is heavily based on the official lesson module and large portions of code are copied from there.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
**/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/mod/customlesson/locallib.php');
require_once($CFG->dirroot.'/mod/customlesson/view_form.php');
require_once($CFG->libdir . '/completionlib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID
$edit = optional_param('edit', -1, PARAM_BOOL);
$userpassword = optional_param('userpassword','',PARAM_RAW);
$backtocourse = optional_param('backtocourse', false, PARAM_RAW);
$cm = get_coursemodule_from_id('customlesson', $id, 0, false, MUST_EXIST);;
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$lesson = new customlesson($DB->get_record('customlesson', array('id' => $cm->instance), '*', MUST_EXIST));
require_login($course, false, $cm);
if ($backtocourse) {
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
}
// Mark as viewed
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$url = new moodle_url('/mod/customlesson/view.php', array('id'=>$id));
if ($pageid !== null) {
$url->param('pageid', $pageid);
}
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
$canmanage = has_capability('mod/customlesson:manage', $context);
$lessonoutput = $PAGE->get_renderer('mod_customlesson');
$reviewmode = false;
$userhasgrade = $DB->count_records("customlesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if ($userhasgrade && !$lesson->retake) {
$reviewmode = true;
}
/// Check these for students only TODO: Find a better method for doing this!
/// Check lesson availability
/// Check for password
/// Check dependencies
/// Check for high scores
if (!$canmanage) {
if (!$lesson->is_accessible()) { // Deadline restrictions
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('notavailable'));
if ($lesson->deadline != 0 && time() > $lesson->deadline) {
echo $lessonoutput->customlesson_inaccessible(get_string('lessonclosed', 'customlesson', userdate($lesson->deadline)));
} else {
echo $lessonoutput->customlesson_inaccessible(get_string('lessonopen', 'customlesson', userdate($lesson->available)));
}
echo $lessonoutput->footer();
exit();
} else if ($lesson->usepassword && empty($USER->lessonloggedin[$lesson->id])) { // Password protected lesson code
$correctpass = false;
if (!empty($userpassword) && (($lesson->password == md5(trim($userpassword))) || ($lesson->password == trim($userpassword)))) {
// with or without md5 for backward compatibility (MDL-11090)
$USER->lessonloggedin[$lesson->id] = true;
if ($lesson->highscores) {
// Logged in - redirect so we go through all of these checks before starting the lesson.
redirect("$CFG->wwwroot/mod/customlesson/view.php?id=$cm->id");
}
} else {
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('passwordprotectedlesson', 'customlesson', format_string($lesson->name)));
echo $lessonoutput->login_prompt($lesson, $userpassword !== '');
echo $lessonoutput->footer();
exit();
}
} else if ($lesson->dependency) { // check for dependencies
if ($dependentlesson = $DB->get_record('customlesson', array('id' => $lesson->dependency))) {
// lesson exists, so we can proceed
$conditions = unserialize($lesson->conditions);
// assume false for all
$errors = array();
// check for the timespent condition
if ($conditions->timespent) {
$timespent = false;
if ($attempttimes = $DB->get_records('customlesson_timer', array("userid"=>$USER->id, "lessonid"=>$dependentlesson->id))) {
// go through all the times and test to see if any of them satisfy the condition
foreach($attempttimes as $attempttime) {
$duration = $attempttime->lessontime - $attempttime->starttime;
if ($conditions->timespent < $duration/60) {
$timespent = true;
}
}
}
if (!$timespent) {
$errors[] = get_string('timespenterror', 'customlesson', $conditions->timespent);
}
}
// check for the gradebetterthan condition
if($conditions->gradebetterthan) {
$gradebetterthan = false;
if ($studentgrades = $DB->get_records('customlesson_grades', array("userid"=>$USER->id, "lessonid"=>$dependentlesson->id))) {
// go through all the grades and test to see if any of them satisfy the condition
foreach($studentgrades as $studentgrade) {
if ($studentgrade->grade >= $conditions->gradebetterthan) {
$gradebetterthan = true;
}
}
}
if (!$gradebetterthan) {
$errors[] = get_string('gradebetterthanerror', 'customlesson', $conditions->gradebetterthan);
}
}
// check for the completed condition
if ($conditions->completed) {
if (!$DB->count_records('customlesson_grades', array('userid'=>$USER->id, 'lessonid'=>$dependentlesson->id))) {
$errors[] = get_string('completederror', 'customlesson');
}
}
if (!empty($errors)) { // print out the errors if any
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('completethefollowingconditions', 'customlesson', format_string($lesson->name)));
echo $lessonoutput->dependancy_errors($dependentlesson, $errors);
echo $lessonoutput->footer();
exit();
}
}
} else if ($lesson->highscores && !$lesson->practice && !optional_param('viewed', 0, PARAM_INT) && empty($pageid)) {
// Display high scores before starting lesson
redirect(new moodle_url('/mod/customlesson/highscores.php', array("id"=>$cm->id)));
}
}
// this is called if a student leaves during a lesson
if ($pageid == CUSTOMLESSON_UNSEENBRANCHPAGE) {
$pageid = customlesson_unseen_question_jump($lesson, $USER->id, $pageid);
}
// display individual pages and their sets of answers
// if pageid is EOL then the end of the lesson has been reached
// for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down
$attemptflag = false;
if (empty($pageid)) {
// make sure there are pages to view
if (!$DB->get_field('customlesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) {
if (!$canmanage) {
$lesson->add_message(get_string('lessonnotready2', 'customlesson')); // a nice message to the student
} else {
if (!$DB->count_records('customlesson_pages', array('lessonid'=>$lesson->id))) {
redirect("$CFG->wwwroot/mod/customlesson/edit.php?id=$cm->id"); // no pages - redirect to add pages
} else {
$lesson->add_message(get_string('lessonpagelinkingbroken', 'customlesson')); // ok, bad mojo
}
}
}
add_to_log($course->id, 'customlesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id);
// if no pageid given see if the lesson has been started
$retries = $DB->count_records('customlesson_grades', array("lessonid" => $lesson->id, "userid" => $USER->id));
if ($retries > 0) {
$attemptflag = true;
}
if (isset($USER->modattempts[$lesson->id])) {
unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing
}
// if there are any questions have been answered correctly in this attempt
$corrrectattempts = $lesson->get_attempts($retries, true);
if (!empty($corrrectattempts)) {
$attempt = end($corrrectattempts);
$jumpto = $DB->get_field('customlesson_answers', 'jumpto', array('id' => $attempt->answerid));
// convert the jumpto to a proper page id
if ($jumpto == 0) { // unlikely value!
$lastpageseen = $attempt->pageid;
} elseif ($jumpto == CUSTOMLESSON_NEXTPAGE) {
if (!$lastpageseen = $DB->get_field('customlesson_pages', 'nextpageid', array('id' => $attempt->pageid))) {
// no nextpage go to end of lesson
$lastpageseen = CUSTOMLESSON_EOL;
}
} else {
$lastpageseen = $jumpto;
}
}
if ($branchtables = $DB->get_records('customlesson_branch', array("lessonid"=>$lesson->id, "userid"=>$USER->id, "retry"=>$retries), 'timeseen DESC')) {
// in here, user has viewed a branch table
$lastbranchtable = current($branchtables);
if (count($corrrectattempts)>0) {
foreach($corrrectattempts as $attempt) {
if ($lastbranchtable->timeseen > $attempt->timeseen) {
// branch table was viewed later than the last attempt
$lastpageseen = $lastbranchtable->pageid;
}
break;
}
} else {
// hasnt answered any questions but has viewed a branch table
$lastpageseen = $lastbranchtable->pageid;
}
}
if (isset($lastpageseen) && $DB->count_records('customlesson_attempts', array('lessonid'=>$lesson->id, 'userid'=>$USER->id, 'retry'=>$retries)) > 0) {
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('leftduringtimedsession', 'customlesson'));
if ($lesson->timed) {
if ($lesson->retake) {
$continuelink = new single_button(new moodle_url('/mod/customlesson/view.php', array('id'=>$cm->id, 'pageid'=>$lesson->firstpageid, 'startlastseen'=>'no')), get_string('continue', 'customlesson'), 'get');
echo '<div class="center leftduring">'.$lessonoutput->message(get_string('leftduringtimed', 'customlesson'), $continuelink).'</div>';
} else {
$courselink = new single_button(new moodle_url('/course/view.php', array('id'=>$PAGE->course->id)), get_string('returntocourse', 'customlesson'), 'get');
echo '<div class="center leftduring">'.$lessonoutput->message(get_string('leftduringtimednoretake', 'customlesson'), $courselink).'</div>';
}
} else {
echo $lessonoutput->continue_links($lesson, $lastpageseen);
}
echo $lessonoutput->footer();
exit();
}
if ($attemptflag) {
if (!$lesson->retake) {
echo $lessonoutput->header($lesson, $cm, 'view', '', null, get_string("noretake", "customlesson"));
$courselink = new single_button(new moodle_url('/course/view.php', array('id'=>$PAGE->course->id)), get_string('returntocourse', 'customlesson'), 'get');
echo $lessonoutput->message(get_string("noretake", "customlesson"), $courselink);
echo $lessonoutput->footer();
exit();
}
}
// start at the first page
if (!$pageid = $DB->get_field('customlesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) {
print_error('cannotfindfirstpage', 'customlesson');
}
/// This is the code for starting a timed test
if(!isset($USER->startlesson[$lesson->id]) && !$canmanage) {
$lesson->start_timer();
}
}
$currenttab = 'view';
$extraeditbuttons = false;
$lessonpageid = null;
$timer = null;
if ($pageid != CUSTOMLESSON_EOL) {
/// This is the code updates the lessontime for a timed test
$startlastseen = optional_param('startlastseen', '', PARAM_ALPHA);
if ($startlastseen == 'no') {
// this deletes old records not totally sure if this is necessary anymore
$retries = $DB->count_records('customlesson_grades', array('lessonid'=>$lesson->id, 'userid'=>$USER->id));
$DB->delete_records('customlesson_attempts', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries));
$DB->delete_records('customlesson_branch', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries));
}
$page = $lesson->load_page($pageid);
// Check if the page is of a special type and if so take any nessecary action
$newpageid = $page->callback_on_view($canmanage);
if (is_numeric($newpageid)) {
$page = $lesson->load_page($newpageid);
}
add_to_log($PAGE->course->id, 'customlesson', 'view', 'view.php?id='. $PAGE->cm->id, $page->id, $PAGE->cm->id);
// This is where several messages (usually warnings) are displayed
// all of this is displayed above the actual page
// check to see if the user can see the left menu
if (!$canmanage) {
$lesson->displayleft = customlesson_displayleftif($lesson);
$continue = ($startlastseen !== '');
$restart = ($continue && $startlastseen == 'yes');
$timer = $lesson->update_timer($continue, $restart);
if ($lesson->timed) {
$timeleft = ($timer->starttime + $lesson->maxtime * 60) - time();
if ($timeleft <= 0) {
// Out of time
$lesson->add_message(get_string('eolstudentoutoftime', 'customlesson'));
redirect(new moodle_url('/mod/customlesson/view.php', array('id'=>$cm->id,'pageid'=>CUSTOMLESSON_EOL, 'outoftime'=>'normal')));
die; // Shouldn't be reached, but make sure
} else if ($timeleft < 60) {
// One minute warning
$lesson->add_message(get_string('studentoneminwarning', 'customlesson'));
}
}
if ($page->qtype == CUSTOMLESSON_PAGE_BRANCHTABLE && $lesson->minquestions) {
// tell student how many questions they have seen, how many are required and their grade
$ntries = $DB->count_records("customlesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
$gradeinfo = customlesson_grade($lesson, $ntries);
if ($gradeinfo->attempts) {
if ($gradeinfo->nquestions < $lesson->minquestions) {
$a = new stdClass;
$a->nquestions = $gradeinfo->nquestions;
$a->minquestions = $lesson->minquestions;
$lesson->add_message(get_string('numberofpagesviewednotice', 'customlesson', $a));
}
$a = new stdClass;
$a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1);
$a->total = $lesson->grade;
if (!$reviewmode && !$lesson->retake){
$lesson->add_message(get_string("numberofcorrectanswers", "customlesson", $gradeinfo->earned), 'notify');
$lesson->add_message(get_string('yourcurrentgradeisoutof', 'customlesson', $a), 'notify');
}
}
}
} else {
$timer = null;
if ($lesson->timed) {
$lesson->add_message(get_string('teachertimerwarning', 'customlesson'));
}
if (customlesson_display_teacher_warning($lesson)) {
// This is the warning msg for teachers to inform them that cluster
// and unseen does not work while logged in as a teacher
$warningvars->cluster = get_string('clusterjump', 'customlesson');
$warningvars->unseen = get_string('unseenpageinbranch', 'customlesson');
$lesson->add_message(get_string('teacherjumpwarning', 'customlesson', $warningvars));
}
}
$PAGE->set_url('/mod/customlesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
$PAGE->set_subpage($page->id);
$currenttab = 'view';
$extraeditbuttons = true;
$lessonpageid = $page->id;
$extrapagetitle = $page->title;
if (($edit != -1) && $PAGE->user_allowed_editing()) {
$USER->editing = $edit;
}
if (is_array($page->answers) && count($page->answers)>0) {
// this is for modattempts option. Find the users previous answer to this page,
// and then display it below in answer processing
if (isset($USER->modattempts[$lesson->id])) {
$retries = $DB->count_records('customlesson_grades', array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (!$attempts = $lesson->get_attempts($retries-1, false, $page->id)) {
print_error('cannotfindpreattempt', 'customlesson');
}
$attempt = end($attempts);
$USER->modattempts[$lesson->id] = $attempt;
} else {
$attempt = false;
}
$lessoncontent = $lessonoutput->display_page($lesson, $page, $attempt);
} else {
$data = new stdClass;
$data->id = $PAGE->cm->id;
$data->pageid = $page->id;
$data->newpageid = $lesson->get_next_page($page->nextpageid);
$customdata = array(
'title' => $page->title,
'contents' => $page->get_contents()
);
$mform = new customlesson_page_without_answers($CFG->wwwroot.'/mod/customlesson/continue.php', $customdata);
$mform->set_data($data);
ob_start();
$mform->display();
$lessoncontent = ob_get_contents();
ob_end_clean();
}
customlesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid, $extrapagetitle);
if ($attemptflag) {
// We are using level 3 header because attempt heading is a sub-heading of lesson title (MDL-30911).
echo $OUTPUT->heading(get_string('attempt', 'customlesson', $retries), 3);
}
/// This calculates and prints the ongoing score
if ($lesson->ongoing && !empty($pageid) && !$reviewmode) {
echo $lessonoutput->ongoing_score($lesson);
}
if ($lesson->displayleft) {
echo '<a name="maincontent" id="maincontent" title="' . get_string('anchortitle', 'customlesson') . '"></a>';
}
echo $lessoncontent;
echo $lessonoutput->slideshow_end();
echo $lessonoutput->progress_bar($lesson);
echo $lessonoutput->footer();
} else {
$lessoncontent = '';
// end of lesson reached work out grade
// Used to check to see if the student ran out of time
$outoftime = optional_param('outoftime', '', PARAM_ALPHA);
// Update the clock / get time information for this user
add_to_log($course->id, "customlesson", "end", "view.php?id=".$PAGE->cm->id, "$lesson->id", $PAGE->cm->id);
// We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
$lessoncontent .= $OUTPUT->heading(get_string("congratulations", "customlesson"), 3);
$lessoncontent .= $OUTPUT->box_start('generalbox boxaligncenter');
$ntries = $DB->count_records("customlesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (isset($USER->modattempts[$lesson->id])) {
$ntries--; // need to look at the old attempts :)
}
if (!$canmanage) {
$lesson->stop_timer();
$gradeinfo = customlesson_grade($lesson, $ntries);
if ($gradeinfo->attempts) {
if (!$lesson->custom) {
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofpagesviewed", "customlesson", $gradeinfo->nquestions), 'center');
if ($lesson->minquestions) {
if ($gradeinfo->nquestions < $lesson->minquestions) {
// print a warning and set nviewed to minquestions
$lessoncontent .= $lessonoutput->paragraph(get_string("youshouldview", "customlesson", $lesson->minquestions), 'center');
}
}
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofcorrectanswers", "customlesson", $gradeinfo->earned), 'center');
}
$a = new stdClass;
$a->score = $gradeinfo->earned;
$a->grade = $gradeinfo->total;
if ($gradeinfo->nmanual) {
$a->tempmaxgrade = $gradeinfo->total - $gradeinfo->manualpoints;
$a->essayquestions = $gradeinfo->nmanual;
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithessays", "customlesson", $a), 'center');
} else {
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithoutessays", "customlesson", $a), 'center');
}
$a = new stdClass;
$a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1);
$a->total = $lesson->grade;
$lessoncontent .= $lessonoutput->paragraph(get_string("yourcurrentgradeisoutof", "customlesson", $a), 'center');
$grade = new stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = $gradeinfo->grade;
$grade->completed = time();
if (!$lesson->practice) {
if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record
if (!$grades = $DB->get_records("customlesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id), "completed DESC", '*', 0, 1)) {
print_error('cannotfindgrade', 'customlesson');
}
$oldgrade = array_shift($grades);
$grade->id = $oldgrade->id;
$DB->update_record("customlesson_grades", $grade);
} else {
$newgradeid = $DB->insert_record("customlesson_grades", $grade);
}
} else {
$DB->delete_records("customlesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries));
}
} else {
if ($lesson->timed) {
if ($outoftime == 'normal') {
$grade = new stdClass();;
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = 0;
$grade->completed = time();
if (!$lesson->practice) {
$newgradeid = $DB->insert_record("customlesson_grades", $grade);
}
$lessoncontent .= get_string("eolstudentoutoftimenoanswers", "customlesson");
}
} else {
$lessoncontent .= get_string("welldone", "customlesson");
}
}
// update central gradebook
customlesson_update_grades($lesson, $USER->id);
} else {
// display for teacher
$lessoncontent .= $lessonoutput->paragraph(get_string("displayofgrade", "customlesson"), 'center');
}
$lessoncontent .= $OUTPUT->box_end(); //End of Lesson button to Continue.
// after all the grade processing, check to see if "Show Grades" is off for the course
// if yes, redirect to the course page
if (!$course->showgrades) {
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
}
// high scores code
if ($lesson->highscores && !$canmanage && !$lesson->practice) {
$lessoncontent .= $OUTPUT->box_start('center');
if ($grades = $DB->get_records("customlesson_grades", array("lessonid" => $lesson->id), "completed")) {
$madeit = false;
if ($highscores = $DB->get_records("customlesson_high_scores", array("lessonid" => $lesson->id))) {
// get all the high scores into an array
$topscores = array();
$uniquescores = array();
foreach ($highscores as $highscore) {
$grade = $grades[$highscore->gradeid]->grade;
$topscores[] = $grade;
$uniquescores[$grade] = 1;
}
// sort to find the lowest score
sort($topscores);
$lowscore = $topscores[0];
if ($gradeinfo->grade >= $lowscore || count($uniquescores) <= $lesson->maxhighscores) {
$madeit = true;
}
}
if (!$highscores or $madeit) {
$lessoncontent .= $lessonoutput->paragraph(get_string("youmadehighscore", "customlesson", $lesson->maxhighscores), 'center');
$aurl = new moodle_url('/mod/customlesson/highscores.php', array('id'=>$PAGE->cm->id, 'sesskey'=>sesskey()));
$lessoncontent .= $OUTPUT->single_button($aurl, get_string('clicktopost', 'customlesson'));
} else {
$lessoncontent .= get_string("nothighscore", "customlesson", $lesson->maxhighscores)."<br />";
}
}
$url = new moodle_url('/mod/customlesson/highscores.php', array('id'=>$PAGE->cm->id, 'link'=>'1'));
$lessoncontent .= html_writer::link($url, get_string('viewhighscores', 'customlesson'), array('class'=>'centerpadded lessonbutton standardbutton'));
$lessoncontent .= $OUTPUT->box_end();
}
if ($lesson->modattempts && !$canmanage) {
// make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
// look at the attempt records to find the first QUESTION page that the user answered, then use that page id
// to pass to view again. This is slick cause it wont call the empty($pageid) code
// $ntries is decremented above
if (!$attempts = $lesson->get_attempts($ntries)) {
$attempts = array();
$url = new moodle_url('/mod/customlesson/view.php', array('id'=>$PAGE->cm->id));
} else {
$firstattempt = current($attempts);
$pageid = $firstattempt->pageid;
// IF the student wishes to review, need to know the last question page that the student answered. This will help to make
// sure that the student can leave the lesson via pushing the continue button.
$lastattempt = end($attempts);
$USER->modattempts[$lesson->id] = $lastattempt->pageid;
$url = new moodle_url('/mod/customlesson/view.php', array('id'=>$PAGE->cm->id, 'pageid'=>$pageid));
}
$lessoncontent .= html_writer::link($url, get_string('reviewlesson', 'customlesson'), array('class' => 'centerpadded lessonbutton standardbutton'));
} elseif ($lesson->modattempts && $canmanage) {
$lessoncontent .= $lessonoutput->paragraph(get_string("modattemptsnoteacher", "customlesson"), 'centerpadded');
}
if ($lesson->activitylink) {
$lessoncontent .= $lesson->link_for_activitylink();
}
$url = new moodle_url('/course/view.php', array('id'=>$course->id));
$lessoncontent .= html_writer::link($url, get_string('returnto', 'customlesson', format_string($course->fullname, true)), array('class'=>'centerpadded lessonbutton standardbutton'));
$url = new moodle_url('/grade/index.php', array('id'=>$course->id));
$lessoncontent .= html_writer::link($url, get_string('viewgrades', 'customlesson'), array('class'=>'centerpadded lessonbutton standardbutton'));
customlesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid, get_string("congratulations", "customlesson"));
echo $lessoncontent;
echo $lessonoutput->footer();
}