3 * Page class for lesson
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once($CFG->libdir
.'/pagelib.php');
12 require_once($CFG->dirroot
.'/course/lib.php'); // needed for some blocks
15 * Define the page types
18 define('PAGE_LESSON_VIEW', 'mod-lesson-view');
21 * Map the classes to the page types
24 page_map_class(PAGE_LESSON_VIEW
, 'page_lesson');
27 * Add the page types defined in this file
30 $DEFINEDPAGES = array(PAGE_LESSON_VIEW
);
33 * Class that models the behavior of a lesson
35 * @author Mark Nielsen (lesson extention only)
38 class page_lesson
extends page_generic_activity
{
45 var $activityname = 'lesson';
47 * Current lesson page ID
51 var $lessonpageid = NULL;
54 * Print a standard lesson heading.
56 * This will also print up to three
57 * buttons in the breadcrumb, lesson heading
58 * lesson tabs, lesson notifications and perhaps
59 * a popup with a media file.
63 function print_header($title = '', $morenavlinks = array()) {
68 /// Variable setup/check
69 $context = get_context_instance(CONTEXT_MODULE
, $this->modulerecord
->id
);
70 $activityname = format_string($this->activityrecord
->name
);
72 if ($this->lessonpageid
=== NULL) {
73 error('Programmer error: must set the lesson page ID');
76 $title = "{$this->courserecord->shortname}: $activityname";
80 $navlinks[] = array('name' => get_string('modulenameplural', $this->activityname
), 'link' => $CFG->wwwroot
."/mod/{$this->activityname}/index.php?id={$this->courserecord->id}", 'type' => 'activity');
81 $navlinks[] = array('name' => format_string($this->activityrecord
->name
), 'link' => $CFG->wwwroot
."/mod/{$this->activityname}/view.php?id={$this->modulerecord->id}", 'type' => 'activityinstance');
83 if (!empty($morenavlinks)) {
84 $navlinks = array_merge($navlinks, $morenavlinks);
89 if (has_capability('mod/lesson:edit', $context)) {
90 $buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord
->id
, $this->courserecord
->id
, get_string('modulename', 'lesson'));
92 if (!empty($this->lessonpageid
) and $this->lessonpageid
!= LESSON_EOL
) {
93 $buttons .= '<form '.$CFG->frametarget
.' method="get" action="'.$CFG->wwwroot
.'/mod/lesson/lesson.php">'.
94 '<input type="hidden" name="id" value="'.$this->modulerecord
->id
.'" />'.
95 '<input type="hidden" name="action" value="editpage" />'.
96 '<input type="hidden" name="redirect" value="navigation" />'.
97 '<input type="hidden" name="pageid" value="'.$this->lessonpageid
.'" />'.
98 '<input type="submit" value="'.get_string('editpagecontent', 'lesson').'" />'.
101 if (!empty($CFG->showblocksonmodpages
) and $this->user_allowed_editing()) {
102 if ($this->user_is_editing()) {
107 $buttons .= '<form '.$CFG->frametarget
.' method="get" action="'.$CFG->wwwroot
.'/mod/lesson/view.php">'.
108 '<input type="hidden" name="id" value="'.$this->modulerecord
->id
.'" />'.
109 '<input type="hidden" name="pageid" value="'.$this->lessonpageid
.'" />'.
110 '<input type="hidden" name="edit" value="'.$onoff.'" />'.
111 '<input type="submit" value="'.get_string("blocksedit$onoff").'" />
115 $buttons .= '</span>';
121 /// Currently broken because the $meta is printed before the JavaScript is printed
122 // if (!optional_param('pageid', 0, PARAM_INT) and !empty($this->activityrecord->mediafile)) {
123 // // open our pop-up
124 // $url = '/mod/lesson/mediafile.php?id='.$this->modulerecord->id;
125 // $name = 'lessonmediafile';
126 // $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width='. $this->activityrecord->mediawidth .',height='. $this->activityrecord->mediaheight;
127 // $meta = "\n<script type=\"text/javascript\">";
128 // $meta .= "\n<!--\n";
129 // $meta .= " openpopup('$url', '$name', '$options', 0);";
130 // $meta .= "\n// -->\n";
131 // $meta .= '</script>';
136 $navigation = build_navigation($navlinks);
138 print_header($title, $this->courserecord
->fullname
, $navigation, '', $meta, true, $buttons, navmenu($this->courserecord
, $this->modulerecord
));
140 if (has_capability('mod/lesson:manage', $context)) {
141 print_heading_with_help($activityname, 'overview', 'lesson');
143 // Rename our objects for the sake of the tab code
144 list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord
, &$this->courserecord
, &$this->activityrecord
, 'view');
145 include($CFG->dirroot
.'/mod/lesson/tabs.php');
147 print_heading($activityname);
150 lesson_print_messages();
153 function get_type() {
154 return PAGE_LESSON_VIEW
;
157 function blocks_get_positions() {
158 return array(BLOCK_POS_LEFT
, BLOCK_POS_RIGHT
);
161 function blocks_default_position() {
162 return BLOCK_POS_RIGHT
;
165 function blocks_move_position(&$instance, $move) {
166 if($instance->position
== BLOCK_POS_LEFT
&& $move == BLOCK_MOVE_RIGHT
) {
167 return BLOCK_POS_RIGHT
;
168 } else if ($instance->position
== BLOCK_POS_RIGHT
&& $move == BLOCK_MOVE_LEFT
) {
169 return BLOCK_POS_LEFT
;
171 return $instance->position
;
175 * Needed to add the ID of the current lesson page
179 function url_get_parameters() {
181 return array('id' => $this->modulerecord
->id
, 'pageid' => $this->lessonpageid
);;
185 * Set the current lesson page ID
189 function set_lessonpageid($pageid) {
190 $this->lessonpageid
= $pageid;