print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, '');
}
-
- function get_type() {
- return PAGE_ADMIN;
- }
}
?>
/// no guest autologin
require_login(0, false);
+$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$adminroot = admin_get_root(); // need all settings
$page = $adminroot->locate($section);
var $filterselect = NULL;
var $tagid = NULL;
- // Mandatory; should return our identifier.
- function get_type() {
- global $CFG;
- require_once($CFG->dirroot .'/blog/lib.php');
- return PAGE_BLOG_VIEW;
- }
-
// we have no format type, use 'blog'
//I think it's a bug, but if this is left the default NULL value then pages can
//fail to load completely
$this->init_full();
// It's a normal blog page
- if (!empty($CFG->{'defaultblocks_'. $this->get_type()})) {
- $blocknames = $CFG->{'defaultblocks_'. $this->get_type()};
+ if (!empty($CFG->{'defaultblocks_'. $this->pagetype})) {
+ $blocknames = $CFG->{'defaultblocks_'. $this->pagetype};
} else {
/// Failsafe - in case nothing was defined.
$blocknames = 'admin,calendar_month,online_users,blog_menu';
die;
}
+ page_map_class(PAGE_ADMIN, 'page_admin');
+ $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
+ $PAGE->init_extra($section); // hack alert!
+ $PAGE->set_extra_button($extrabutton);
+ $PAGE->set_extra_url_params($extraurlparams, $actualurl);
+ $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
+
$adminroot = admin_get_root(false, false); // settings not required for external pages
$extpage = $adminroot->locate($section);
die;
}
- page_map_class(PAGE_ADMIN, 'page_admin');
- $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
- $PAGE->init_extra($section); // hack alert!
- $PAGE->set_extra_button($extrabutton);
- $PAGE->set_extra_url_params($extraurlparams, $actualurl);
-
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
if (!isset($USER->adminediting)) {
$sql = "SELECT 1, MAX(weight) + 1 AS nextfree
FROM {block_pinned}
WHERE pagetype = ? AND position = ?";
- $params = array($page->get_type(), $newpos);
+ $params = array($page->pagetype, $newpos);
} else {
$sql = "SELECT 1, MAX(weight) + 1 AS nextfree
FROM {block_instance}
WHERE pageid = ? AND pagetype = ? AND position = ?";
- $params = array($page->get_id(), $page->get_type(), $newpos);
+ $params = array($page->get_id(), $page->pagetype, $newpos);
}
$weight = $DB->get_record_sql($sql, $params);
if (empty($pinned)) {
$newinstance->pageid = $page->get_id();
}
- $newinstance->pagetype = $page->get_type();
+ $newinstance->pagetype = $page->pagetype;
$newinstance->position = $newpos;
$newinstance->weight = empty($weight->nextfree) ? 0 : $weight->nextfree;
$newinstance->visible = 1;
}
$select = "pagetype = ?";
- $params = array($page->get_type());
+ $params = array($page->pagetype);
if ($visible) {
$select .= " AND visible = 1";
function blocks_get_by_page($page) {
global $DB;
- $blocks = $DB->get_records_select('block_instance', "pageid = ? AND pagetype = ?", array($page->get_id(), $page->get_type()),
- 'position, weight');
+ $blocks = $DB->get_records_select('block_instance', "pageid = ? AND pagetype = ?",
+ array($page->get_id(), $page->pagetype), 'position, weight');
$positions = $page->blocks_get_positions();
$arr = array();
// indexed and the indexes match, so we can work straight away... but CAREFULLY!
// Ready to start creating block instances, but first drop any existing ones
- blocks_delete_all_on_page($page->get_type(), $page->get_id());
+ blocks_delete_all_on_page($page->pagetype, $page->get_id());
// Here we slyly count $posblocks and NOT $positions. This can actually make a difference
// if the textual representation has undefined slots in the end. So we only work with as many
$newinstance = new stdClass;
$newinstance->blockid = $idforname[$blockname];
$newinstance->pageid = $page->get_id();
- $newinstance->pagetype = $page->get_type();
+ $newinstance->pagetype = $page->pagetype;
$newinstance->position = $position;
$newinstance->weight = $weight;
$newinstance->visible = 1;
protected $_context = null;
+ protected $_pagetype = null;
+
/**
* @return integer one of the STATE_... constants. You should not normally need
* to use this in your code. It is indended for internal use by this class
return $this->_context;
}
+ /**
+ * @return string e.g. 'my-index' or 'mod-quiz-attempt'. Same as the id attribute on <body>.
+ */
+ public function get_pagetype() {
+ if (is_null($this->_pagetype)) {
+ throw new coding_exception('$PAGE->pagetype accessed before it was known.');
+ }
+ return $this->_pagetype;
+ }
+
/**
* Set the state. The state must be one of that STATE_... constants, and
* the state is only allowed to advance one step at a time.
$this->_context = $context;
}
+ /**
+ * @param string $pagetype e.g. 'my-index' or 'mod-quiz-attempt'. Normally
+ * you do not need to set this manually, it is automatically created from the
+ * script name. However, on some pages this is overridden. For example, the
+ * page type for coures/view.php includes the course format, for example
+ * 'coures-view-weeks'. This gets used as the id attribute on <body> and
+ * also for determining which blocks are displayed.
+ */
+ public function set_pagetype($pagetype) {
+ $this->_pagetype = $pagetype;
+ }
+
/**
* PHP overloading magic to make the $PAGE->course syntax work.
*/
throw new coding_exception('Unknown field ' . $field . ' of $PAGE.');
}
}
+
+/// Deperecated fields and methods for backwards compatibility =================
+ /**
+ * @deprecated since Moodle 2.0 - use $PAGE->pagetype instaed.
+ * @return string page type.
+ */
+ public function get_type() {
+ debugging('Call to deprecated method moodle_page::get_type. Please use $PAGE->pagetype instead.');
+ return $this->get_pagetype();
+ }
}
/**
$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
- debugging('Page object\'s type ('. $object->get_type() .') does not match requested type ('. $type .')');
- }
$object->init_quick($data);
$object->set_course($PAGE->course);
+ $object->set_pagetype($type);
return $object;
}
return $path;
}
- // This forces implementers to actually hardwire their page identification constant in the class.
- // Good thing, if you ask me. That way we can later auto-detect "installed" page types by querying
- // the classes themselves in the future.
- function get_type() {
- trigger_error('Page class does not implement method <strong>get_type()</strong>', E_USER_ERROR);
- return NULL;
- }
-
// Simple stuff, do not override this.
function get_id() {
return $this->id;
// SELF-REPORTING SECTION
- // 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 PAGE_COURSE_VIEW;
- }
-
// This is like the "category" of a page of this "type". For example, if the type is PAGE_COURSE_VIEW
// the format_name is the actual name of the course format. If the type were PAGE_ACTIVITY_VIEW, then
// the format_name might be that activity's name etc.
// Validate
$this->assert(new CheckSpecifiedFieldsExpectation($context), $this->testpage->context);
}
+
+ public function test_cant_get_pagetype_before_set() {
+ // Set expectation.
+ $this->expectException();
+ // Exercise SUT
+ $this->testpage->pagetype;
+ }
+
+ public function test_set_pagetype() {
+ // Exercise SUT
+ $this->testpage->set_pagetype('a-page-type');
+ // Validate
+ $this->assertEqual('a-page-type', $this->testpage->pagetype);
+ }
}
/**
$this->activityname = 'chat';
parent::init_quick($data);
}
-
- function get_type() {
- return PAGE_CHAT_VIEW;
- }
}
?>
function print_header($title, $morenavlinks = NULL, $meta) {
parent::print_header($title, $morenavlinks, '', $meta);
}
-
- function get_type() {
- return PAGE_DATA_VIEW;
- }
}
?>
lesson_print_messages();
}
- function get_type() {
- return PAGE_LESSON_VIEW;
- }
-
function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}
$this->activityname = 'quiz';
parent::init_quick($data);
}
-
- function get_type() {
- return PAGE_QUIZ_VIEW;
- }
}
?>
class page_my_moodle extends page_base {
- function get_type() {
- return PAGE_MY_MOODLE;
- }
-
function user_allowed_editing() {
page_id_and_class($id,$class);
if ($id == PAGE_MY_MOODLE) {
class page_tag extends page_base {
var $tag_object = NULL;
-
- function get_type() {
- return PAGE_TAG_INDEX;
- }
function user_allowed_editing() {
$systemcontext = get_context_instance(CONTEXT_SYSTEM);