]> git.mjollnir.org Git - moodle.git/commitdiff
Utilizing page_id_and_class(), make a factory function page_create_instance()
authordefacer <defacer>
Wed, 2 Feb 2005 02:32:40 +0000 (02:32 +0000)
committerdefacer <defacer>
Wed, 2 Feb 2005 02:32:40 +0000 (02:32 +0000)
that does not need the page type as an argument (autodetects from the URL).

lib/pagelib.php

index eee0dd9c4643971030bb6a1e4a3e022c1d37e195..c82df817542ca44db2a04692ab81440d58b52afd 100644 (file)
@@ -19,6 +19,16 @@ if(record_exists('block_instance', 'pagetype', 'course')) {
 }
 // End of dirty compatibility hack -- remove this before 1.5 goes gold
 
+/**
+ * Factory function page_create_object(). Called with a numeric ID for a page, it autodetects
+ * the page type, constructs the correct object and returns it.
+ */
+
+function page_create_instance($instance) {
+    page_id_and_class($id, $class);
+    return page_create_object($id, $instance);
+}
+
 /**
  * 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.
@@ -137,23 +147,7 @@ class page_base {
     }
 
     function construct() {
-        global $CFG, $ME;
-
-        $path = substr($ME, strlen($CFG->wwwroot) + 1);
-        $path = str_replace('.php', '', $path);
-        if (substr($path, -1) == '/') {
-            $path .= 'index';
-        }
-
-        if (empty($path)) {
-            $this->body_id    = 'index';
-            $this->body_class = 'course-view';
-        } else {
-            $this->body_id    = str_replace('/', '-', $path);
-            $classarray = explode('-', $this->body_id);
-            array_pop($classarray);
-            $this->body_class = implode('-', $classarray);
-        }
+        page_id_and_class($this->body_id, $this->body_class);
     }
 
     // USER-RELATED THINGS
@@ -178,16 +172,6 @@ class page_base {
         return;
     }
 
-    // Returns $this->body_class
-    function body_class() {
-        return $this->body_class;
-    }
-
-    // Returns $this->body_id
-    function body_id() {
-        return $this->body_id;
-    }
-
     // BLOCKS RELATED SECTION
 
     // By default, pages don't have any blocks. Override this in your derived class if you need blocks.
@@ -270,6 +254,16 @@ class page_base {
         return NULL;
     }
 
+    // Returns $this->body_class
+    function get_body_class() {
+        return $this->body_class;
+    }
+
+    // Returns $this->body_id
+    function get_body_id() {
+        return $this->body_id;
+    }
+
     // Initialize the data members of the parent class
     function init_quick($data) {
         $this->type = $data->pagetype;