From 7542a4e57438324d626b29df0ebf020ef7339d8b Mon Sep 17 00:00:00 2001 From: defacer Date: Mon, 31 Jan 2005 02:18:15 +0000 Subject: [PATCH] Dropping the use of MOODLE_PAGE_COURSE ! The new constant is PAGE_COURSE_VIEW, and it's more streamlined with the new CSS-related ids for 1.5. There are great possibilities for the future here, so we 're getting ready. On the other hand, this has to be the ugliest hack I 've ever inflicted on any program (look at pagelib.php). Thankfully it will only stay for just a little while. --- admin/site.php | 2 +- backup/backuplib.php | 2 +- backup/restorelib.php | 6 +++--- blocks/course_summary/block_course_summary.php | 2 +- blocks/db/mysql.php | 4 ++-- blocks/db/postgres7.php | 4 ++-- blocks/quiz_results/block_quiz_results.php | 2 +- blocks/quiz_results/config_instance.html | 4 ++-- blocks/rss_client/block_rss_client.php | 2 +- course/edit.php | 4 ++-- course/view.php | 2 +- index.php | 2 +- lib/blocklib.php | 4 ++-- lib/pagelib.php | 17 ++++++++++++----- 14 files changed, 32 insertions(+), 25 deletions(-) diff --git a/admin/site.php b/admin/site.php index a0959c009d..1b3e34615a 100644 --- a/admin/site.php +++ b/admin/site.php @@ -41,7 +41,7 @@ if ($newid = insert_record('course', $form)) { // Site created, add blocks for it - $page = page_create_object(MOODLE_PAGE_COURSE, $newid); + $page = page_create_object(PAGE_COURSE_VIEW, $newid); blocks_repopulate_page($page); // Return value not checked because you can always edit later $cat->name = get_string('miscellaneous'); diff --git a/backup/backuplib.php b/backup/backuplib.php index 5b36dc9b26..7187f65dd3 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -616,7 +616,7 @@ // Read all of the block table $blocks = blocks_get_record(); - $page = page_create_object(MOODLE_PAGE_COURSE, $preferences->backup_course); + $page = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course); if ($instances = blocks_get_by_page($page)) { //Blocks open tag diff --git a/backup/restorelib.php b/backup/restorelib.php index 5ff936b7ba..616e227eb3 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -590,12 +590,12 @@ $status = true; - delete_records('block_instance', 'pageid', $restore->course_id, 'pagetype', MOODLE_PAGE_COURSE); + delete_records('block_instance', 'pageid', $restore->course_id, 'pagetype', PAGE_COURSE_VIEW); if (empty($backup_block_format)) { // This is a backup from Moodle < 1.5 if (empty($blockinfo)) { echo ' (pre 1.3)'; //debug // Looks like it's from Moodle < 1.3. Let's give the course default blocks... - $newpage = page_create_object(MOODLE_PAGE_COURSE, $restore->course_id); + $newpage = page_create_object(PAGE_COURSE_VIEW, $restore->course_id); blocks_repopulate_page($newpage); } else { echo ' (1.3-1.4)'; //debug @@ -622,7 +622,7 @@ } $blockinstance->blockid = $blockrecords[$blockname]->id; $blockinstance->pageid = $restore->course_id; - $blockinstance->pagetype = MOODLE_PAGE_COURSE; + $blockinstance->pagetype = PAGE_COURSE_VIEW; $blockinstance->position = $blockposition; $blockinstance->weight = $blockweight; if(!$status = insert_record('block_instance', $blockinstance)) { diff --git a/blocks/course_summary/block_course_summary.php b/blocks/course_summary/block_course_summary.php index d0b20a2581..fc4ed93f0c 100644 --- a/blocks/course_summary/block_course_summary.php +++ b/blocks/course_summary/block_course_summary.php @@ -8,7 +8,7 @@ class block_course_summary extends block_base { } function specialization() { - if($this->instance->pagetype == MOODLE_PAGE_COURSE && $this->instance->pageid != SITEID) { + if($this->instance->pagetype == PAGE_COURSE_VIEW && $this->instance->pageid != SITEID) { $this->title = get_string('coursesummary', 'block_course_summary'); } } diff --git a/blocks/db/mysql.php b/blocks/db/mysql.php index 2123123d98..efa69b947f 100644 --- a/blocks/db/mysql.php +++ b/blocks/db/mysql.php @@ -93,7 +93,7 @@ global $CFG; $instance = new stdClass; $instance->blockid = abs($blk); $instance->pageid = $thiscourse->id; - $instance->pagetype = MOODLE_PAGE_COURSE; + $instance->pagetype = PAGE_COURSE_VIEW; $instance->position = BLOCK_POS_LEFT; $instance->weight = $weight; $instance->visible = ($blk > 0) ? 1 : 0; @@ -107,7 +107,7 @@ global $CFG; $instance = new stdClass; $instance->blockid = abs($blk); $instance->pageid = $thiscourse->id; - $instance->pagetype = MOODLE_PAGE_COURSE; + $instance->pagetype = PAGE_COURSE_VIEW; $instance->position = BLOCK_POS_RIGHT; $instance->weight = $weight; $instance->visible = ($blk > 0) ? 1 : 0; diff --git a/blocks/db/postgres7.php b/blocks/db/postgres7.php index ec0acfac97..bb730778c3 100644 --- a/blocks/db/postgres7.php +++ b/blocks/db/postgres7.php @@ -91,7 +91,7 @@ global $CFG; $instance = new stdClass; $instance->blockid = abs($blk); $instance->pageid = $thiscourse->id; - $instance->pagetype = MOODLE_PAGE_COURSE; + $instance->pagetype = PAGE_COURSE_VIEW; $instance->position = BLOCK_POS_LEFT; $instance->weight = $weight; $instance->visible = ($blk > 0) ? 1 : 0; @@ -105,7 +105,7 @@ global $CFG; $instance = new stdClass; $instance->blockid = abs($blk); $instance->pageid = $thiscourse->id; - $instance->pagetype = MOODLE_PAGE_COURSE; + $instance->pagetype = PAGE_COURSE_VIEW; $instance->position = BLOCK_POS_RIGHT; $instance->weight = $weight; $instance->visible = ($blk > 0) ? 1 : 0; diff --git a/blocks/quiz_results/block_quiz_results.php b/blocks/quiz_results/block_quiz_results.php index dc11b116fd..4804811856 100644 --- a/blocks/quiz_results/block_quiz_results.php +++ b/blocks/quiz_results/block_quiz_results.php @@ -26,7 +26,7 @@ class block_quiz_results extends block_base { $this->content->text = ''; $this->content->footer = ''; - if($this->instance->pagetype == MOODLE_PAGE_COURSE) { + if($this->instance->pagetype == PAGE_COURSE_VIEW) { // We need to see if we are monitoring a quiz $quizid = empty($this->config->quizid) ? 0 : $this->config->quizid; $courseid = $this->instance->pageid; diff --git a/blocks/quiz_results/config_instance.html b/blocks/quiz_results/config_instance.html index 14d8f87638..264f936f8e 100644 --- a/blocks/quiz_results/config_instance.html +++ b/blocks/quiz_results/config_instance.html @@ -1,5 +1,5 @@ -instance->pagetype == MOODLE_PAGE_COURSE) { ?> +instance->pagetype == PAGE_COURSE_VIEW) { ?> -instance->pagetype == MOODLE_PAGE_COURSE) ?> +instance->pagetype == PAGE_COURSE_VIEW) ?>
@@ -21,7 +21,7 @@ ?>
diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index f783f9a3d0..67df87edd5 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -70,7 +70,7 @@ class block_rss_client extends block_base { $isteacher = false; $courseid = ''; - if ($this->instance->pagetype == MOODLE_PAGE_COURSE) { + if ($this->instance->pagetype == PAGE_COURSE_VIEW) { $isteacher = isteacher($this->instance->pageid); $courseid = $this->instance->pageid; } diff --git a/course/edit.php b/course/edit.php index 02a8564262..c305a091cb 100644 --- a/course/edit.php +++ b/course/edit.php @@ -70,7 +70,7 @@ if (!empty($course)) { // Test for and remove blocks which aren't appropriate anymore - $page = page_create_object(MOODLE_PAGE_COURSE, $course->id); + $page = page_create_object(PAGE_COURSE_VIEW, $course->id); blocks_remove_inappropriate($page); // Update with the new data @@ -91,7 +91,7 @@ if ($newcourseid = insert_record('course', $form)) { // Set up new course // Setup the blocks - $page = page_create_object(MOODLE_PAGE_COURSE, $newcourseid); + $page = page_create_object(PAGE_COURSE_VIEW, $newcourseid); blocks_repopulate_page($page); // Return value not checked because you can always edit later $section = NULL; diff --git a/course/view.php b/course/view.php index 58bd86073d..759b637472 100644 --- a/course/view.php +++ b/course/view.php @@ -37,7 +37,7 @@ $course->format = 'weeks'; // Default format is weeks } - $PAGE = page_create_object(MOODLE_PAGE_COURSE, $course->id); + $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); $pageblocks = blocks_get_by_page($PAGE); if (!isset($USER->editing)) { diff --git a/index.php b/index.php index 82b5161f5f..48dfcfa848 100644 --- a/index.php +++ b/index.php @@ -56,7 +56,7 @@ $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true); } - $PAGE = page_create_object(MOODLE_PAGE_COURSE, SITEID); + $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID); $editing = $PAGE->user_is_editing(); diff --git a/lib/blocklib.php b/lib/blocklib.php index 2a8d2f3ccc..3938d9b716 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -854,14 +854,14 @@ function upgrade_blocks_plugins($continueto) { //Iterate over each course if ($courses = get_records('course')) { foreach ($courses as $course) { - $page = page_create_object(MOODLE_PAGE_COURSE, $course->id); + $page = page_create_object(PAGE_COURSE_VIEW, $course->id); blocks_repopulate_page($page); } } } if (!empty($CFG->siteblocksadded)) { /// This is a once-off hack to make a proper upgrade - $page = page_create_object(MOODLE_PAGE_COURSE, SITEID); + $page = page_create_object(PAGE_COURSE_VIEW, SITEID); blocks_repopulate_page($page); delete_records('config', 'name', 'siteblocksadded'); } diff --git a/lib/pagelib.php b/lib/pagelib.php index 1c30ed9349..b65afbb52f 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -12,12 +12,19 @@ * @package pages */ + +// Start of dirty compatibility hack -- this will be here for a couple of weeks +if(record_exists('block_instance', 'pagetype', 'course')) { + execute_sql('UPDATE '.$GLOBALS['CFG']->prefix.'block_instance SET pagetype = \'course-view\' WHERE pagetype = \'course\'', false); +} +// End of dirty compatibility hack -- remove this before 1.5 goes gold + /// Constants /** * Definition of course page type. */ -define('MOODLE_PAGE_COURSE', 'course'); +define('PAGE_COURSE_VIEW', 'course-view'); /** * Factory function page_create_object(). Called with a pagetype identifier and possibly with @@ -59,7 +66,7 @@ function page_map_class($type, $classname = NULL) { if ($mappings === NULL) { $mappings = array( - MOODLE_PAGE_COURSE => 'page_course' + PAGE_COURSE_VIEW => 'page_course' ); } @@ -385,11 +392,11 @@ class page_course extends page_base { // 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; + return PAGE_COURSE_VIEW; } - // This is like the "category" of a page of this "type". For example, if the type is MOODLE_PAGE_COURSE - // the format_name is the actual name of the course format. If the type were MOODLE_PAGE_ACTIVITY, then + // 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. function get_format_name() { $this->init_full(); -- 2.39.5