3 /**************************************************************************
4 this file displays the lesson statistics.
5 **************************************************************************/
7 require_once('../../config.php');
8 require_once('locallib.php');
10 $id = required_param('id', PARAM_INT
); // Course Module ID
11 $pageid = optional_param('pageid', NULL, PARAM_INT
); // Lesson Page ID
12 $action = optional_param('action'); // action to take
14 if (! $cm = get_record('course_modules', 'id', $id)) {
15 error('Course Module ID was incorrect');
18 if (! $course = get_record('course', 'id', $cm->course
)) {
19 error('Course is misconfigured');
22 if (! $lesson = get_record('lesson', 'id', $cm->instance
)) {
23 error('Course module is incorrect');
26 if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id
, 'timeseen')) {
27 error('Could not find any attempts for this lesson');
30 if (! $students = get_records_sql("SELECT DISTINCT u.*
31 FROM {$CFG->prefix}user u,
32 {$CFG->prefix}lesson_attempts a
33 WHERE a.lessonid = '$lesson->id' and
35 ORDER BY u.lastname")) {
36 error("Error: could not find users");
40 if (! $grades = get_records('lesson_grades', 'lessonid', $lesson->id
, 'completed')) {
44 if (! $times = get_records('lesson_timer', 'lessonid', $lesson->id
, 'starttime')) {
48 // make sure people are where they should be
49 require_login($course->id
, false);
51 if (!isteacheredit($course->id
)) {
52 error("Must be teacher to view Reports");
55 /// Print the page header
56 $strlessons = get_string('modulenameplural', 'lesson');
58 if ($course->category
) {
59 $navigation = '<a href="../../course/view.php?id='. $course->id
.'">'. $course->shortname
.'</a> ->';
61 $button = '<form target="'. $CFG->framename
.'" method="get" action="'. $CFG->wwwroot
.'/course/mod.php">'.
62 '<input type="hidden" name="update" value="'. $cm->id
.'" />'.
63 '<input type="hidden" name="sesskey" value="'. $USER->sesskey
.'" />'.
64 '<input type="hidden" name="return" value="true" />'.
65 '<input type="submit" value="'. get_string('editlessonsettings', 'lesson') .'" /></form>';
67 print_header($course->shortname
.': '. format_string($lesson->name
), $course->fullname
,
68 "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> <a href=\"view.php?id=$cm->id\">".format_string($lesson->name
,true)."</a>
69 -> <a href=\"report.php?id=$cm->id\">".get_string("report", "lesson")."</a>",
70 '', '', true, $button,
71 navmenu($course, $cm));
73 print_heading(get_string("lesson", "lesson", format_string($lesson->name
)), "center", 5);
76 $detaillink = "<a href=\"report.php?id=$cm->id&action=detail\">".get_string("detailedstats", "lesson")."</a>";
77 $overviewlink = "<a href=\"report.php?id=$cm->id\">".get_string("overview", "lesson")."</a>";
78 print_heading($overviewlink." ".$detaillink);
81 /**************************************************************************
82 this action is for default view and overview view
83 **************************************************************************/
84 if (empty($action) ||
$action == 'view') {
85 $studentdata = array();
87 // build an array for output
88 foreach ($attempts as $attempt) {
89 // if the user is not in the array or if the retry number is not in the sub array, add the data for that try.
90 if (!array_key_exists($attempt->userid
, $studentdata) ||
!array_key_exists($attempt->retry
, $studentdata[$attempt->userid
])) {
91 // restore/setup defaults
97 // search for the grade record for this try. if not there, the nulls defined above will be used.
98 foreach($grades as $grade) {
99 // check to see if the grade matches the correct user
100 if ($grade->userid
== $attempt->userid
) {
101 // see if n is = to the retry
102 if ($n == $attempt->retry
) {
104 $usergrade = $grade->grade
;
107 $n++
; // if not equal, then increment n
111 // search for the time record for this try. if not there, the nulls defined above will be used.
112 foreach($times as $time) {
113 // check to see if the grade matches the correct user
114 if ($time->userid
== $attempt->userid
) {
115 // see if n is = to the retry
116 if ($n == $attempt->retry
) {
118 $timeend = $time->lessontime
;
119 $timestart = $time->starttime
;
122 $n++
; // if not equal, then increment n
126 // build up the array.
127 // this array represents each student and all of their tries at the lesson
128 $studentdata[$attempt->userid
][$attempt->retry
] = array( "timestart" => $timestart,
129 "timeend" => $timeend,
130 "grade" => $usergrade,
131 "try" => $attempt->retry
,
132 "userid" => $attempt->userid
);
135 // set all the stats variables
143 $table = new stdClass
;
145 // set up the table object
146 $table->head
= array(get_string('studentname', 'lesson', $course->student
), get_string('attempts', 'lesson'), get_string('highscore', 'lesson'));
147 $table->align
= array("center", "left", "left");
148 $table->wrap
= array("nowrap", "nowrap", "nowrap");
149 $table->width
= "90%";
150 $table->size
= array("*", "70%", "*");
152 // print out the $studentdata array
153 // going through each student that has attempted the lesson, so, each student should have something to be displayed
154 foreach ($students as $student) {
155 // check to see if the student has attempts to print out
156 if (array_key_exists($student->id
, $studentdata)) {
157 // set/reset some variables
159 // gather the data for each user attempt
161 $bestgradefound = false;
162 // $tries holds all the tries/retries a student has done
163 $tries = $studentdata[$student->id
];
164 $studentname = "{$student->lastname}, $student->firstname";
165 foreach ($tries as $try) {
166 // start to build up the link
167 $temp = "<a href=\"report.php?id=$cm->id&action=detail&userid=".$try["userid"]."&try=".$try["try"]."\">";
168 if ($try["grade"] != NULL) { // if NULL then not done yet
169 // this is what the link does when the user has completed the try
170 $timetotake = $try["timeend"] - $try["timestart"];
172 $temp .= $try["grade"]."%";
173 $bestgradefound = true;
174 if ($try["grade"] > $bestgrade) {
175 $bestgrade = $try["grade"];
177 $temp .= " ".userdate($try["timestart"]);
178 $temp .= ", (".format_time($timetotake).")</a>";
180 // this is what the link does/looks like when the user has not completed the try
181 $temp .= get_string("notcompleted", "lesson");
182 $temp .= " ".userdate($try["timestart"])."</a>";
185 // build up the attempts array
188 // run these lines for the stats only if the user finnished the lesson
189 if ($try["grade"] != NULL) {
191 $avescore +
= $try["grade"];
192 $avetime +
= $timetotake;
193 if ($try["grade"] > $highscore ||
$highscore == NULL) {
194 $highscore = $try["grade"];
196 if ($try["grade"] < $lowscore ||
$lowscore == NULL) {
197 $lowscore = $try["grade"];
199 if ($timetotake > $hightime ||
$hightime == NULL) {
200 $hightime = $timetotake;
202 if ($timetotake < $lowtime ||
$lowtime == NULL) {
203 $lowtime = $timetotake;
207 // get line breaks in after each attempt
208 $attempts = implode("<br />\n", $attempts);
209 // add it to the table data[] object
210 $table->data
[] = array($studentname, $attempts, $bestgrade."%");
213 // print it all out !
216 // some stat calculations
217 if ($numofattempts == 0) {
218 $avescore = get_string("notcompleted", "lesson");
220 $avescore = format_float($avescore/$numofattempts, 2, ".", ",");
222 if ($avetime == NULL) {
223 $avetime = get_string("notcompleted", "lesson");
225 $avetime = format_float($avetime/$numofattempts, 0, ".", ",");
226 $avetime = format_time($avetime);
228 if ($hightime == NULL) {
229 $hightime = get_string("notcompleted", "lesson");
231 $hightime = format_time($hightime);
233 if ($lowtime == NULL) {
234 $lowtime = get_string("notcompleted", "lesson");
236 $lowtime = format_time($lowtime);
238 if ($highscore == NULL) {
239 $highscore = get_string("notcompleted", "lesson");
241 if ($lowscore == NULL) {
242 $lowscore = get_string("notcompleted", "lesson");
246 print_heading(get_string('lessonstats', 'lesson'));
247 $stattable = new stdClass
;
248 $stattable->head
= array(get_string('averagescore', 'lesson'), get_string('averagetime', 'lesson'),
249 get_string('highscore', 'lesson'), get_string('lowscore', 'lesson'),
250 get_string('hightime', 'lesson'), get_string('lowtime', 'lesson'));
251 $stattable->align
= array("center", "center", "center", "center", "center", "center");
252 $stattable->wrap
= array("nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
253 $stattable->width
= "90%";
254 $stattable->size
= array("*", "*", "*", "*", "*", "*");
255 $stattable->data
[] = array($avescore, $avetime, $highscore, $lowscore, $hightime, $lowtime);
257 print_table($stattable);
259 /**************************************************************************
260 this action is for a student detailed view and for the general detailed view
262 General flow of this section of the code
263 1. Generate a object which holds values for the statistics for each question/answer
264 2. Cycle through all the pages to create a object. Foreach page, see if the student actually answered
265 the page. Then process the page appropriatly. Display all info about the question,
266 Highlight correct answers, show how the user answered the question, and display statistics
268 3. Print out info about the try (if needed)
269 4. Print out the object which contains all the try info
271 **************************************************************************/
272 else if ($action == 'detail') {
274 $formattextdefoptions->para
= false; //I'll use it widely in this page
276 $userid = optional_param('userid', NULL, PARAM_INT
); // if empty, then will display the general detailed view
277 $try = optional_param('try', NULL, PARAM_INT
);
279 if (! $lessonpages = get_records("lesson_pages", "lessonid", $lesson->id
)) {
280 error("Could not find Lesson Pages");
282 if (! $pageid = get_field("lesson_pages", "id", "lessonid", $lesson->id
, "prevpageid", 0)) {
283 error("Could not find first page");
286 if (!empty($userid)) {
287 // print out users name
288 $headingobject->lastname
= $students[$userid]->lastname
;
289 $headingobject->firstname
= $students[$userid]->firstname
;
290 $headingobject->attempt
= $try +
1;
291 print_heading(get_string("studentattemptlesson", "lesson", $headingobject));
294 // now gather the stats into an object
295 $firstpageid = $pageid;
296 $pagestats = array();
297 while ($pageid != 0) { // EOL
298 $page = $lessonpages[$pageid];
300 if ($allanswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid = $page->id", "timeseen")) {
301 // get them ready for processing
302 $orderedanswers = array();
303 foreach ($allanswers as $singleanswer) {
304 // ordering them like this, will help to find the single attempt record that we want to keep.
305 $orderedanswers[$singleanswer->userid
][$singleanswer->retry
][] = $singleanswer;
307 // this is foreach user and for each try for that user, keep one attempt record
308 foreach ($orderedanswers as $orderedanswer) {
309 foreach($orderedanswer as $tries) {
310 if(count($tries) > $lesson->maxattempts
) { // if there are more tries than the max that is allowed, grab the last "legal" attempt
311 $temp = $tries[$lesson->maxattempts
- 1];
313 // else, user attempted the question less than the max, so grab the last one
316 // page interpretation
317 // depending on the page type, process stat info for that page
318 switch ($page->qtype
) {
319 case LESSON_MULTICHOICE
:
320 case LESSON_TRUEFALSE
:
321 if ($page->qoption
) {
322 $userresponse = explode(",", $temp->useranswer
);
323 foreach ($userresponse as $response) {
324 if (isset($pagestats[$temp->pageid
][$response])) {
325 $pagestats[$temp->pageid
][$response]++
;
327 $pagestats[$temp->pageid
][$response] = 1;
331 if (isset($pagestats[$temp->pageid
][$temp->answerid
])) {
332 $pagestats[$temp->pageid
][$temp->answerid
]++
;
334 $pagestats[$temp->pageid
][$temp->answerid
] = 1;
337 if (isset($pagestats[$temp->pageid
]["total"])) {
338 $pagestats[$temp->pageid
]["total"]++
;
340 $pagestats[$temp->pageid
]["total"] = 1;
343 case LESSON_SHORTANSWER
:
344 case LESSON_NUMERICAL
:
345 if (isset($pagestats[$temp->pageid
][$temp->useranswer
])) {
346 $pagestats[$temp->pageid
][$temp->useranswer
]++
;
348 $pagestats[$temp->pageid
][$temp->useranswer
] = 1;
350 if (isset($pagestats[$temp->pageid
]["total"])) {
351 $pagestats[$temp->pageid
]["total"]++
;
353 $pagestats[$temp->pageid
]["total"] = 1;
356 case LESSON_MATCHING
:
357 if ($temp->correct
) {
358 if (isset($pagestats[$temp->pageid
]["correct"])) {
359 $pagestats[$temp->pageid
]["correct"]++
;
361 $pagestats[$temp->pageid
]["correct"] = 1;
364 if (isset($pagestats[$temp->pageid
]["total"])) {
365 $pagestats[$temp->pageid
]["total"]++
;
367 $pagestats[$temp->pageid
]["total"] = 1;
371 $essayinfo = unserialize($temp->useranswer
);
372 if ($essayinfo->graded
) {
373 if (isset($pagestats[$temp->pageid
])) {
374 $essaystats = $pagestats[$temp->pageid
];
375 $essaystats->totalscore +
= $essayinfo->score
;
376 $essaystats->total++
;
377 $pagestats[$temp->pageid
] = $essaystats;
379 $essaystats->totalscore
= $essayinfo->score
;
380 $essaystats->total
= 1;
381 $pagestats[$temp->pageid
] = $essaystats;
390 // no one answered yet...
392 //unset($orderedanswers); initialized above now
393 $pageid = $page->nextpageid
;
398 $answerpages = array();
400 $pageid = $firstpageid;
401 // cycle through all the pages
402 // foreach page, add to the $answerpages[] array all the data that is needed
403 // from the question, the users attempt, and the statistics
404 // grayout pages that the user did not answer and Branch, end of branch, cluster
405 // and end of cluster pages
406 while ($pageid != 0) { // EOL
407 $page = $lessonpages[$pageid];
408 $answerpage = new stdClass
;
410 $answerdata = new stdClass
;
412 $answerpage->title
= format_string($page->title
);
413 $answerpage->contents
= format_text($page->contents
);
415 // get the page qtype
416 switch ($page->qtype
) {
418 case LESSON_MATCHING
:
419 case LESSON_TRUEFALSE
:
420 case LESSON_NUMERICAL
:
421 $answerpage->qtype
= $LESSON_QUESTION_TYPE[$page->qtype
];
422 $answerpage->grayout
= 0;
424 case LESSON_SHORTANSWER
:
425 $answerpage->qtype
= $LESSON_QUESTION_TYPE[$page->qtype
];
426 if ($page->qoption
) {
427 $answerpage->qtype
.= " - ".get_string("casesensitive", "lesson");
429 $answerpage->grayout
= 0;
431 case LESSON_MULTICHOICE
:
432 $answerpage->qtype
= $LESSON_QUESTION_TYPE[$page->qtype
];
433 if ($page->qoption
) {
434 $answerpage->qtype
.= " - ".get_string("multianswer", "lesson");
436 $answerpage->grayout
= 0;
438 case LESSON_BRANCHTABLE
:
439 $answerpage->qtype
= get_string("branchtable", "lesson");
440 $answerpage->grayout
= 1;
442 case LESSON_ENDOFBRANCH
:
443 $answerpage->qtype
= get_string("endofbranch", "lesson");
444 $answerpage->grayout
= 1;
446 case LESSON_CLUSTER
:
447 $answerpage->qtype
= get_string("clustertitle", "lesson");
448 $answerpage->grayout
= 1;
450 case LESSON_ENDOFCLUSTER
:
451 $answerpage->qtype
= get_string("endofclustertitle", "lesson");
452 $answerpage->grayout
= 1;
457 if (empty($userid)) {
458 // there is no userid, so set these vars and display stats.
459 $answerpage->grayout
= 0;
461 $answerdata->score
= NULL;
462 $answerdata->response
= NULL;
463 } elseif ($useranswers = get_records_select("lesson_attempts",
464 "lessonid = $lesson->id AND userid = $userid AND retry = $try AND pageid = $page->id", "timeseen")) {
465 // get the user's answer for this page
466 // need to find the right one
468 foreach ($useranswers as $userattempt) {
469 $useranswer = $userattempt;
471 if ($lesson->maxattempts
== $i) {
472 break; // reached maxattempts, break out
476 // user did not answer this page, gray it out and set some nulls
477 $answerpage->grayout
= 1;
479 $answerdata->score
= NULL;
480 $answerdata->response
= NULL;
483 // build up the answer data
484 if ($answers = get_records("lesson_answers", "pageid", $page->id
, "id")) {
487 // go through each answer and display it properly with statistics, highlight if correct answer,
488 // and display what the user entered
489 foreach ($answers as $answer) {
490 switch ($page->qtype
) {
491 case LESSON_MULTICHOICE
:
492 case LESSON_TRUEFALSE
:
493 if ($page->qoption
) {
494 $userresponse = explode(",", $useranswer->useranswer
);
495 if (in_array($answer->id
, $userresponse)) {
497 $data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
498 if (!isset($answerdata->response
)) {
499 if ($answer->response
== NULL) {
500 if ($useranswer->correct
) {
501 $answerdata->response
= get_string("thatsthecorrectanswer", "lesson");
503 $answerdata->response
= get_string("thatsthewronganswer", "lesson");
506 $answerdata->response
= $answer->response
;
509 if (!isset($answerdata->score
)) {
510 if ($lesson->custom
) {
511 $answerdata->score
= get_string("pointsearned", "lesson").": ".$answer->score
;
512 } elseif ($useranswer->correct
) {
513 $answerdata->score
= get_string("receivedcredit", "lesson");
515 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
520 $data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[$i]\" value=\"0\" disabled=\"disabled\" />";
522 if (($answer->score
> 0 && $lesson->custom
) ||
(lesson_iscorrect($page->id
, $answer->jumpto
) && !$lesson->custom
)) {
523 $data .= "<font class=highlight>".format_text($answer->answer
,FORMAT_MOODLE
,$formattextdefoptions)."</font>";
525 $data .= format_text($answer->answer
,FORMAT_MOODLE
,$formattextdefoptions);
528 if ($answer->id
== $useranswer->answerid
) {
530 $data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
531 if ($answer->response
== NULL) {
532 if ($useranswer->correct
) {
533 $answerdata->response
= get_string("thatsthecorrectanswer", "lesson");
535 $answerdata->response
= get_string("thatsthewronganswer", "lesson");
538 $answerdata->response
= $answer->response
;
540 if ($lesson->custom
) {
541 $answerdata->score
= get_string("pointsearned", "lesson").": ".$answer->score
;
542 } elseif ($useranswer->correct
) {
543 $answerdata->score
= get_string("receivedcredit", "lesson");
545 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
549 $data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[$i]\" value=\"0\" disabled=\"disabled\" />";
551 if (($answer->score
> 0 && $lesson->custom
) ||
(lesson_iscorrect($page->id
, $answer->jumpto
) && !$lesson->custom
)) {
552 $data .= "<font class=\"highlight\">".format_text($answer->answer
,FORMAT_MOODLE
,$formattextdefoptions)."</font>";
554 $data .= format_text($answer->answer
,FORMAT_MOODLE
,$formattextdefoptions);
557 if (isset($pagestats[$page->id
][$answer->id
])) {
558 $percent = $pagestats[$page->id
][$answer->id
] / $pagestats[$page->id
]["total"] * 100;
559 $percent = round($percent, 2);
560 $percent .= "% ".get_string("checkedthisone", "lesson");
562 $percent = get_string("noonecheckedthis", "lesson");
565 $answerdata->answers
[] = array($data, $percent);
567 case LESSON_SHORTANSWER
:
568 case LESSON_NUMERICAL
:
569 if ($useranswer == NULL && $i == 0) {
570 // I have the $i == 0 because it is easier to blast through it all at once.
571 if (isset($pagestats[$page->id
])) {
572 $stats = $pagestats[$page->id
];
573 $total = $stats["total"];
574 unset($stats["total"]);
575 foreach ($stats as $valentered => $ntimes) {
576 $data = "<input type=\"text\" size=\"50\" disabled=\"disabled\" readonly=\"readonly\" value=\"$valentered\">";
577 $percent = $ntimes / $total * 100;
578 $percent = round($percent, 2);
579 $percent .= "% ".get_string("enteredthis", "lesson");
580 $answerdata->answers
[] = array($data, $percent);
583 $answerdata->answers
[] = array(get_string("nooneansweredthisquestion", "lesson"), " ");
586 } else if ($answer->answer
== $useranswer->useranswer
&& $useranswer != NULL) {
587 // get in here when a user answer matches one of the answers to the page
588 $data = "<input type=\"text\" size=\"50\" disabled=\"disabled\" readonly=\"readonly\" value=\"$useranswer->useranswer\">";
589 if (isset($pagestats[$page->id
][$answer->answer
])) {
590 $percent = $pagestats[$page->id
][$answer->answer
] / $pagestats[$page->id
]["total"] * 100;
591 $percent = round($percent, 2);
592 $percent .= "% ".get_string("enteredthis", "lesson");
594 $percent = get_string("nooneenteredthis", "lesson");
596 $answerdata->answers
[] = array($data, $percent);
598 if ($answer->response
== NULL) {
599 if ($useranswer->correct
) {
600 $answerdata->response
= get_string("thatsthecorrectanswer", "lesson");
602 $answerdata->response
= get_string("thatsthewronganswer", "lesson");
605 $answerdata->response
= $answer->response
;
607 if ($lesson->custom
) {
608 $answerdata->score
= get_string("pointsearned", "lesson").": ".$answer->score
;
609 } elseif ($useranswer->correct
) {
610 $answerdata->score
= get_string("receivedcredit", "lesson");
612 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
614 } elseif ($answer == end($answers) && !isset($answerdata) && $useranswer != NULL) {
615 // get in here when what the user entered is not one of the answers
616 $data = "<input type=\"text\" size=\"50\" disabled=\"disabled\" readonly=\"readonly\" value=\"$useranswer->useranswer\">";
617 if (isset($pagestats[$page->id
][$answer->answer
])) {
618 $percent = $pagestats[$page->id
][$answer->answer
] / $pagestats[$page->id
]["total"] * 100;
619 $percent = round($percent, 2);
620 $percent .= "% ".get_string("enteredthis", "lesson");
622 $percent = get_string("nooneenteredthis", "lesson");
624 $answerdata->answers
[] = array($data, $percent);
626 $answerdata->response
= get_string("thatsthewronganswer", "lesson");
627 if ($lesson->custom
) {
628 $answerdata->score
= get_string("pointsearned", "lesson").": 0";
630 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
634 case LESSON_MATCHING
:
635 if ($n == 0 && $useranswer->correct
) {
636 if ($answer->response
== NULL && $useranswer != NULL) {
637 $answerdata->response
= get_string("thatsthecorrectanswer", "lesson");
639 $answerdata->response
= $answer->response
;
641 } elseif ($n == 1 && !$useranswer->correct
) {
642 if ($answer->response
== NULL && $useranswer != NULL) {
643 $answerdata->response
= get_string("thatsthewronganswer", "lesson");
645 $answerdata->response
= $answer->response
;
648 if ($n == 2 && $useranswer->correct
&& $useranswer != NULL) {
649 if ($lesson->custom
) {
650 $answerdata->score
= get_string("pointsearned", "lesson").": ".$answer->score
;
652 $answerdata->score
= get_string("receivedcredit", "lesson");
654 } elseif ($n == 3 && !$useranswer->correct
&& $useranswer != NULL) {
655 if ($lesson->custom
) {
656 $answerdata->score
= get_string("pointsearned", "lesson").": ".$answer->score
;
658 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
661 $data = "<select disabled=\"disabled\"><option selected>".strip_tags(format_text($answer->answer
,FORMAT_MOODLE
,$formattextdefoptions))."</option></select>";
662 if ($useranswer != NULL) {
663 $userresponse = explode(",", $useranswer->useranswer
);
664 $data .= "<select disabled=\"disabled\"><option selected>".strip_tags(format_string($answers[$userresponse[$i]]->response
,FORMAT_PLAIN
,$formattextdefoptions))."</option></select>";
666 $data .= "<select disabled=\"disabled\"><option selected>".strip_tags(format_string($answer->response
,FORMAT_PLAIN
,$formattextdefoptions))."</option></select>";
670 if (isset($pagestats[$page->id
])) {
671 $percent = $pagestats[$page->id
]["correct"] / $pagestats[$page->id
]["total"] * 100;
672 $percent = round($percent, 2);
673 $percent .= "% ".get_string("answeredcorrectly", "lesson");
675 $percent = get_string("nooneansweredthisquestion", "lesson");
681 $answerdata->answers
[] = array($data, $percent);
687 if ($useranswer != NULL) {
688 $essayinfo = unserialize($useranswer->useranswer
);
689 if ($essayinfo->response
== NULL) {
690 $answerdata->response
= get_string("nocommentyet", "lesson");
692 $answerdata->response
= $essayinfo->response
;
694 if (isset($pagestats[$page->id
])) {
695 $percent = $pagestats[$page->id
]->totalscore
/ $pagestats[$page->id
]->total
* 100;
696 $percent = round($percent, 2);
697 $percent = get_string("averagescore", "lesson").": ". $percent ."%";
699 // dont think this should ever be reached....
700 $percent = get_string("nooneansweredthisquestion", "lesson");
702 if ($essayinfo->graded
) {
703 if ($lesson->custom
) {
704 $answerdata->score
= get_string("pointsearned", "lesson").": ".$essayinfo->score
;
705 } elseif ($essayinfo->score
) {
706 $answerdata->score
= get_string("receivedcredit", "lesson");
708 $answerdata->score
= get_string("didnotreceivecredit", "lesson");
711 $answerdata->score
= get_string("havenotgradedyet", "lesson");
714 $essayinfo->answer
= get_string("didnotanswerquestion", "lesson");
717 if (isset($pagestats[$page->id
])) {
718 $avescore = $pagestats[$page->id
]->totalscore
/ $pagestats[$page->id
]->total
;
719 $avescore = round($avescore, 2);
720 $avescore = get_string("averagescore", "lesson").": ". $avescore ;
722 // dont think this should ever be reached....
723 $avescore = get_string("nooneansweredthisquestion", "lesson");
725 $answerdata->answers
[] = array($essayinfo->answer
, $avescore);
727 case LESSON_BRANCHTABLE
:
728 $data = "<input type=\"button\" name=\"$answer->id\" value=\"".strip_tags(format_text($answer->answer
, FORMAT_MOODLE
,$formattextdefoptions))."\" disabled=\"disabled\"> ";
729 $data .= get_string("jumptsto", "lesson").": ";
730 if ($answer->jumpto
== 0) {
731 $data .= get_string("thispage", "lesson");
732 } elseif ($answer->jumpto
== LESSON_NEXTPAGE
) {
733 $data .= get_string("nextpage", "lesson");
734 } elseif ($answer->jumpto
== LESSON_EOL
) {
735 $data .= get_string("endoflesson", "lesson");
736 } elseif ($answer->jumpto
== LESSON_UNSEENBRANCHPAGE
) {
737 $data .= get_string("unseenpageinbranch", "lesson");
738 } elseif ($answer->jumpto
== LESSON_PREVIOUSPAGE
) {
739 $data .= get_string("previouspage", "lesson");
740 } elseif ($answer->jumpto
== LESSON_RANDOMPAGE
) {
741 $data .= get_string("randompageinbranch", "lesson");
742 } elseif ($answer->jumpto
== LESSON_RANDOMBRANCH
) {
743 $data .= get_string("randombranch", "lesson");
744 } elseif ($answer->jumpto
== LESSON_CLUSTERJUMP
) {
745 $data .= get_string("clusterjump", "lesson");
747 $data .= format_string($lessonpages[$answer->jumpto
]->title
)." ".get_string("page", "lesson");
750 $answerdata->answers
[] = array($data, "");
751 $answerpage->grayout
= 1; // always grayed out
753 case LESSON_ENDOFBRANCH
:
754 case LESSON_CLUSTER
:
755 case LESSON_ENDOFCLUSTER
:
756 $data = get_string("jumptsto", "lesson").": ";
757 if ($answer->jumpto
== 0) {
758 $data .= get_string("thispage", "lesson");
759 } elseif ($answer->jumpto
== LESSON_NEXTPAGE
) {
760 $data .= get_string("nextpage", "lesson");
761 } elseif ($answer->jumpto
== LESSON_EOL
) {
762 $data .= get_string("endoflesson", "lesson");
763 } elseif ($answer->jumpto
== LESSON_UNSEENBRANCHPAGE
) {
764 $data .= get_string("unseenpageinbranch", "lesson");
765 } elseif ($answer->jumpto
== LESSON_PREVIOUSPAGE
) {
766 $data .= get_string("previouspage", "lesson");
767 } elseif ($answer->jumpto
== LESSON_RANDOMPAGE
) {
768 $data .= get_string("randompageinbranch", "lesson");
769 } elseif ($answer->jumpto
== LESSON_RANDOMBRANCH
) {
770 $data .= get_string("randombranch", "lesson");
771 } elseif ($answer->jumpto
== LESSON_CLUSTERJUMP
) {
772 $data .= get_string("clusterjump", "lesson");
774 $data .= format_string($lessonpages[$answer->jumpto
]->title
)." ".get_string("page", "lesson");
776 $answerdata->answers
[] = array($data, "");
777 $answerpage->grayout
= 1; // always grayed out
780 if (isset($answerdata)) {
781 $answerpage->answerdata
= $answerdata;
784 $answerpages[] = $answerpage;
786 $pageid = $page->nextpageid
;
789 /// actually start printing something
790 $table = new stdClass
;
791 $table->wrap
= array();
792 $table->width
= "60%";
795 if (!empty($userid)) {
796 // if looking at a students try, print out some basic stats at the top
797 $table->head
= array();
798 $table->align
= array("right", "left");
799 $table->size
= array("*", "*");
801 if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $userid", "completed", "*", $try, 1)) {
804 $grade = current($grades);
805 $grade = $grade->grade
;
807 if (!$times = get_records_select("lesson_timer", "lessonid = $lesson->id and userid = $userid", "starttime", "*", $try, 1)) {
810 $timetotake = current($times);
811 $timetotake = $timetotake->lessontime
- $timetotake->starttime
;
814 if ($timetotake == -1 ||
$completed == -1 ||
$grade == -1) {
815 $table->align
= array("center");
816 $table->size
= array("*");
818 $table->data
[] = array(get_string("notcompleted", "lesson"));
820 $table->align
= array("right", "left");
821 $table->size
= array("*", "*");
823 $table->data
[] = array(get_string("timetaken", "lesson").":", format_time($timetotake));
824 $table->data
[] = array(get_string("completed", "lesson").":", userdate($completed));
825 $table->data
[] = array(get_string("grade", "lesson").":", $grade."%");
832 $table->align
= array("left", "left");
833 $table->size
= array("70%", "*");
835 foreach ($answerpages as $page) {
837 if ($page->grayout
) { // set the color of text
838 $fontstart = "<span class=\"dimmed\">";
839 $fontend = "</font>";
840 $fontstart2 = $fontstart;
841 $fontend2 = $fontend;
849 $table->head
= array($fontstart2.$page->qtype
.": ".format_string($page->title
).$fontend2, $fontstart2.get_string("classstats", "lesson").$fontend2);
850 $table->data
[] = array($fontstart.get_string("question", "lesson").": <br />".$fontend.$fontstart2.$page->contents
.$fontend2, " ");
851 $table->data
[] = array($fontstart.get_string("answer", "lesson").":".$fontend);
852 // apply the font to each answer
853 foreach ($page->answerdata
->answers
as $answer){
855 foreach ($answer as $single) {
856 // need to apply a font to each one
857 $modified[] = $fontstart2.$single.$fontend2;
859 $table->data
[] = $modified;
861 if ($page->answerdata
->response
!= NULL) {
862 $table->data
[] = array($fontstart.get_string("response", "lesson").": <br />".$fontend.$fontstart2.format_text($page->answerdata
->response
,FORMAT_MOODLE
,$formattextdefoptions).$fontend2, " ");
864 $table->data
[] = array($page->answerdata
->score
, " ");
871 error("Fatal Error: Unknown Action: ".$action."\n");
875 print_footer($course);