From 86b7a42880c7f4c61beee3589b3a3cb7639d1e5c Mon Sep 17 00:00:00 2001 From: michaelpenne Date: Tue, 5 Apr 2005 22:42:34 +0000 Subject: [PATCH] now if you leave the lesson the the middle of a bunch of branch tables, you will return to the last one you answered. Also, if show grades is off in course settings, the lesson will process and store the grade for the student but then redirect the student to the course page immediatly. --- mod/lesson/view.php | 117 +++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 44 deletions(-) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index ae216882502..3a5a3782076 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -166,11 +166,7 @@ if ($attempts = get_records_select('lesson_attempts', "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND correct = 1", 'timeseen DESC')) { - // get the first page - if (!$firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, - 'prevpageid', 0)) { - error('Navigation: first page not found'); - } + foreach ($attempts as $attempt) { $jumpto = get_field('lesson_answers', 'jumpto', 'id', $attempt->answerid); // convert the jumpto to a proper page id @@ -187,46 +183,72 @@ } break; // only look at the latest correct attempt } - //if ($lastpageseen != $firstpageid) { - if (count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id, 'retry', $retries) > 0) { - /// CDC-FLAG /// - if ($lesson->timed) { - if ($lesson->retake) { - echo '
' . "\n"; - echo '' . "\n"; - echo '' . "\n"; - echo '' . "\n"; - echo '' . "\n"; /// CDC-FLAG added this line - print_simple_box('

'. get_string('leftduringtimed', 'lesson') .'

', 'center'); - echo '

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' - echo '
' . "\n"; - echo '';///CDC Chris Berri added close div tag - } else { - print_simple_box_start('center'); - echo '
'; - echo get_string('leftduringtimednoretake', 'lesson'); - echo '

'. get_string('returntocourse', 'lesson') .''; - echo '
'; - print_simple_box_end(); - } - - } else { - echo "
\n"; - echo "id\" />\n"; - echo "\n"; - echo "\n"; - echo "\n"; /// CDC-FLAG added this line - print_simple_box("

".get_string('youhaveseen','lesson').'

', - "center"); - echo "

   

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' - echo "
\n"; echo "";///CDC Chris Berri added close div tag - } - print_footer($course); - exit(); + } else { + $attempts = NULL; + } + + if ($branchtables = get_records_select('lesson_branch', + "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries", 'timeseen DESC')) { + // in here, user has viewed a branch table + $lastbranchtable = current($branchtables); + if ($attempts != NULL) { + foreach($attempts 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 ($lastpageseen != $firstpageid) { + if (isset($lastpageseen) and count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id, 'retry', $retries) > 0) { + // get the first page + if (!$firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, + 'prevpageid', 0)) { + error('Navigation: first page not found'); } + /// CDC-FLAG /// + if ($lesson->timed) { + if ($lesson->retake) { + echo '
' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; /// CDC-FLAG added this line + print_simple_box('

'. get_string('leftduringtimed', 'lesson') .'

', 'center'); + echo '

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' + echo '
' . "\n"; + echo '';///CDC Chris Berri added close div tag + } else { + print_simple_box_start('center'); + echo '
'; + echo get_string('leftduringtimednoretake', 'lesson'); + echo '

'. get_string('returntocourse', 'lesson') .''; + echo '
'; + print_simple_box_end(); + } + + } else { + echo "
\n"; + echo "id\" />\n"; + echo "\n"; + echo "\n"; + echo "\n"; /// CDC-FLAG added this line + print_simple_box("

".get_string('youhaveseen','lesson').'

', + "center"); + echo "

   

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' + echo "
\n"; echo "";///CDC Chris Berri added close div tag + } + print_footer($course); + exit(); } if ($grades) { @@ -1039,6 +1061,13 @@ 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)) { echo "

";