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');
// 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
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 {
$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.'&blockaction=toggle">' .
// 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
+?>
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
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;
$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)) {
$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)) .'" />',
//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');
}
*/
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 {
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];
- }
-
}
// 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;