mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Fix for bug 2241:
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.
This commit is contained in:
parent
a9e91540df
commit
9b12850043
@ -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');
|
||||
|
@ -616,7 +616,7 @@
|
||||
// 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
|
||||
|
@ -117,7 +117,7 @@
|
||||
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 {
|
||||
|
@ -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.'&blockaction=toggle">' .
|
||||
|
@ -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');
|
||||
@ -111,11 +106,11 @@
|
||||
|
||||
// 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();
|
||||
@ -190,4 +185,4 @@
|
||||
|
||||
echo '</tr></table>';
|
||||
print_footer();
|
||||
?>
|
||||
?>
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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)) .'" />',
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -19,12 +19,60 @@
|
||||
*/
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user