From 1d00ec6a6a785989385e872f527e34e9851de978 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 8 May 2009 03:11:24 +0000 Subject: [PATCH] blocklib: MDL-19010 finally fix the regressions that mean that you could not create a new course. --- course/lib.php | 3 +-- lib/adminlib.php | 3 +++ lib/blocklib.php | 23 ++++++++++++++++------- theme/standard/styles_layout.css | 24 ++++++++++++------------ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/course/lib.php b/course/lib.php index 82a5044172..8ab86c2ecc 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3536,8 +3536,7 @@ function create_course($data) { $course = $DB->get_record('course', array('id'=>$newcourseid)); // Setup the blocks - $page = page_create_object(PAGE_COURSE_VIEW, $course->id); - blocks_repopulate_page($page); // Return value not checked because you can always edit later + blocks_add_default_course_blocks($course); update_restricted_mods($course, $allowedmods); diff --git a/lib/adminlib.php b/lib/adminlib.php index 59e74f23e2..c944bea9d9 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3913,6 +3913,9 @@ function admin_externalpage_setup($section, $extrabutton = '', } $PAGE->set_url(str_replace($CFG->wwwroot . '/', '', $actualurl), array_merge($extraurlparams, array('section' => $section))); + if (strpos($PAGE->pagetype, 'admin-') !== 0) { + $PAGE->set_pagetype('admin-' . $PAGE->pagetype); + } if (empty($extpage) or !($extpage instanceof admin_externalpage)) { print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); diff --git a/lib/blocklib.php b/lib/blocklib.php index ceeba07b68..a2d3876a81 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -54,8 +54,20 @@ require_once($CFG->libdir.'/pagelib.php'); * only at the point that the load_blocks() method is called. It is the caller's * responsibility to ensure that those fields do not subsequently change. * - * The implements ArrayAccess is a horrible backwards_compatibility thing. - * TODO explain! + * + * Note about the weird 'implements ArrayAccess' part of the declaration: + * + * ArrayAccess is a magic PHP5 thing. If your class implements the ArrayAccess + * interface, then other code can use the $object[$index] syntax, and it will + * call the offsetGet method of the object. + * See http://php.net/manual/en/class.arrayaccess.php + * + * So, why do we do this here? Basically, some of the deprecated blocks methods + * like blocks_setup used to return an array of blocks on the page, with array + * keys BLOCK_POS_LEFT, BLOCK_POS_RIGHT. We can keep legacy code that calls those + * deprecated functions mostly working by changing blocks_setup to return the + * block_manger object, and then use 'implements ArrayAccess' so that the right + * thing happens when legacy code does something like $pageblocks[BLOCK_POS_LEFT]. */ class block_manager implements ArrayAccess { @@ -1355,8 +1367,8 @@ function blocks_add_default_course_blocks($course) { $blocknames = blocks_parse_default_blocks_list($CFG->$defaultblocks); } else { - $formatconfig = $CFG->dirroot.'/course/format/'.$pageformat.'/config.php'; - if (file_exists_and_readable($formatconfig)) { + $formatconfig = $CFG->dirroot.'/course/format/'.$course->format.'/config.php'; + if (is_readable($formatconfig)) { require($formatconfig); } if (!empty($format['defaultblocks'])) { @@ -1382,9 +1394,6 @@ function blocks_add_default_course_blocks($course) { $page = new moodle_page(); $page->set_course($course); - print_object($page); // DONOTCOMMIT - print_object($pagetypepattern); // DONOTCOMMIT - print_object($blocknames); // DONOTCOMMIT $page->blocks->add_blocks($blocknames, $pagetypepattern); } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index b8515af3a1..19bbd9afed 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2305,46 +2305,46 @@ body#course-index .courseboxes { padding:20px; } -body#course-category .rolelink { +body#admin-course-category .rolelink { text-align:right; padding:10px; } -body#course-category .addcategory { +body#admin-course-category .addcategory { text-align: center; padding: 10px; } -body#course-index .buttons .singlebutton, -body#course-category .buttons .singlebutton { +body#admin-course-index .buttons .singlebutton, +body#admin-course-category .buttons .singlebutton { display: inline; } -body#course-index .buttons, -body#course-category .buttons { +body#admin-course-index .buttons, +body#admin-course-category .buttons { text-align: center; margin-bottom: 15px; } -body#course-index #middle-column .editcourse { +body#admin-course-index #middle-column .editcourse { margin-left:auto; margin-right:auto; margin-top:20px; margin-bottom:20px; } -body#course-index #middle-column .editcourse th, -body#course-index #middle-column .editcourse td { +body#admin-course-index #middle-column .editcourse th, +body#admin-course-index #middle-column .editcourse td { padding-left:10px; padding-right:10px; } -body#course-index #middle-column .editcourse .count { +body#admin-course-index #middle-column .editcourse .count { text-align:right; } -body#course-index .singlebutton, -body#course-index .addcategory { +body#admin-course-index .singlebutton, +body#admin-course-index .addcategory { text-align: center; } -- 2.39.5