]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for bug 2241:
authordefacer <defacer>
Mon, 29 Nov 2004 04:19:05 +0000 (04:19 +0000)
committerdefacer <defacer>
Mon, 29 Nov 2004 04:19:05 +0000 (04:19 +0000)
I hope this time I got everything changed to the new Page interface! I 'm
really sorry for messing up and breaking new installations... :(

Also moved the only two functions of the API outside the page_base class.

admin/site.php
backup/backuplib.php
backup/restore_execute.html
blocks/moodleblock.class.php
blocks/pagedemo.php
course/edit.php
course/view.php
index.php
lib/blocklib.php
lib/pagelib.php

index 4c0dfc68f5a6de78615c2f866f51aaf1ddf96418..f1b20bb92f9cf9c7acb687ce34c836a02994007d 100644 (file)
@@ -41,7 +41,7 @@
                 if ($newid = insert_record('course', $form)) {
 
                     // Site created, add blocks for it
-                    $page = page_base::create_object(MOODLE_PAGE_COURSE, $newid);
+                    $page = page_create_object(MOODLE_PAGE_COURSE, $newid);
                     blocks_repopulate_page($page); // Return value not checked because you can always edit later
 
                     $cat->name = get_string('miscellaneous');
index 339a6fce8ace303efeeccf04530882c515a6e2c7..e6fa4f617674127f42ba3385cb0a6106f96c6f45 100644 (file)
         // Read all of the block table
         $blocks = blocks_get_record();
 
-        $page = MoodlePage::create_object(MOODLE_PAGE_COURSE, $preferences->backup_course);
+        $page = page_create_object(MOODLE_PAGE_COURSE, $preferences->backup_course);
 
         if ($instances = blocks_get_by_page($page)) {
             //Blocks open tag
index cb5e8fc7f0c555154dad0705fc3d9902b6978938..768d026535665fec6fda391e2e802bb7b4cfd6dc 100644 (file)
             if (empty($info->backup_block_format)) {     // This is a backup from Moodle < 1.5
                 if (empty($course_header->blockinfo)) {
                     // Looks like it's from Moodle < 1.3. Let's give the course default blocks...
-                    $newpage = MoodlePage::create_object(MOODLE_PAGE_COURSE, $course_header->course_id);
+                    $newpage = page_create_object(MOODLE_PAGE_COURSE, $course_header->course_id);
                     blocks_repopulate_page($newpage);
 
                 } else {
index 983ad472f22463755b194c7090c92dcbda8004bd..82022f8860e3b8a5b4daec332873c81fd0e94c80 100644 (file)
@@ -296,7 +296,7 @@ class block_base {
             $title = $this->str->show;
         }
 
-        $page   = page_base::create_object($this->instance->pagetype, $this->instance->pageid);
+        $page   = page_create_object($this->instance->pagetype, $this->instance->pageid);
         $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey));
      
         $movebuttons .= '<a style="margin-right: 6px; margin-left: 2px;" title="'. $title .'" href="'.$script.'&amp;blockaction=toggle">' .
index 27d837eb71c144d26a84f10ac6737adb11c1b864..ada8efc7c61b356184f7c295a2d82f93f4cc6f7e 100644 (file)
@@ -2,12 +2,7 @@
 
     // All of this is standard Moodle fixtures
 
-    if (!file_exists('./config.php')) {
-        header('Location: install.php');
-        die;
-    }
-
-    require_once('config.php');
+    require_once('../config.php');
     require_once($CFG->dirroot .'/course/lib.php');
     require_once($CFG->dirroot .'/lib/blocklib.php');
     require_once($CFG->dirroot .'/mod/resource/lib.php');
 
     // Before creating our page object, we need to map our page identifier to the actual name
     // of the class which will be handling its operations. Pretty simple, but essential.
-    MoodlePage::map_page_type(MOODLE_PAGE_TEST, 'MoodlePage_Test');
+    page_map_class(MOODLE_PAGE_TEST, 'page_test');
 
     // Now, create our page object. The identifier "1" is passed arbitrarily because we don't
     // have multiple "testpages"; if we did, that would be the "testpageid" from the database.
-    $PAGE = MoodlePage::create_object(MOODLE_PAGE_TEST, 1);
+    $PAGE = page_create_object(MOODLE_PAGE_TEST, 1);
 
     $PAGE->print_header(NULL);
     $editing = $PAGE->user_is_editing();
 
     echo '</tr></table>';
     print_footer();
-?>
\ No newline at end of file
+?>
index 2ba4f4b7766fbf0e67d8d875f981f49ebb2a2943..42d2c472f1d23cb7f5965bcc13f2dec944b1a9b6 100644 (file)
@@ -52,7 +52,7 @@
 
             if (!empty($course)) {
                 // Test for and remove blocks which aren't appropriate anymore
-                $page = MoodlePage::create_object(MOODLE_PAGE_COURSE, $course->id);
+                $page = page_create_object(MOODLE_PAGE_COURSE, $course->id);
                 blocks_remove_inappropriate($page);
 
                 // Update with the new data
@@ -69,7 +69,7 @@
                 if ($newcourseid = insert_record('course', $form)) {  // Set up new course
                     
                     // Setup the blocks
-                    $page = MoodlePage::create_object(MOODLE_PAGE_COURSE, $newcourseid);
+                    $page = page_create_object(MOODLE_PAGE_COURSE, $newcourseid);
                     blocks_repopulate_page($page); // Return value not checked because you can always edit later
 
                     $section = NULL;
index 087339d8c26ec020b70bbecc1ab8854648f8637e..6c2986a108308d277c19dba6589df614b6c5a565 100644 (file)
@@ -37,7 +37,7 @@
         $course->format = 'weeks';  // Default format is weeks
     }
 
-    $PAGE = page_base::create_object(MOODLE_PAGE_COURSE, $course->id);
+    $PAGE = page_create_object(MOODLE_PAGE_COURSE, $course->id);
     $pageblocks = blocks_get_by_page($PAGE);
    
     if (!isset($USER->editing)) {
index 5f566c9109f3df521634eccd6f95f9397a7bfe7f..23cff164c4e9b9db953dd851de6571fa89622ab2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -55,7 +55,7 @@
         $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
     }
 
-    $PAGE = page_base::create_object(MOODLE_PAGE_COURSE, SITEID);
+    $PAGE = page_create_object(MOODLE_PAGE_COURSE, SITEID);
 
     print_header(strip_tags($site->fullname), $site->fullname, 'home', '',
                  '<meta name="description" content="'. s(strip_tags($site->summary)) .'" />',
index 3d26dee807366919783fa33b3aa079adeff25443..2467b1cc85e5d2c84395dc81e5e398781183b7a8 100644 (file)
@@ -845,14 +845,14 @@ function upgrade_blocks_plugins($continueto) {
         //Iterate over each course
         if ($courses = get_records('course')) {
             foreach ($courses as $course) {
-                $page = MoodlePage::create_object(MOODLE_PAGE_COURSE, $course->id);
+                $page = page_create_object(MOODLE_PAGE_COURSE, $course->id);
                 blocks_repopulate_page($page);
             }
         }
     }
 
     if (!empty($CFG->siteblocksadded)) {     /// This is a once-off hack to make a proper upgrade
-        $page = MoodlePage::create_object(MOODLE_PAGE_COURSE, SITEID);
+        $page = page_create_object(MOODLE_PAGE_COURSE, SITEID);
         blocks_repopulate_page($page);
         delete_records('config', 'name', 'siteblocksadded');
     }
index dab25f916bc9ff6bf8ca13f31b99ce2a0057bfa0..e032d3815e4bcd26b2a53652f237c31c32438e29 100644 (file)
  */
 define('MOODLE_PAGE_COURSE',    'course');
 
+/**
+ * Factory function page_create_object(). Called with a pagetype identifier and possibly with
+ * its numeric ID. Returns a fully constructed page_base subclass you can work with.
+ */
+
+function page_create_object($type, $id = NULL) {
+    $data = new stdClass;
+    $data->pagetype = $type;
+    $data->pageid   = $id;
+
+    $classname = page_map_class($type);
+
+    $object = &new $classname;
+    // TODO: subclassing check here
+
+    if($object->get_type() !== $type) {
+        // Somehow somewhere someone made a mistake
+        error('Page object\'s type ('. $object->get_type() .') does not match requested type ('. $type .')');
+    }
+
+    $object->init_quick($data);
+    return $object;
+}
+
+/**
+ * Function page_map_type() is the way for your code to define its own page subclasses and let Moodle recognize them.
+ * Use it to associate the textual identifier of your Page with the actual class name that has to be instantiated.
+ */
+
+function page_map_class($type, $classname = NULL) {
+    static $mappings = array(
+        MOODLE_PAGE_COURSE => 'page_course'
+    );
+
+    if(!empty($type) && !empty($classname)) {
+        $mappings[$type] = $classname;
+    }
+    if(!isset($mappings[$type])) {
+        error('Page class mapping requested for unknown type: '.$type);
+    }
+
+    if(!class_exists($mappings[$type])) {
+        error('Page class mapping for id "'.$type.'" exists but class "'.$mappings[$type].'" is not defined');
+    }
+
+    return $mappings[$type];
+}
+
 /**
  * Parent class from which all Moodle page classes derive
  *
  * @author Jon Papaioannou
  * @package pages
- * @todo This parent class is very messy still. Please for the moment ignore it [except maybe create_object()] and move on to the derived class page_course to see the comments there.
+ * @todo This parent class is very messy still. Please for the moment ignore it and move on to the derived class page_course to see the comments there.
  */
 
 class page_base {
@@ -161,52 +209,6 @@ class page_base {
     function init_full() {
         $this->full_init_done = true;
     }
-
-    // DO NOT TOUCH! NEVER! SECTION
-
-    // Factory method page_base::create_object(). Called with a pagetype identifier and possibly with
-    // its numeric ID. Returns a fully constructed page_base subclass you can work with.
-    function create_object($type, $id = NULL) {
-
-        $data = new stdClass;
-        $data->pagetype = $type;
-        $data->pageid   = $id;
-
-        $classname = page_base::map_page_type($type);
-
-        $object = &new $classname;
-        // TODO: subclassing check here
-
-        if($object->get_type() !== $type) {
-            // Somehow somewhere someone made a mistake
-            error('Page object\'s type ('. $object->get_type() .') does not match requested type ('. $type .')');
-        }
-
-        $object->init_quick($data);
-        return $object;
-    }
-
-    // Method map_page_type() is the way for your code to define its own Page subclasses and let Moodle recognize them.
-    // Use it to associate the textual identifier of your Page with the actual class name that has to be instantiated.
-    function map_page_type($type, $classname = NULL) {
-        static $mappings = array(
-            MOODLE_PAGE_COURSE => 'page_course'
-        );
-
-        if(!empty($type) && !empty($classname)) {
-            $mappings[$type] = $classname;
-        }
-        if(!isset($mappings[$type])) {
-            error('Page class mapping requested for unknown type: '.$type);
-        }
-
-        if(!class_exists($mappings[$type])) {
-            error('Page class mapping for id "'.$type.'" exists but class "'.$mappings[$type].'" is not defined');
-        }
-
-        return $mappings[$type];
-    }
-
 }
 
 
@@ -283,7 +285,7 @@ class page_course extends page_base {
 
     // SELF-REPORTING SECTION
 
-    // This is hardwired here so the factory method create_object() can be sure there was no mistake.
+    // This is hardwired here so the factory function page_create_object() can be sure there was no mistake.
     // Also, it doubles as a way to let others inquire about our type.
     function get_type() {
         return MOODLE_PAGE_COURSE;