/// very hacky page setup
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);
$PAGE->set_pagetype('admin-setting-' . $section);
+$PAGE->init_extra($section);
if (!isset($USER->adminediting)) {
$USER->adminediting = false;
page_map_class(PAGE_ADMIN, 'page_admin');
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
+ $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$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);
throw new coding_exception('Cannot call moodle_page::set_course after output has been started.');
}
+ if (!empty($this->_course->id) && $this->_course->id != $course->id) {
+ $this->_categories = null;
+ }
+
$this->_course = clone($course);
$COURSE = $this->_course;
$this->set_context(get_context_instance(CONTEXT_COURSE, $this->_course->id));
}
- $this->_categories = null;
-
moodle_setlocale();
theme_setup();
}
$this->add_body_class($this->url_to_class_name($CFG->wwwroot));
+ if ($CFG->allowcategorythemes) {
+ $this->ensure_category_loaded();
+ foreach ($this->_categories as $catid => $notused) {
+ $this->add_body_class('category-' . $catid);
+ }
+ } else {
+ $catid = 0;
+ if (is_array($this->_categories)) {
+ $catids = array_keys($this->_categories);
+ $catid = reset($catids);
+ } else if (!empty($this->_course->category)) {
+ $catid = $this->_course->category;
+ }
+ if ($catid) {
+ $this->add_body_class('category-' . $catid);
+ }
+ }
+
if (!isloggedin()) {
$this->add_body_class('notloggedin');
}
* its numeric ID. Returns a fully constructed page_base subclass you can work with.
*/
function page_create_object($type, $id = NULL) {
- global $CFG, $PAGE;
+ global $CFG, $PAGE, $SITE;
$data = new stdClass;
$data->pagetype = $type;
$classname = page_map_class($type);
$object = new $classname;
-
$object->init_quick($data);
- $object->set_course($PAGE->course);
+ $course = $PAGE->course;
+ if ($course->id != $SITE->id) {
+ $object->set_course($course);
+ } else {
+ try {
+ $category = $PAGE->category;
+ } catch (coding_exception $e) {
+ // Was not set before, so no need to try to set it again.
+ $category = false;
+ }
+ if ($category) {
+ $object->set_category_by_id($category->id);
+ } else {
+ $object->set_course($SITE);
+ }
+ }
//$object->set_pagetype($type);
return $object;
}
$this->testpage->set_category_by_id(123);
}
+ public function test_categories_array_empty_for_front_page() {
+ // Setup fixture
+ $course = $this->create_a_course();
+ $course->category = 0;
+ $this->testpage->set_context(new stdClass); // Avoid trying to set the context.
+ $this->testpage->set_course($course);
+ // Exercise SUT and validate.
+ $this->assertEqual(array(), $this->testpage->categories);
+ }
+
public function test_set_state_normal_path() {
$this->assertEqual(moodle_page::STATE_BEFORE_HEADER, $this->testpage->state);