From: tjhunt Date: Thu, 23 Jul 2009 10:01:19 +0000 (+0000) Subject: lesson: MDL-19890 Fix block-printing code in lesson (I hope) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4262a2f8062c557e41d8cc5f2116cf64e2c3364c;p=moodle.git lesson: MDL-19890 Fix block-printing code in lesson (I hope) This got broken by one of the commits for MDL-19077 & MDL-19010 --- diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 6e85b521fc..00d7f87b26 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -616,12 +616,27 @@ class required_js extends linked_requirement { * is responsible for outputting this HTML promptly. */ public function asap() { - if ($this->is_done()) { - return; - } if (!$this->manager->is_head_done()) { $this->in_head(); return ''; + } else { + return $this->now(); + } + } + + /** + * Return the required JavaScript immediately, so it can be included in some + * HTML that is being built. + * + * This is not really recommeneded. But is necessary in some legacy code that + * includes a .js files that does document.write. + * + * @return string The HTML for the script tag. The caller + * is responsible for making sure it is output. + */ + public function now() { + if ($this->is_done()) { + return ''; } $output = $this->get_html(); $this->mark_done(); diff --git a/mod/lesson/action/continue.html b/mod/lesson/action/continue.html index 8fd055055a..1f78ba6d90 100644 --- a/mod/lesson/action/continue.html +++ b/mod/lesson/action/continue.html @@ -7,26 +7,6 @@ **/ ?> - - - - - - - - - - - - - - -
- id, $lesson); - - if (!empty($CFG->showblocksonmodpages)) { - if ((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) { - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); - } - } - ?> - - displayleft) { // Skip navigation anchor ?> @@ -97,23 +77,3 @@ - - - id, $lesson, $timer); - lesson_print_mediafile_block($cm->id, $lesson); - - if (!empty($CFG->showblocksonmodpages)) { - if ((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) { - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); - } - } - ?> -
- \ No newline at end of file diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index afa2ed2e01..6bfe5d6302 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -682,7 +682,7 @@ $options = new stdClass; $options->noclean = true; $options->para = true; - $feedback = print_simple_box(format_text($page->contents, FORMAT_MOODLE, $options), 'center', '', '', 5, 'generalbox', '', true); + $feedback = print_box(format_text($page->contents, FORMAT_MOODLE, $options), 'generalbox boxaligncenter', '', true); $feedback .= ''.get_string("youranswer", "lesson").' : '.format_text($studentanswer, FORMAT_MOODLE, $options). "
".format_text($response, FORMAT_MOODLE, $options).'
'; } @@ -783,12 +783,9 @@ $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); $PAGE->set_subpage($page->id); - $pageblocks = blocks_setup($PAGE); - - $leftcolumnwidth = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); - $rightcolumnwidth = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210); /// Print the header, heading and tabs + lesson_add_pretend_blocks($PAGE, $cm, $lesson, $timer); lesson_print_header($cm, $course, $lesson, 'view', true, $page->id); include(dirname(__FILE__).'/continue.html'); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index c133b47fe4..bd3632225d 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -230,19 +230,16 @@ if (!defined("LESSON_RESPONSE_EDITOR")) { function lesson_print_header($cm, $course, $lesson, $currenttab = '', $extraeditbuttons = false, $lessonpageid = NULL) { global $CFG, $PAGE; - // Note: MDL-19010 there will be further changes to printing header and blocks. - // The code will be much nicer than this eventually. - $context = get_context_instance(CONTEXT_MODULE, $cm->id); $activityname = format_string($lesson->name, true, $course->id); - $strlesson = get_string('modulename', 'lesson'); if (empty($title)) { $title = "{$course->shortname}: $activityname"; } /// Build the buttons + $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (has_capability('mod/lesson:edit', $context)) { - $buttons = update_module_button($cm->id, $course->id, $strlesson); + $buttons = update_module_button($cm->id, $course->id, get_string('modulename', 'lesson')); if ($extraeditbuttons) { if ($lessonpageid === NULL) { print_error('invalidpageid', 'lesson'); @@ -255,20 +252,6 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '', $extraedit ''. ''. ''; - - if (!empty($CFG->showblocksonmodpages) and $PAGE->user_allowed_editing()) { - if ($PAGE->user_is_editing()) { - $onoff = 'off'; - } else { - $onoff = 'on'; - } - $buttons .= '
frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/view.php">'. - ''. - ''. - ''. - ' -
'; - } } $buttons = '' . $buttons .''; } @@ -1734,54 +1717,93 @@ function lesson_displayleftif($lesson) { return $lesson->displayleft; } +/** + * + * @param $cm + * @param $lesson + * @param $page + * @return unknown_type + */ +function lesson_add_pretend_blocks($page, $cm, $lesson, $timer = null) { + $bc = lesson_menu_block_contents($cm->id, $lesson); + if (!empty($bc)) { + $regions = $page->blocks->get_regions(); + $firstregion = reset($regions); + $page->blocks->add_pretend_block($bc, $firstregion); + } + + $bc = lesson_mediafile_block_contents($cm->id, $lesson); + if (!empty($bc)) { + $page->blocks->add_pretend_block($bc, $page->blocks->get_default_region()); + } + + if (!empty($timer)) { + $bc = lesson_clock_block_contents($cm->id, $lesson, $timer, $page); + if (!empty($bc)) { + $page->blocks->add_pretend_block($bc, $page->blocks->get_default_region()); + } + } +} + /** * If there is a media file associated with this - * lesson, then print it in a block. + * lesson, return a block_contents that displays it. * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object - * @return void + * @return block_contents **/ -function lesson_print_mediafile_block($cmid, $lesson) { - if (!empty($lesson->mediafile)) { - $url = '/mod/lesson/mediafile.php?id='.$cmid; - $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $lesson->mediawidth .',height='. $lesson->mediaheight; - $name = 'lessonmediafile'; - - $content = link_to_popup_window ($url, $name, get_string('mediafilepopup', 'lesson'), '', '', get_string('mediafilepopup', 'lesson'), $options, true); - $content .= helpbutton("mediafilestudent", get_string("mediafile", "lesson"), "lesson", true, false, '', true); - - print_side_block(get_string('linkedmedia', 'lesson'), $content, NULL, NULL, '', array('class' => 'mediafile'), get_string('linkedmedia', 'lesson')); +function lesson_mediafile_block_contents($cmid, $lesson) { + if (empty($lesson->mediafile)) { + return null; } + + $url = '/mod/lesson/mediafile.php?id='.$cmid; + $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $lesson->mediawidth .',height='. $lesson->mediaheight; + $name = 'lessonmediafile'; + + $content = link_to_popup_window ($url, $name, get_string('mediafilepopup', 'lesson'), '', '', get_string('mediafilepopup', 'lesson'), $options, true); + $content .= helpbutton("mediafilestudent", get_string("mediafile", "lesson"), "lesson", true, false, '', true); + + $bc = new block_contents(); + $bc->title = get_string('linkedmedia', 'lesson'); + $bc->set_classes('mediafile'); + $bc->content = $content; + + return $bc; } /** * If a timed lesson and not a teacher, then - * print the clock + * return a block_contents containing the clock. * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object * @param object $timer Full timer record object - * @return void + * @return block_contents **/ -function lesson_print_clock_block($cmid, $lesson, $timer) { - global $CFG, $PAGE; - +function lesson_clock_block_contents($cmid, $lesson, $timer, $page) { + // Display for timed lessons and for students only $context = get_context_instance(CONTEXT_MODULE, $cmid); + if(!$lesson->timed || has_capability('mod/lesson:manage', $context)) { + return null; + } - // Display for timed lessons and for students only - if($lesson->timed and !has_capability('mod/lesson:manage', $context) and !empty($timer)) { + $content = '
'; + $content .= lesson_print_time_remaining($timer->starttime, $lesson->maxtime, true)."\n"; + $content .= '
'; - $clocksettings = Array('starttime'=>$timer->starttime, 'servertime'=>time(),'testlength'=>($lesson->maxtime * 60)); - $content = $PAGE->requires->data_for_js('clocksettings', $clocksettings)->asap(); - $content .= $PAGE->requires->js('mod/lesson/timer.js')->asap(); - $content .= $PAGE->requires->js_function_call('show_clock')->asap(); - $content .= '
'; - $content .= lesson_print_time_remaining($timer->starttime, $lesson->maxtime, true)."\n"; - $content .= '
'; + $clocksettings = array('starttime'=>$timer->starttime, 'servertime'=>time(),'testlength'=>($lesson->maxtime * 60)); + $content .= $page->requires->data_for_js('clocksettings', $clocksettings)->now(); + $content .= $page->requires->js('mod/lesson/timer.js')->now(); + $content .= $page->requires->js_function_call('show_clock')->now(); - print_side_block(get_string('timeremaining', 'lesson'), $content, NULL, NULL, '', array('class' => 'clock'), get_string('timeremaining', 'lesson')); - } + $bc = new block_contents(); + $bc->title = get_string('timeremaining', 'lesson'); + $bc->set_classes('clock'); + $bc->content = $content; + + return $bc; } /** @@ -1792,77 +1814,44 @@ function lesson_print_clock_block($cmid, $lesson, $timer) { * @param object $lesson Full lesson record object * @return void **/ -function lesson_print_menu_block($cmid, $lesson) { +function lesson_menu_block_contents($cmid, $lesson) { global $CFG, $DB; - if ($lesson->displayleft) { - $pageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0)); - $params = array ("lessonid" => $lesson->id); - $pages = $DB->get_records_select('lesson_pages', "lessonid = :lessonid", $params); - $currentpageid = optional_param('pageid', $pageid, PARAM_INT); - - if ($pageid and $pages) { - $content = '\n
\n\n
\n"; - print_side_block(get_string('lessonmenu', 'lesson'), $content, NULL, NULL, '', array('class' => 'menu'), get_string('lessonmenu', 'lesson')); - } + if (!$pageid || !$pages) { + return null; } -} -/** - * This is not ideal, but checks to see if a - * column has "block" content. - * - * In the future, it would be nice if the lesson - * media file, timer and navigation were blocks - * then this would be unnecessary. - * - * @uses $CFG - * @uses $PAGE - * @param object $lesson Full lesson record object - * @param array $pageblocks An array of block instances organized by left and right columns - * @param string $column Pass either BLOCK_POS_RIGHT or BLOCK_POS_LEFT constants - * @return boolean - **/ -function lesson_blocks_have_content($lesson, $pageblocks, $column) { - global $CFG, $PAGE; + $content = '\n
\n\n
\n"; - return false; -} + $bc = new block_contents(); + $bc->title = get_string('lessonmenu', 'lesson'); + $bc->set_classes('menu'); + $bc->content = $content; -?> + return $bc; +} diff --git a/mod/lesson/view.php b/mod/lesson/view.php index b882bf7a94..659ecf3422 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -39,12 +39,12 @@ } lesson_print_header($cm, $course, $lesson); - print_simple_box_start('center'); + print_box_start('generalbox boxaligncenter'); echo '
'; echo '

'.$message.'

'; echo ''; echo '
'; - print_simple_box_end(); + print_box_end(); print_footer($course); exit(); @@ -65,7 +65,7 @@ if (!$correctpass) { lesson_print_header($cm, $course, $lesson); echo "
\n"; - print_simple_box_start('center'); + print_box_start('generalbox boxaligncenter'); echo '
' . "\n"; echo '
'; echo '' . "\n"; @@ -79,7 +79,7 @@ lesson_print_submit_link(get_string('continue', 'lesson'), 'password', 'center', 'standardbutton submitbutton'); echo '
'; - print_simple_box_end(); + print_box_end(); echo "
\n"; print_footer($course); exit(); @@ -147,10 +147,10 @@ if (!empty($errors)) { // print out the errors if any lesson_print_header($cm, $course, $lesson); echo '

'; - print_simple_box_start('center'); + print_box_start('generalbox boxaligncenter'); print_string('completethefollowingconditions', 'lesson', $dependentlesson->name); echo '

'.implode('
'.get_string('and', 'lesson').'
', $errors).'

'; - print_simple_box_end(); + print_box_end(); echo '

'; print_footer($course); exit(); @@ -260,22 +260,22 @@ lesson_print_header($cm, $course, $lesson); if ($lesson->timed) { if ($lesson->retake) { - print_simple_box('

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

', 'center'); + print_box('

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

', 'generalbox boxaligncenter'); echo '
'. ''. get_string('continue', 'lesson').'
'; } else { - print_simple_box_start('center'); + print_box_start('generalbox boxaligncenter'); echo '
'; echo get_string('leftduringtimednoretake', 'lesson'); echo '

'; echo '
'; - print_simple_box_end(); + print_box_end(); } } else { - print_simple_box("

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

', - "center"); + print_box("

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

', + 'generalbox boxaligncenter'); echo '
'; echo ''. @@ -297,12 +297,12 @@ } if (!$lesson->retake) { lesson_print_header($cm, $course, $lesson, 'view'); - print_simple_box_start('center'); + print_box_start('generalbox boxaligncenter'); echo "
"; echo get_string("noretake", "lesson"); echo "

'; echo "
"; - print_simple_box_end(); + print_box_end(); print_footer($course); exit(); //redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson")); @@ -507,6 +507,7 @@ } /// Print the page header, heading and tabs + lesson_add_pretend_blocks($PAGE, $cm, $lesson, $timer); lesson_print_header($cm, $course, $lesson, 'view', 'true', $page->id); if ($attemptflag) { @@ -518,7 +519,14 @@ lesson_print_ongoing_score($lesson); } - require($CFG->dirroot.'/mod/lesson/viewstart.html'); + if ($lesson->displayleft) { + echo ''; + } + + if ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { // Starts the slideshow div + echo '
'; + } // now starting to print the page's contents if ($page->qtype == LESSON_BRANCHTABLE) { @@ -530,9 +538,9 @@ if (!$lesson->slideshow) { $options = new stdClass; $options->noclean = true; - print_simple_box('
'. + print_box('
'. format_text($page->contents, FORMAT_MOODLE, $options). - '
', 'center'); + '
', 'generalbox boxaligncenter'); } // this is for modattempts option. Find the users previous answer to this page, @@ -556,7 +564,7 @@ echo ""; echo ""; echo ""; - print_simple_box_start("center"); + print_box_start('generalbox boxaligncenter'); echo ''; } // default format text options @@ -575,7 +583,7 @@ echo '
'. ": \n"; echo '
'; - print_simple_box_end(); + print_box_end(); lesson_print_submit_link(get_string('pleaseenteryouranswerinthebox', 'lesson'), 'answerform'); break; case LESSON_TRUEFALSE : @@ -598,7 +606,7 @@ $i++; } echo ''; - print_simple_box_end(); + print_box_end(); lesson_print_submit_link(get_string('pleasecheckoneanswer', 'lesson'), 'answerform'); break; case LESSON_MULTICHOICE : @@ -637,7 +645,7 @@ $i++; } echo ''; - print_simple_box_end(); + print_box_end(); if ($page->qoption) { $linkname = get_string('pleasecheckoneormoreanswers', 'lesson'); } else { @@ -688,7 +696,7 @@ } } echo ''; - print_simple_box_end(); + print_box_end(); lesson_print_submit_link(get_string('pleasematchtheabovepairs', 'lesson'), 'answerform'); break; case LESSON_BRANCHTABLE : @@ -745,12 +753,12 @@ echo ':'. '\n"; echo ''; - print_simple_box_end(); + print_box_end(); lesson_print_submit_link(get_string('pleaseenteryouranswerinthebox', 'lesson'), 'answerform'); break; default: // close the tags MDL-7861 echo (''); - print_simple_box_end(); + print_box_end(); break; } if ($page->qtype != LESSON_BRANCHTABLE) { // To fix XHTML problem (BT have their own forms) @@ -813,7 +821,7 @@ // Finish of the page lesson_print_progress_bar($lesson, $course); - require($CFG->dirroot.'/mod/lesson/viewend.html'); + } else { // end of lesson reached work out grade @@ -833,12 +841,13 @@ $DB->update_record("lesson_timer", $timer); } - + add_to_log($course->id, "lesson", "end", "view.php?id=$cm->id", "$lesson->id", $cm->id); - + + lesson_add_pretend_blocks($PAGE, $cm, $lesson, $timer); lesson_print_header($cm, $course, $lesson, 'view'); print_heading(get_string("congratulations", "lesson")); - print_simple_box_start("center"); + print_box_start('generalbox boxaligncenter'); $ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id)); if (isset($USER->modattempts[$lesson->id])) { $ntries--; // need to look at the old attempts :) @@ -920,7 +929,7 @@ // display for teacher echo "

".get_string("displayofgrade", "lesson")."

\n"; } - print_simple_box_end(); //End of Lesson button to Continue. + print_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 diff --git a/mod/lesson/viewend.html b/mod/lesson/viewend.html deleted file mode 100644 index f2760960a2..0000000000 --- a/mod/lesson/viewend.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - id, $lesson, $timer); - lesson_print_mediafile_block($cm->id, $lesson); - - if (!empty($CFG->showblocksonmodpages)) { - if ((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) { - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); - } - } - ?> - - - - - \ No newline at end of file diff --git a/mod/lesson/viewstart.html b/mod/lesson/viewstart.html deleted file mode 100644 index d9286e96ae..0000000000 --- a/mod/lesson/viewstart.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - -
- id, $lesson); - - if (!empty($CFG->showblocksonmodpages)) { - if ((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) { - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); - } - } - ?> - - - displayleft) { ?> - - - - - -slideshow && $page->qtype == LESSON_BRANCHTABLE) { // Starts the slideshow div ?> - -
- - - \ No newline at end of file