From 5631925a26bf1f71f270ccd7b05d743edebb0b14 Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Sun, 10 Sep 2006 18:19:29 +0000 Subject: [PATCH] Started to separate out logic and presentation in view.php. Decided to wrap the question printing with HTML templates (viewstart.html and viewend.html) Still needs a lot of work --- mod/lesson/action/continue.php | 1 + mod/lesson/locallib.php | 16 ++- mod/lesson/view.php | 254 +++++++++++---------------------- mod/lesson/viewend.html | 42 ++++++ mod/lesson/viewstart.html | 61 ++++++++ 5 files changed, 206 insertions(+), 168 deletions(-) create mode 100644 mod/lesson/viewend.html create mode 100644 mod/lesson/viewstart.html diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index 49bf28fa21..249c908853 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -36,6 +36,7 @@ } if ((($timer->starttime + $lesson->maxtime * 60) - time()) <= 0) { // Out of time + lesson_set_message(get_string('eolstudentoutoftime', 'lesson')); redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); } } diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 5822ff05fd..10aeefb869 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -251,6 +251,20 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { $button = ''; } + if (!optional_param('pageid', 0, PARAM_INT) and !empty($lesson->mediafile)) { + // open our pop-up + $url = '/mod/lesson/mediafile.php?id='.$cm->id; + $name = 'lessonmediafile'; + $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $lesson->mediawidth .',height='. $lesson->mediaheight; + $meta = "\n'; + } else { + $meta = ''; + } + /// Header setup if ($course->category) { $navigation = "wwwroot/course/view.php?id=$course->id\" title=\"$course->fullname\">$course->shortname ->"; @@ -262,7 +276,7 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { /// Print header, heading, tabs and messages print_header("$course->shortname: $strname", $course->fullname, "$navigation id\" title=\"$strlessons\">$strlessons -> $strname", - '', '', true, $button, navmenu($course, $cm)); + '', $meta, true, $button, navmenu($course, $cm)); if (has_capability('mod/lesson:manage')) { print_heading_with_help(format_string($lesson->name, true), "overview", "lesson"); diff --git a/mod/lesson/view.php b/mod/lesson/view.php index cd8d2beba0..5f04b50dcf 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -1,7 +1,13 @@ -id); require_capability('mod/lesson:view', $context); -/// Check these for students only +/// 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 (!has_capability('mod/lesson:manage', $context)) { @@ -62,6 +68,7 @@ } if (!$correctpass) { + lesson_print_header($cm, $course, $lesson); echo "
\n"; print_simple_box_start('center'); echo '
' . "\n"; @@ -78,47 +85,11 @@ lesson_print_submit_link(get_string('continue', 'lesson'), 'password', 'center', 'standardbutton submitbutton'); print_simple_box_end(); echo "
\n"; + print_footer($course); exit(); } - } else if ($lesson->highscores and !$lesson->practice and !optional_param('viewed', 0)) { - // Display high scores before starting lesson - redirect("$CFG->wwwroot/mod/lesson/highscores.php?id=$cm->id"); - } - } - - lesson_print_header($cm, $course, $lesson, 'view'); - - // set up some general variables - $path = $CFG->wwwroot .'/course'; - - // this is called if a student leaves during a lesson - if($pageid == LESSON_UNSEENBRANCHPAGE) { - $pageid = lesson_unseen_question_jump($lesson->id, $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 - $timedflag = false; - $attemptflag = false; - if (empty($pageid)) { - // make sure there are pages to view - if (!get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - if (!has_capability('mod/lesson:manage', $context)) { - notify(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student - } else { - if (!count_records('lesson_pages', 'lessonid', $lesson->id)) { - redirect('view.php?id='.$cm->id); // no pages - redirect to add pages - } else { - notify(get_string('lessonpagelinkingbroken', 'lesson')); // ok, bad mojo - } - } - print_footer($course); - exit(); - } - // check for dependencies - if ($lesson->dependency and !has_capability('mod/lesson:manage', $context)) { + } else if ($lesson->dependency) { // check for dependencies if ($dependentlesson = get_record('lesson', 'id', $lesson->dependency)) { // lesson exists, so we can proceed $conditions = unserialize($lesson->conditions); @@ -140,7 +111,7 @@ } else { $timespent = true; // there isn't one set } - + // check for the gradebetterthan condition if($conditions->gradebetterthan) { if ($studentgrades = get_records_select('lesson_grades', "userid = $USER->id AND lessonid = $dependentlesson->id")) { @@ -154,7 +125,7 @@ } else { $gradebetterthan = true; // there isn't one set } - + // check for the completed condition if ($conditions->completed) { if (count_records('lesson_grades', 'userid', $USER->id, 'lessonid', $dependentlesson->id)) { @@ -163,7 +134,7 @@ } else { $completed = true; // not set } - + $errors = array(); // collect all of our error statements if (!$timespent) { @@ -176,6 +147,7 @@ $errors[] = get_string('gradebetterthanerror', 'lesson', $conditions->gradebetterthan); } if (!empty($errors)) { // print out the errors if any + lesson_print_header($cm, $course, $lesson); echo '

'; print_simple_box_start('center'); print_string('completethefollowingconditions', 'lesson', $dependentlesson->name); @@ -186,8 +158,41 @@ exit(); } } + + } else if ($lesson->highscores and !$lesson->practice and !optional_param('viewed', 0)) { // TODO: THIS DOES NOT WORK!!!! + // Display high scores before starting lesson + redirect("$CFG->wwwroot/mod/lesson/highscores.php?id=$cm->id"); + } + } + + // set up some general variables + $path = $CFG->wwwroot .'/course'; + + // this is called if a student leaves during a lesson + if($pageid == LESSON_UNSEENBRANCHPAGE) { + $pageid = lesson_unseen_question_jump($lesson->id, $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 (!get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + if (!has_capability('mod/lesson:manage', $context)) { + lesson_set_message(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student + } else { + if (!count_records('lesson_pages', 'lessonid', $lesson->id)) { + redirect("$CFG->wwwroot/mod/lesson/lesson.php?id=$cm->id&action=addpage&pageid=0"); // no pages - redirect to add pages + } else { + lesson_set_message(get_string('lessonpagelinkingbroken', 'lesson')); // ok, bad mojo + } + } } + add_to_log($course->id, 'lesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id); + // if no pageid given see if the lesson has been started if ($grades = get_records_select('lesson_grades', 'lessonid = '. $lesson->id .' AND userid = '. $USER->id, 'grade DESC')) { @@ -252,6 +257,7 @@ 'prevpageid', 0)) { error('Navigation: first page not found'); } + lesson_print_header($cm, $course, $lesson); if ($lesson->timed) { if ($lesson->retake) { print_simple_box('

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

', 'center'); @@ -290,6 +296,7 @@ break; } if (!$lesson->retake) { + lesson_print_header($cm, $course, $lesson, 'view'); print_simple_box_start('center'); echo "
"; echo get_string("noretake", "lesson"); @@ -322,21 +329,9 @@ error('Error: could not insert row into lesson_timer table'); } if ($lesson->timed) { - $timedflag = true; + lesson_set_message(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); } } - - if (!empty($lesson->mediafile)) { - // open our pop-up - $url = '/mod/lesson/mediafile.php?id='.$cm->id; - $name = 'lessonmediafile'; - $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $lesson->mediawidth .',height='. $lesson->mediaheight; - echo "\n'; - } } if ($pageid != LESSON_EOL) { @@ -359,6 +354,7 @@ } add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); + if (!$page = get_record('lesson_pages', 'id', $pageid)) { error('Navigation: the page record not found'); } @@ -394,48 +390,6 @@ $lesson->displayleft = lesson_displayleftif($lesson); } - // start of left menu - if ($lesson->displayleft) { - echo '
'; - // skip navigation link - echo ''; - if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - // print the pages - echo "
\n"; - echo '
'.get_string('lessonmenu', 'lesson')."
\n"; - echo '\n"; - echo "
\n"; - lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); - echo "
\n"; - echo "
\n"; - } - if ($page->qtype == LESSON_BRANCHTABLE) { - $width = ''; - } else { - $width = ' width="100%" '; - } - echo '
'; - // skip to anchor - echo ''; - } elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { - echo ' + +
'; // only want this if no left menu - } - - // starts the slideshow div - if($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { - echo "
\n". - "
bgcolor; - height: ".$lesson->height."px; - width: ".$lesson->width."px; - \">\n"; - } else { - echo "
\n"; - $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE - } - // This is where several messages (usually warnings) are displayed // all of this is displayed above the actual page @@ -443,10 +397,10 @@ $url = '/mod/lesson/mediafile.php?id='.$cm->id; $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $lesson->mediawidth .',height='. $lesson->mediaheight; $name = 'lessonmediafile'; - echo '
'; - link_to_popup_window ($url, $name, get_string('mediafilepopup', 'lesson'), '', '', get_string('mediafilepopup', 'lesson'), $options); - helpbutton("mediafilestudent", get_string("mediafile", "lesson"), "lesson"); - echo '
'; + $medialink = link_to_popup_window ($url, $name, get_string('mediafilepopup', 'lesson'), '', '', get_string('mediafilepopup', 'lesson'), $options, true); + $medialink .= helpbutton("mediafilestudent", get_string("mediafile", "lesson"), "lesson", true, false, '', true); + } else { + $medialink = ''; } // clock code // get time information for this user @@ -471,34 +425,16 @@ // for timed lessons, display clock if ($lesson->timed) { if(has_capability('mod/lesson:manage', $context)) { - echo '

'. get_string('teachertimerwarning', 'lesson') .'

'; + lesson_set_message(get_string('teachertimerwarning', 'lesson')); } else { - if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { - // code for the clock - echo ''. - "
".get_string("timeremaining", "lesson"). - "
"; - echo "\n"; - echo '\n"; - echo "
"; - echo "


"; - } else { + if ((($timer->starttime + $lesson->maxtime * 60) - time()) <= 0) { + lesson_set_message(get_string('eolstudentoutoftime', 'lesson')); redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); } // update clock when viewing a new page... no special treatment if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60) { - echo "

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

"; + lesson_set_message(get_string('studentoneminwarning', 'lesson')); } - - if ($timedflag) { - print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); - } } } @@ -509,10 +445,6 @@ error('Error: could not update lesson_timer table'); } } - - if ($attemptflag) { - print_heading(get_string('attempt', 'lesson', $retries + 1)); - } // before we output everything check to see if the page is a EOB, if so jump directly // to it's associated branch table @@ -544,11 +476,9 @@ } else if ($answer->jumpto == LESSON_PREVIOUSPAGE) { $answer->jumpto = $page->prevpageid; } - redirect("view.php?id=$cm->id&action=navigation&pageid=$answer->jumpto");// REMOVED: , get_string("endofbranch", "lesson") + redirect("view.php?id=$cm->id&action=navigation&pageid=$answer->jumpto"); break; } - print_footer($course); - exit(); } else { error('Navigation: No answers on EOB'); } @@ -559,15 +489,10 @@ if (lesson_display_teacher_warning($lesson->id)) { $warningvars->cluster = get_string('clusterjump', 'lesson'); $warningvars->unseen = get_string('unseenpageinbranch', 'lesson'); - echo '

'. get_string('teacherjumpwarning', 'lesson', $warningvars) .'

'; + lesson_set_message(get_string('teacherjumpwarning', 'lesson', $warningvars)); } } - /// This calculates and prints the ongoing score - if ($lesson->ongoing and !empty($pageid)) { - lesson_print_ongoing_score($lesson); - } - if ($page->qtype == LESSON_BRANCHTABLE) { if ($lesson->minquestions and !has_capability('mod/lesson:manage', $context)) { // tell student how many questions they have seen, how many are required and their grade @@ -576,29 +501,30 @@ $gradeinfo = lesson_grade($lesson, $ntries); if ($gradeinfo->attempts) { - echo "

".get_string("numberofpagesviewed", "lesson", $gradeinfo->nquestions). - "; (".get_string("youshouldview", "lesson", $lesson->minquestions).")
"; - // count the number of distinct correct pages if ($gradeinfo->nquestions < $lesson->minquestions) { - $gradeinfo->nquestions = $lesson->minquestions; + $a = new stdClass; + $a->nquestions = $gradeinfo->nquestions; + $a->minquestions = $lesson->minquestions; + lesson_set_message(get_string('numberofpagesviewednotice', 'lesson', $a)); } - echo get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned)."
\n"; - echo get_string("yourcurrentgradeis", "lesson", - number_format($gradeinfo->grade * $lesson->grade / 100, 1)). - " (".get_string("outof", "lesson", $lesson->grade).")

\n"; + lesson_set_message(get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned), 'notify'); + $a = new stdClass; + $a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1); + $a->total = $lesson->grade; + lesson_set_message(get_string('yourcurrentgradeisoutof', 'lesson', $a), 'notify'); } } } - + + lesson_print_header($cm, $course, $lesson, 'view'); + require($CFG->dirroot.'/mod/lesson/viewstart.html'); + // now starting to print the page's contents - echo "
"; - echo ""; - echo format_string($lesson->name) . ""; if ($page->qtype == LESSON_BRANCHTABLE) { - echo ":
"; print_heading(format_string($page->title)); + } else { + $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE } - echo "

"; if (!$lesson->slideshow) { $options = new stdClass; @@ -607,7 +533,6 @@ format_text($page->contents, FORMAT_MOODLE, $options). '', 'center'); } - echo "
\n"; // this is for modattempts option. Find the users previous answer to this page, // and then display it below in answer processing @@ -894,18 +819,15 @@ get_string("continue", "lesson")."\" />

\n"; echo "\n"; } + + // Finish of the page lesson_print_progress_bar($lesson, $course); - echo "
\n"; + require($CFG->dirroot.'/mod/lesson/viewend.html'); } else { // end of lesson reached work out grade - // check to see if the student ran out of time + // Used to check to see if the student ran out of time $outoftime = optional_param('outoftime', '', PARAM_ALPHA); - if ($lesson->timed && !has_capability('mod/lesson:manage', $context)) { - if ($outoftime == 'normal') { - print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center"); - } - } // Update the clock / get time information for this user if (!has_capability('mod/lesson:manage', $context)) { @@ -923,6 +845,8 @@ } add_to_log($course->id, "lesson", "end", "view.php?id=$cm->id", "$lesson->id", $cm->id); + + lesson_print_header($cm, $course, $lesson, 'view'); print_heading(get_string("congratulations", "lesson")); print_simple_box_start("center"); $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); @@ -1087,10 +1011,6 @@ echo "\n"; // Back to the menu (course view). echo "\n"; //view grades } - - if ($lesson->displayleft || $lesson->slideshow) { // this ends the table cell and table for the leftmenu or for slideshow - echo "
"; - } /// Finish the page print_footer($course); diff --git a/mod/lesson/viewend.html b/mod/lesson/viewend.html new file mode 100644 index 0000000000..1e8014d151 --- /dev/null +++ b/mod/lesson/viewend.html @@ -0,0 +1,42 @@ + + +
+ + +timed and !has_capability('mod/lesson:manage', $context)) { // Display for timed lessons and for students only ?> + + + + + + + + +
+ + +
+timed) { ?> +
+
+ \ No newline at end of file diff --git a/mod/lesson/viewstart.html b/mod/lesson/viewstart.html new file mode 100644 index 0000000000..9824ddf130 --- /dev/null +++ b/mod/lesson/viewstart.html @@ -0,0 +1,61 @@ + + + + + +displayleft) { +// Displaying left menu + if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { ?> + + + +displayleft) +?> + +
+ +
+
+ + +
+
+ + displayleft) { ?> + + + + + +slideshow && $page->qtype == LESSON_BRANCHTABLE) { // Starts the slideshow div ?> + +
+ + + +ongoing and !empty($pageid)) { + lesson_print_ongoing_score($lesson); + } +?> + \ No newline at end of file -- 2.39.5