course)) { error('Course is misconfigured'); } if (! $lesson = get_record('lesson', 'id', $cm->instance)) { error('Course module is incorrect'); } require_login($course->id, false, $cm); /// Print the page header if ($course->category) { $navigation = ''. $course->shortname .' ->'; } $strlessons = get_string('modulenameplural', 'lesson'); $strlesson = get_string('modulename', 'lesson'); /// CDC-FLAG moved the action up because I needed to know what the action will be before the header is printed if (empty($action)) { if (isteacher($course->id)) { $action = 'teacherview'; } elseif (time() < $lesson->available) { print_header($course->shortname .': '. format_string($lesson->name), $course->fullname, $navigation .''. $strlessons .' -> '. ''. format_string($lesson->name,true) .'', '', '', true, '', navmenu($course, $cm)); print_simple_box_start('center'); echo '
'; $button .= ''; if ($action == 'navigation' && $pageid != LESSON_EOL) { $currentpageid = $pageid; // very important not to alter $pageid. if (empty($currentpageid)) { if (!$currentpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { error('Navigation: first page not found'); } } $button .= ' | '. ''; } $button .= ' |
'; if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { // print the pages echo ''; } echo ' | ';
} elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) {
echo '
'; echo format_text($page->contents); echo " |
".get_string("numberofpagesviewed", "lesson", $nviewed). "
\n"; if ($lesson->minquestions) { if ($nviewed < $lesson->minquestions) { // print a warning and set nviewed to minquestions echo "".get_string("youshouldview", "lesson", $lesson->minquestions)." ".get_string("pages", "lesson")."
\n"; $nviewed = $lesson->minquestions; } } echo "".get_string("numberofcorrectanswers", "lesson", $ncorrect). "
\n"; $thegrade = round(100 * $ncorrect / $nviewed, 5); echo "".get_string("gradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")
\n"; } else { $score = 0; $essayquestions = 0; $essayquestionpoints = 0; if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen")) { // group each try with its page foreach ($useranswers as $useranswer) { $attemptset[$useranswer->pageid][] = $useranswer; } $pageids = array_keys($attemptset); $pageids = implode(",", $pageids); // get only the pages and their answers that the user answered $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); foreach ($attemptset as $attempts) { if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt $attempt = $attempts[$lesson->maxattempts - 1]; } else { // else, user attempted the question less than the max, so grab the last one $attempt = end($attempts); } // if essay question, handle it, otherwise add to score if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { $essayinfo = unserialize($attempt->useranswer); $score += $essayinfo->score; $essayquestions++; $essayquestionpoints += $pageanswers[$attempt->answerid]->score; } else { if (array_key_exists($attempt->answerid, $pageanswers)) { $score += $pageanswers[$attempt->answerid]->score; } } } $bestscores = array(); // find the highest possible score per page foreach ($pageanswers as $pageanswer) { if(isset($bestscores[$pageanswer->pageid])) { if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { $bestscores[$pageanswer->pageid] = $pageanswer->score; } } else { $bestscores[$pageanswer->pageid] = $pageanswer->score; } } $bestscore = array_sum($bestscores); } $thegrade = round(100 * $score / $bestscore, 5); $a = new stdClass; if ($essayquestions > 0) { $a->score = $score; $a->tempmaxgrade = $bestscore - $essayquestionpoints; $a->essayquestions = $essayquestions; $a->grade = $bestscore; echo "".get_string("gradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")
\n"; } /// CDC-FLAG /// $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = $thegrade; $grade->completed = time(); if (!$lesson->practice) { if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed")) { error("Could not find Grade Records"); } $oldgrade = end($grades); $grade->id = $oldgrade->id; if (!$update = update_record("lesson_grades", $grade)) { error("Navigation: grade not updated"); } } else { if (!$newgradeid = insert_record("lesson_grades", $grade)) { error("Navigation: grade not inserted"); } } } else { if (!delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { error("Could not delete lesson attempts"); } } } else { if ($lesson->timed) { if (isset($_GET["outoftime"])) { if ($_GET["outoftime"] == "normal") { $grade = new stdClass; $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = 0; $grade->completed = time(); if (!$lesson->practice) { if (!$newgradeid = insert_record("lesson_grades", $grade)) { error("Navigation: grade not inserted"); } } echo get_string("eolstudentoutoftimenoanswers", "lesson"); } } } else { echo get_string("welldone", "lesson"); } } } else { // display for teacher echo "".get_string("displayofgrade", "lesson")."
\n"; } print_simple_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($CFG->wwwroot.'/course/view.php?id='.$course->id); } ///CDC-FLAG /// high scores code if ($lesson->highscores && !isteacher($course->id) && !$lesson->practice) { echo "".get_string("reviewlesson", "lesson")."
\n"; } elseif ($lesson->modattempts && isteacher($course->id)) { echo "".get_string("modattemptsnoteacher", "lesson")."
"; } echo "id\">".get_string("mainmenu", "lesson")."
\n"; //CDC Back to the menu (course view). echo "id\">".get_string("viewgrades", "lesson")."
\n"; //CDC view grades } if ($lesson->displayleft || $lesson->slideshow) { // this ends the table cell and table for the leftmenu or for slideshow echo ""; } } /*******************teacher view **************************************/ elseif ($action == 'teacherview') { /// CDC-FLAG /// link to grade essay questions and to report if ($userattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions. $usercount = array(); foreach ($userattempts as $userattempts) { $usercount[$userattempts->userid] = 0; } $a = new stdClass; $a->users = count($usercount); $a->usersname = $course->students; echo ""; } if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay // get only the attempts that are in response to essay questions $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) { $studentessays = array(); // makes an array that organizes essayattempts by grouping userid, then pageid, then try count foreach ($essayattempts as $essayattempt) { $studentessays[$essayattempt->userid][$essayattempt->pageid][$essayattempt->retry][] = $essayattempt; } $a = new stdClass; $a->notgradedcount = 0; $a->notsentcount = 0; foreach ($studentessays as $pages) { // students foreach ($pages as $tries) { // pages // go through each essay per page foreach($tries as $try) { // actual attempts // make sure they didn't answer it more than the max number of attmepts if (count($try) > $lesson->maxattempts) { $essay = $try[$lesson->maxattempts-1]; } else { $essay = end($try); } $essayinfo = unserialize($essay->useranswer); if ($essayinfo->graded == 0) { $a->notgradedcount++; } if ($essayinfo->sent == 0) { $a->notsentcount++; } } } } echo "