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)
This commit is contained in:
mark-nielsen
2007-03-24 23:07:59 +00:00
parent 572889f194
commit 888f0c5460
10 changed files with 368 additions and 84 deletions
+29 -13
View File
@@ -8,14 +8,24 @@
?>
<!-- Primary layout table -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<table id="layout-table" cellpadding="0" cellspacing="0">
<tr>
<!-- First Column -->
<td valign="top">
<?php print_menu_block($cm->id, $lesson); ?>
<?php if (lesson_blocks_have_content($lesson, $pageblocks, BLOCK_POS_LEFT)) { ?>
<td id="left-column" style="width: <?php echo $leftcolumnwidth; ?>px;">
<?php
lesson_print_menu_block($cm->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);
}
}
?>
</td>
<?php } ?>
<!-- Start Primary column -->
<td align="center" width="100%">
<td id="middle-column">
<?php if ($lesson->displayleft) { // Skip navigation anchor ?>
@@ -30,11 +40,7 @@
}
?>
<table border="0" align="center">
<tr>
<td class="c0"><?php echo $feedback ?></td>
</tr>
</table>
<?php echo $feedback ?>
<?php if (isset($USER->modattempts[$lesson->id])) { // User is modifying attempts - save button and some instructions ?>
@@ -93,11 +99,21 @@
</form>
</td>
<!-- End primary column -->
<td>
<?php if (lesson_blocks_have_content($lesson, $pageblocks, BLOCK_POS_RIGHT)) { ?>
<td id="right-column" style="width: <?php echo $rightcolumnwidth; ?>px;">
<!-- Third column -->
<?php print_clock_block($cm->id, $lesson, $timer); ?>
<?php print_mediafile_block($cm->id, $lesson); // If there is one ?>
<?php
lesson_print_clock_block($cm->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);
}
}
?>
</td>
<?php } ?>
</tr>
</table>
<!-- End primary layout table -->
+13 -2
View File
@@ -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');
?>
+6
View File
@@ -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;
}
+59 -54
View File
@@ -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 = '<table><tr><td>'.$button.
'</td><td>'.
'<form '.$CFG->frametarget.' method="get" action="'. $CFG->wwwroot .'/mod/lesson/lesson.php">'.
'<div>'.
'<input type="hidden" name="id" value="'. $cm->id .'" />'.
'<input type="hidden" name="action" value="editpage" />'.
'<input type="hidden" name="redirect" value="navigation" />'.
'<input type="hidden" name="pageid" value="'. $pageid .'" />'.
'<input type="submit" value="'. get_string('editpagecontent', 'lesson') .'" />'.
'</div>'.
'</form>'.
'</td></tr></table>';
}
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (has_capability('mod/lesson:edit', $context)) {
$button = update_module_button($cm->id, $course->id, $strlesson);
} 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<script type=\"text/javascript\">";
$meta .= "\n<!--\n";
$meta .= " openpopup('$url', '$name', '$options', 0);";
$meta .= "\n-->\n";
$meta .= '</script>';
} 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);
print_heading(format_string($lesson->name, true));
}
if (!empty($currenttab) and has_capability('mod/lesson:manage', $context)) {
include($CFG->dirroot.'/mod/lesson/tabs.php');
}
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;
}
?>
+1 -1
View File
@@ -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;
}
}
+206
View File
@@ -0,0 +1,206 @@
<?php // $Id$
/**
* Page class for lesson
*
* @author Mark Nielsen
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package lesson
**/
require_once($CFG->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}&amp;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[] = '<a href="'.$href.'">'.$text.'</a>';
}
}
$breadcrumb = implode(' -> ', $urls);
/// Build the buttons
if (has_capability('mod/lesson:edit', $context)) {
$buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson'));
if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) {
$buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
'<input type="hidden" name="action" value="editpage" />'.
'<input type="hidden" name="redirect" value="navigation" />'.
'<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
'<input type="submit" value="'.get_string('editpagecontent', 'lesson').'" />'.
'</form>';
if (!empty($CFG->showblocksonmodpages) and $this->user_allowed_editing()) {
if ($this->user_is_editing()) {
$onoff = 'off';
} else {
$onoff = 'on';
}
$buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/view.php">'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
'<input type="hidden" name="pageid" value="'.$this->lessonpageid.'" />'.
'<input type="hidden" name="edit" value="'.$onoff.'" />'.
'<input type="submit" value="'.get_string("blocksedit$onoff").'" />
</form>';
}
}
$buttons .= '</span>';
} else {
$buttons = '&nbsp;';
}
/// 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<script type=\"text/javascript\">";
// $meta .= "\n<!--\n";
// $meta .= " openpopup('$url', '$name', '$options', 0);";
// $meta .= "\n// -->\n";
// $meta .= '</script>';
// } 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;
}
}
?>
+7 -2
View File
@@ -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 {
+19 -4
View File
@@ -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
+13 -3
View File
@@ -9,10 +9,20 @@
?>
<!-- Start view end -->
</td>
<td>
<?php print_clock_block($cm->id, $lesson, $timer); ?>
<?php print_mediafile_block($cm->id, $lesson); // If there is one ?>
<?php if (lesson_blocks_have_content($lesson, $pageblocks, BLOCK_POS_RIGHT)) { ?>
<td id="right-column" style="width: <?php echo $rightcolumnwidth; ?>px;">
<?php
lesson_print_clock_block($cm->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);
}
}
?>
</td>
<?php } ?>
</tr>
</table>
<!-- End view end -->
+15 -5
View File
@@ -8,14 +8,24 @@
**/
?>
<!-- Start view start -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<table id="layout-table" cellpadding="0" cellspacing="0">
<tr>
<!-- First Column -->
<td valign="top">
<?php print_menu_block($cm->id, $lesson); ?>
<?php if (lesson_blocks_have_content($lesson, $pageblocks, BLOCK_POS_LEFT)) { ?>
<td id="left-column" style="width: <?php echo $leftcolumnwidth; ?>px;">
<?php
lesson_print_menu_block($cm->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);
}
}
?>
</td>
<?php } ?>
<!-- Start main column -->
<td style="width:100%;" align="center">
<td id="middle-column" align="center">
<?php if ($lesson->displayleft) { ?>