]> git.mjollnir.org Git - moodle.git/commitdiff
pagelib: MDL-12212 eliminate data_lesson
authortjhunt <tjhunt>
Wed, 6 May 2009 09:31:08 +0000 (09:31 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 09:31:08 +0000 (09:31 +0000)
mod/lesson/action/continue.php
mod/lesson/lib.php
mod/lesson/locallib.php
mod/lesson/pagelib.php [deleted file]
mod/lesson/view.php

index 098d65a6df8d1604e5be422f222aae12025d9a58..ee0b10e83673d49da97259d0fd886bb104a960b4 100644 (file)
@@ -8,8 +8,6 @@
  **/
     confirm_sesskey();
 
-    require_once($CFG->dirroot.'/mod/lesson/pagelib.php');
-
     // left menu code
     // check to see if the user can see the left menu
     if (!has_capability('mod/lesson:manage', $context)) {
         lesson_set_message('('.get_string("maximumnumberofattemptsreached", "lesson").')');
     }
 
-    $PAGE = page_create_object('mod-lesson-view', $lesson->id);
     $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
-    $PAGE->set_lessonpageid($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
-    $PAGE->print_header();
+    lesson_print_header($cm, $course, $lesson, 'view', true, $page->id);
 
     include(dirname(__FILE__).'/continue.html');
 ?>
index 138fe5bb34f2c7e71b2b8b82417cdcc4026710a7..83f6d16df357fa63fc5bd070a08931673f48a548 100644 (file)
@@ -109,12 +109,6 @@ function lesson_delete_instance($id) {
             delete_event($event->id);
         }
     }
-    $pagetypes = page_import_types('mod/lesson/');
-    foreach ($pagetypes as $pagetype) {
-        if (!blocks_delete_all_on_page($pagetype, $lesson->id)) {
-            $result = false;
-        }
-    }
 
     lesson_grade_item_delete($lesson);
 
index c5b714d52acfba9628468807aa5d8f17b5c0c27d..cedadc60fe426d7ee34549e554f152bc561a6cd9 100644 (file)
@@ -215,48 +215,82 @@ if (!defined("LESSON_RESPONSE_EDITOR")) {
 /**
  * Print the standard header for lesson module
  *
- * @uses $CFG
- * @uses $USER
+ * 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.
+ *
  * @param object $cm Course module record object
- * @param object $course Couse record object
- * @param object $lesson Lesson module record object
+ * @param object $course Course record object
+ * @param object $lesson Lesson record object
  * @param string $currenttab Current tab for the lesson tabs
- * @return boolean
+ * @param boolean $extraeditbuttons Show the extra edit buttons next to the 'Update this lesson' button.
+ * @param integer $lessonpageid if $extraeditbuttons is true then you must pass the page id here.
  **/
-function lesson_print_header($cm, $course, $lesson, $currenttab = '') {
-    global $CFG, $USER;
+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');
-    $strname   = format_string($lesson->name, true, $course->id);
 
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    if (empty($title)) {
+        $title = "{$course->shortname}: $activityname";
+    }
 
+/// Build the buttons
     if (has_capability('mod/lesson:edit', $context)) {
-        $button = update_module_button($cm->id, $course->id, $strlesson);
+        $buttons = update_module_button($cm->id, $course->id, $strlesson);
+        if ($extraeditbuttons) {
+            if ($lessonpageid === NULL) {
+                print_error('invalidpageid', 'lesson');
+            }
+            if (!empty($lessonpageid) and $lessonpageid != LESSON_EOL) {
+                $buttons .= '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'.
+                            '<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="'.$lessonpageid.'" />'.
+                            '<input type="submit" value="'.get_string('editpagecontent', 'lesson').'" />'.
+                            '</form>';
+
+                if (!empty($CFG->showblocksonmodpages) and $PAGE->user_allowed_editing()) {
+                    if ($PAGE->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="'.$cm->id.'" />'.
+                                '<input type="hidden" name="pageid" value="'.$lessonpageid.'" />'.
+                                '<input type="hidden" name="edit" value="'.$onoff.'" />'.
+                                '<input type="submit" value="'.get_string("blocksedit$onoff").'" />
+                                </form>';
+                }
+            }
+            $buttons = '<span class="edit_buttons">' . $buttons  .'</span>';
+        }
     } else {
-        $button = '';
+        $buttons = '&nbsp;';
     }
 
 /// Header setup
-    $navigation = build_navigation('', $cm);
-    
-/// Print header, heading, tabs and messages
-    print_header("$course->shortname: $strname", $course->fullname, $navigation,
-                  '', '', true, $button, navmenu($course, $cm));
+    $navigation = build_navigation(array(), $cm);
+    print_header($title, $course->fullname, $navigation, '', '', true, $buttons, navmenu($course, $cm));
 
     if (has_capability('mod/lesson:manage', $context)) {
-        print_heading_with_help($strname, "overview", "lesson");
+        print_heading_with_help($activityname, 'overview', 'lesson');
 
         if (!empty($currenttab)) {
             include($CFG->dirroot.'/mod/lesson/tabs.php');
         }
     } else {
-        print_heading($strname);
+        print_heading($activityname);
     }
 
     lesson_print_messages();
-
-    return true;
 }
 
 /**
@@ -436,10 +470,10 @@ function lesson_print_time_remaining($starttime, $maxtime, $return = false) {
  **/
 function lesson_print_page_actions($cmid, $page, $printmove, $printaddpage = false, $return = false) {
     global $CFG;
-    
+
     $context = get_context_instance(CONTEXT_MODULE, $cmid);
     $actions = array();
-    
+
     if (has_capability('mod/lesson:edit', $context)) {
         if ($printmove) {
             $actions[] = "<a title=\"".get_string('move')."\" href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;action=move&amp;pageid=$page->id\">
@@ -450,10 +484,10 @@ function lesson_print_page_actions($cmid, $page, $printmove, $printaddpage = fal
         
         $actions[] = "<a title=\"".get_string('preview')."\" href=\"$CFG->wwwroot/mod/lesson/view.php?id=$cmid&amp;pageid=$page->id\">
                       <img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"".get_string('preview')."\" /></a>\n";
-        
+
         $actions[] = "<a title=\"".get_string('delete')."\" href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;sesskey=".sesskey()."&amp;action=confirmdelete&amp;pageid=$page->id\">
                       <img src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"".get_string('delete')."\" /></a>\n";
-        
+
         if ($printaddpage) {
             // Add page drop-down
             $options = array();
@@ -464,13 +498,13 @@ function lesson_print_page_actions($cmid, $page, $printmove, $printaddpage = fal
             $options['addpage']                                = get_string('question', 'lesson');
             // Base url
             $common = "$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;pageid=$page->id&amp;action=";
-        
+
             $actions[] = popup_form($common, $options, "addpage_$page->id", '', get_string('addpage', 'lesson').'...', '', '', true);
         }
     }
-    
+
     $actions = implode(' ', $actions);
-    
+
     if ($return) {
         return $actions;
     } else {
diff --git a/mod/lesson/pagelib.php b/mod/lesson/pagelib.php
deleted file mode 100644 (file)
index b1975b6..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-<?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 = '', $morenavlinks = 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) {
-            print_error('invalidpageid', 'lesson');
-        }
-        if (empty($title)) {
-            $title = "{$this->course->shortname}: $activityname";
-        }
-        
-    /// Build the buttons
-        if (has_capability('mod/lesson:edit', $context)) {
-            $buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->course->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 = '';
-        // }
-
-        $navigation = build_navigation($morenavlinks, $this->modulerecord);
-        print_header($title, $this->course->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->course, $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->course, &$this->activityrecord, 'view');
-            include($CFG->dirroot.'/mod/lesson/tabs.php');
-        } else {
-            print_heading($activityname);
-        }
-
-        lesson_print_messages();
-    }
-
-    /**
-     * Set the current lesson page ID
-     *
-     * @return void
-     **/
-    function set_lessonpageid($pageid) {
-        $this->lessonpageid = $pageid;
-    }
-}
-?>
index 44898e72e303649943365112ca8855f5bc0e0083..e3a81dcd3359ce365edd8480da461c90a3e61453 100644 (file)
@@ -7,10 +7,9 @@
  * @package lesson
  **/
 
-    require_once('../../config.php');
+    require_once(dirname(__FILE__) . '/../../config.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');
 
     $id      = required_param('id', PARAM_INT);             // Course Module ID
     $pageid  = optional_param('pageid', NULL, PARAM_INT);   // Lesson Page ID
             }
         }
 
-        $PAGE = page_create_instance($lesson->id);
         $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
-        $PAGE->set_lessonpageid($page->id);
+        $PAGE->set_subpage($page->id);
         $pageblocks = blocks_setup($PAGE);
 
         $leftcolumnwidth  = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
         }
 
     /// Print the page header, heading and tabs
-        $PAGE->print_header();
+        lesson_print_header($cm, $course, $lesson, 'view', 'true', $page->id);
 
         if ($attemptflag) {
             print_heading(get_string('attempt', 'lesson', $retries + 1));