From: mark-nielsen Date: Sat, 24 Mar 2007 23:07:59 +0000 (+0000) Subject: Adding blocks to lesson X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=888f0c546070ea7b13da4e957437413397ba53f2;p=moodle.git Adding blocks to lesson * added pagelib.php with lesson_page class definition * Lesson view now uses standard page layout classes Other fixes: * minor fix to mod settings form * fixed function names (some were missing lesson_ prefix) --- diff --git a/mod/lesson/action/continue.html b/mod/lesson/action/continue.html index b9c59c7178..8fd055055a 100644 --- a/mod/lesson/action/continue.html +++ b/mod/lesson/action/continue.html @@ -8,14 +8,24 @@ ?> - - +
+ - + - - +
- id, $lesson); ?> + + + 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 ?> @@ -30,11 +40,7 @@ } ?> - - - - -
+ modattempts[$lesson->id])) { // User is modifying attempts - save button and some instructions ?> @@ -93,11 +99,21 @@
+ + - id, $lesson, $timer); ?> - id, $lesson); // If there is one ?> + 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 6cd9e6b794..97d6051117 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -8,6 +8,9 @@ **/ confirm_sesskey(); + require_once($CFG->dirroot.'/mod/lesson/pagelib.php'); + require_once($CFG->libdir.'/blocklib.php'); + // left menu code // check to see if the user can see the left menu if (!has_capability('mod/lesson:manage', $context)) { @@ -771,8 +774,16 @@ if ($maxattemptsreached != 0) { lesson_set_message('('.get_string("maximumnumberofattemptsreached", "lesson").')'); } - - lesson_print_header($cm, $course, $lesson, 'view'); + + $PAGE = page_create_object('mod-lesson-view', $lesson->id); + $PAGE->set_lessonpageid($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 + $PAGE->print_header(); include(dirname(__FILE__).'/continue.html'); ?> diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 3a3ea18474..9cd26f4d41 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -238,6 +238,12 @@ function lesson_delete_instance($id) { delete_event($event->id); } } + $pagetypes = page_import_types('mod/lesson/'); + foreach ($pagetypes as $pagetype) { + if (!delete_records('block_instance', 'pageid', $lesson->id, 'pagetype', $pagetype)) { + $result = false; + } + } return $result; } diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 98a9390a2d..8162eb0780 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -225,55 +225,19 @@ if (!defined("LESSON_RESPONSE_EDITOR")) { **/ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { global $CFG, $USER; - + $strlessons = get_string('modulenameplural', 'lesson'); $strlesson = get_string('modulename', 'lesson'); $strname = format_string($lesson->name, true); - + $context = get_context_instance(CONTEXT_MODULE, $cm->id); - - // Changed the update_module_button and added another button when a teacher is checking the navigation of the lesson + if (has_capability('mod/lesson:edit', $context)) { - $button = update_module_button($cm->id, $course->id, $strlesson); - - if ($currenttab == 'view') { - if (!$pageid = optional_param('pageid', 0, PARAM_INT)) { - $pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0); - } - if (!empty($pageid) and $pageid != LESSON_EOL) { - $button = '
'.$button. - ''. - '
frametarget.' method="get" action="'. $CFG->wwwroot .'/mod/lesson/lesson.php">'. - '
'. - ''. - ''. - ''. - ''. - ''. - '
'. - '
'. - '
'; - } - } } else { $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 $navigation = array(); if ($course->id != SITEID) { @@ -294,20 +258,20 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { /// Print header, heading, tabs and messages print_header("$course->shortname: $strname", $course->fullname, $breadcrumb, - '', $meta, true, $button, navmenu($course, $cm)); - + '', '', true, $button, navmenu($course, $cm)); + if (has_capability('mod/lesson:manage', $context)) { print_heading_with_help(format_string($lesson->name, true), "overview", "lesson"); + + if (!empty($currenttab)) { + include($CFG->dirroot.'/mod/lesson/tabs.php'); + } } else { - print_heading($lesson->name); - } - - if (!empty($currenttab) and has_capability('mod/lesson:manage', $context)) { - include($CFG->dirroot.'/mod/lesson/tabs.php'); + print_heading(format_string($lesson->name, true)); } - + lesson_print_messages(); - + return true; } @@ -1758,7 +1722,7 @@ function lesson_displayleftif($lesson) { * @param object $lesson Full lesson record object * @return void **/ -function print_mediafile_block($cmid, $lesson) { +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; @@ -1780,7 +1744,7 @@ function print_mediafile_block($cmid, $lesson) { * @param object $timer Full timer record object * @return void **/ -function print_clock_block($cmid, $lesson, $timer) { +function lesson_print_clock_block($cmid, $lesson, $timer) { global $CFG; $context = get_context_instance(CONTEXT_MODULE, $cmid); @@ -1812,7 +1776,7 @@ function print_clock_block($cmid, $lesson, $timer) { * @param object $lesson Full lesson record object * @return void **/ -function print_menu_block($cmid, $lesson) { +function lesson_print_menu_block($cmid, $lesson) { global $CFG; if ($lesson->displayleft) { @@ -1843,4 +1807,45 @@ function print_menu_block($cmid, $lesson) { } } +/** + * 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; + + // First check lesson conditions + if ($column == BLOCK_POS_RIGHT) { + $managecap = false; + if ($cm = get_coursemodule_from_instance('lesson', $lesson->id, $lesson->course)) { + $managecap = has_capability('mod/lesson:manage', get_context_instance(CONTEXT_MODULE, $cm->id)); + } + if (($lesson->timed and !$managecap) or !empty($lesson->mediafile)) { + return true; + } + } else if ($column == BLOCK_POS_LEFT) { + if ($lesson->displayleft) { + return true; + } + } + if (!empty($CFG->showblocksonmodpages)) { + if ((blocks_have_content($pageblocks, $column) || $PAGE->user_is_editing())) { + return true; + } + } + + return false; +} + ?> diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index a3d74cf96d..afa6e5c146 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -245,7 +245,7 @@ class mod_lesson_mod_form extends moodleform_mod { // get the module name and then store it in a new array if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) { - if ($this->_cm->id != $mod->id){ + if (!empty($this->_cm->id) and $this->_cm->id != $mod->id){ $modinstances[$mod->id] = $mod->modname.' - '.$module->name; } } diff --git a/mod/lesson/pagelib.php b/mod/lesson/pagelib.php new file mode 100644 index 0000000000..b8b2c5fe13 --- /dev/null +++ b/mod/lesson/pagelib.php @@ -0,0 +1,206 @@ +libdir.'/pagelib.php'); +require_once($CFG->dirroot.'/course/lib.php'); // needed for some blocks + +/** + * Define the page types + * + **/ +define('PAGE_LESSON_VIEW', 'mod-lesson-view'); + +/** + * Map the classes to the page types + * + **/ +page_map_class(PAGE_LESSON_VIEW, 'page_lesson'); + +/** + * Add the page types defined in this file + * + **/ +$DEFINEDPAGES = array(PAGE_LESSON_VIEW); + +/** + * Class that models the behavior of a lesson + * + * @author Mark Nielsen (lesson extention only) + * @package lesson + **/ +class page_lesson extends page_generic_activity { + + /** + * Module name + * + * @var string + **/ + var $activityname = 'lesson'; + /** + * Current lesson page ID + * + * @var string + **/ + var $lessonpageid = NULL; + + /** + * Print a standard lesson heading. + * + * This will also print up to three + * buttons in the breadcrumb, lesson heading + * lesson tabs, lesson notifications and perhaps + * a popup with a media file. + * + * @return void + **/ + function print_header($title = '', $morebreadcrumbs = array()) { + global $CFG; + + $this->init_full(); + + /// Variable setup/check + $context = get_context_instance(CONTEXT_MODULE, $this->modulerecord->id); + $activityname = format_string($this->activityrecord->name); + + if ($this->lessonpageid === NULL) { + error('Programmer error: must set the lesson page ID'); + } + if (empty($title)) { + $title = "{$this->courserecord->shortname}: $activityname"; + } + + /// Build the breadcrumb + $breadcrumbs = array(); + if ($this->courserecord->id != SITEID) { + $breadcrumbs[$this->courserecord->shortname] = "$CFG->wwwroot/course/view.php?id={$this->courserecord->id}"; + } + $breadcrumbs[get_string('modulenameplural', 'lesson')] = "$CFG->wwwroot/mod/lesson/index.php?id={$this->courserecord->id}"; + + if (empty($morebreadcrumbs)) { + $breadcrumbs[$activityname] = ''; + } else { + $breadcrumbs[$activityname] = "$CFG->wwwroot/mod/lesson/view.php?id={$this->modulerecord->id}&pageid=$this->lessonpageid"; + $breadcrumbs = array_merge($breadcrumbs, $morebreadcrumbs); + } + // Convert to breadcrumb string + $urls = array(); + foreach($breadcrumbs as $text => $href) { + if (empty($href)) { + $urls[] = $text; + } else { + $urls[] = ''.$text.''; + } + } + $breadcrumb = implode(' -> ', $urls); + + /// Build the buttons + if (has_capability('mod/lesson:edit', $context)) { + $buttons = ''.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson')); + + if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) { + $buttons .= '
frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'. + ''. + ''. + ''. + ''. + ''. + '
'; + + if (!empty($CFG->showblocksonmodpages) and $this->user_allowed_editing()) { + if ($this->user_is_editing()) { + $onoff = 'off'; + } else { + $onoff = 'on'; + } + $buttons .= '
frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/view.php">'. + ''. + ''. + ''. + ' +
'; + } + } + $buttons .= '
'; + } else { + $buttons = ' '; + } + + /// Build the meta + /// Currently broken because the $meta is printed before the JavaScript is printed + // if (!optional_param('pageid', 0, PARAM_INT) and !empty($this->activityrecord->mediafile)) { + // // open our pop-up + // $url = '/mod/lesson/mediafile.php?id='.$this->modulerecord->id; + // $name = 'lessonmediafile'; + // $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $this->activityrecord->mediawidth .',height='. $this->activityrecord->mediaheight; + // $meta = "\n'; + // } else { + $meta = ''; + // } + + print_header($title, $this->courserecord->fullname, $breadcrumb, '', $meta, true, $buttons, navmenu($this->courserecord, $this->modulerecord)); + + if (has_capability('mod/lesson:manage', $context)) { + print_heading_with_help($activityname, 'overview', 'lesson'); + + // Rename our objects for the sake of the tab code + list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord, &$this->courserecord, &$this->activityrecord, 'view'); + include($CFG->dirroot.'/mod/lesson/tabs.php'); + } else { + print_heading($activityname); + } + + lesson_print_messages(); + } + + function get_type() { + return PAGE_LESSON_VIEW; + } + + function blocks_get_positions() { + return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT); + } + + function blocks_default_position() { + return BLOCK_POS_RIGHT; + } + + function blocks_move_position(&$instance, $move) { + if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) { + return BLOCK_POS_RIGHT; + } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) { + return BLOCK_POS_LEFT; + } + return $instance->position; + } + + /** + * Needed to add the ID of the current lesson page + * + * @return array + **/ + function url_get_parameters() { + $this->init_full(); + return array('id' => $this->modulerecord->id, 'pageid' => $this->lessonpageid);; + } + + /** + * Set the current lesson page ID + * + * @return void + **/ + function set_lessonpageid($pageid) { + $this->lessonpageid = $pageid; + } +} +?> \ No newline at end of file diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index 95bd04c440..9d19bb3cb7 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -6,8 +6,13 @@ text-align: left; } -.mod-lesson .sideblock { - width: 170px; +.mod-lesson #layout-table { + width: 100%; +} + +.mod-lesson .edit_buttons form, +.mod-lesson .edit_buttons input { + display: inline; } .mod-lesson .clock .content { diff --git a/mod/lesson/view.php b/mod/lesson/view.php index be8a0588c4..51cdcd1f23 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -8,11 +8,14 @@ **/ require_once('../../config.php'); - require_once('locallib.php'); - require_once('lib.php'); + require_once($CFG->dirroot.'/mod/lesson/locallib.php'); + require_once($CFG->dirroot.'/mod/lesson/lib.php'); + require_once($CFG->dirroot.'/mod/lesson/pagelib.php'); + require_once($CFG->libdir.'/blocklib.php'); $id = required_param('id', PARAM_INT); // Course Module ID $pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID + $edit = optional_param('edit', -1, PARAM_BOOL); list($cm, $course, $lesson) = lesson_get_basics($id); @@ -492,8 +495,20 @@ } } } - - lesson_print_header($cm, $course, $lesson, 'view'); + + $PAGE = page_create_instance($lesson->id); + $PAGE->set_lessonpageid($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); + + if (($edit != -1) and $PAGE->user_allowed_editing()) { + $USER->editing = $edit; + } + + /// Print the page header, heading and tabs + $PAGE->print_header(); require($CFG->dirroot.'/mod/lesson/viewstart.html'); // now starting to print the page's contents diff --git a/mod/lesson/viewend.html b/mod/lesson/viewend.html index f0b95e93c3..f2760960a2 100644 --- a/mod/lesson/viewend.html +++ b/mod/lesson/viewend.html @@ -9,10 +9,20 @@ ?> - - id, $lesson, $timer); ?> - id, $lesson); // If there is one ?> + + + 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 index ab2bdfd613..15f17dbe94 100644 --- a/mod/lesson/viewstart.html +++ b/mod/lesson/viewstart.html @@ -8,14 +8,24 @@ **/ ?> - - +
+ - + -
- id, $lesson); ?> + + + 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) { ?>