From 31940ba6228cd9ca28c2ef36736aaa894868dd4f Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 6 May 2009 08:35:39 +0000 Subject: [PATCH] moodle_page: MDL-12212 remove code in legacy page types that stores a course record --- blog/blogpage.php | 11 ++-------- blog/header.php | 2 +- lib/pagelib.php | 47 ++++++++++++++++-------------------------- mod/lesson/pagelib.php | 8 +++---- 4 files changed, 25 insertions(+), 43 deletions(-) diff --git a/blog/blogpage.php b/blog/blogpage.php index f246bf1cee..43839a9dfe 100644 --- a/blog/blogpage.php +++ b/blog/blogpage.php @@ -13,8 +13,6 @@ define('PAGE_BLOG_VIEW', 'blog-view'); class page_blog extends page_base { var $editing = false; - var $courserecord = NULL; - var $courseid = NULL; var $filtertype = NULL; var $filterselect = NULL; var $tagid = NULL; @@ -55,11 +53,6 @@ class page_blog extends page_base { if ($this->courseid == 0 || $this->courseid == 1 || !is_numeric($this->courseid) ) { $this->courseid = ''; - $courserecord = NULL; - } else { - if (! ($courserecord = $DB->get_record('course', array('id'=>$this->courseid))) ) { - print_error('invalidcourseid', 'error', '', $this->courseid); - } } $this->full_init_done = true; } @@ -111,8 +104,8 @@ class page_blog extends page_base { return $array; } - if (!empty($this->courseid)) { - $array['courseid'] = $this->courseid; + if (!empty($this->course->id)) { + $array['courseid'] = $this->course->id; } if (!empty($this->filtertype)) { $array['filtertype'] = $this->filtertype; diff --git a/blog/header.php b/blog/header.php index 58b0d23f85..e6474bffb5 100755 --- a/blog/header.php +++ b/blog/header.php @@ -46,7 +46,7 @@ if (empty($USER->id)) { } else { $PAGE = page_create_object($pagetype, $USER->id); } -$PAGE->courseid = $courseid; +$PAGE->set_course($course); $PAGE->filtertype = $filtertype; $PAGE->filterselect = $filterselect; $PAGE->tagid = $tagid; diff --git a/lib/pagelib.php b/lib/pagelib.php index 697bccb999..8874eebdf5 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -195,13 +195,21 @@ class moodle_page { /// Deperecated fields and methods for backwards compatibility ================= /** - * @deprecated since Moodle 2.0 - use $PAGE->pagetype instaed. + * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead. * @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(); } + /** + * @deprecated since Moodle 2.0 - use $PAGE->course instead. + * @return object course. + */ + public function get_courserecord() { + debugging('Call to deprecated method moodle_page::get_courserecord. Please use $PAGE->course instead.'); + return $this->get_course(); + } } /** @@ -463,11 +471,6 @@ class page_base extends moodle_page { */ class page_course extends page_base { - // Any data we might need to store specifically about ourself should be declared here. - // After init_full() is called for the first time, ALL of these variables should be - // initialized correctly and ready for use. - var $courserecord = NULL; - // Do any validation of the officially recognized bits of the data and forward to parent. // Do NOT load up "expensive" resouces (e.g. SQL data) here! function init_quick($data) { @@ -490,15 +493,6 @@ class page_course extends page_base { if (empty($this->id)) { $this->id = 0; // avoid db errors } - if ($this->id == $COURSE->id) { - $this->courserecord = $COURSE; - } else { - $this->courserecord = $DB->get_record('course', array('id'=>$this->id)); - } - - if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) { - print_error('cannotinitpage', 'debug', '', (object)array('name'=>'course', 'id'=>$this->id)); - } $this->context = get_context_instance(CONTEXT_COURSE, $this->id); @@ -569,7 +563,7 @@ class page_course extends page_base { $this->init_full(); $replacements = array( - '%fullname%' => $this->courserecord->fullname + '%fullname%' => $this->course->fullname ); foreach($replacements as $search => $replace) { $title = str_replace($search, $replace, $title); @@ -585,9 +579,9 @@ class page_course extends page_base { // The "Editing On" button will be appearing only in the "main" course screen // (i.e., no breadcrumbs other than the default one added inside this function) - $buttons = switchroles_form($this->courserecord->id); + $buttons = switchroles_form($this->course->id); if ($this->user_allowed_editing()) { - $buttons .= update_course_icon($this->courserecord->id ); + $buttons .= update_course_icon($this->course->id ); } $buttons = empty($morenavlinks) ? $buttons : ' '; @@ -596,8 +590,8 @@ class page_course extends page_base { $buttons = ($buttons == ' ') ? $extrabuttons : $buttons.$extrabuttons; } - print_header($title, $this->courserecord->fullname, $navigation, - '', $meta, true, $buttons, user_login_string($this->courserecord, $USER), false, $bodytags); + print_header($title, $this->course->fullname, $navigation, + '', $meta, true, $buttons, user_login_string($this->course, $USER), false, $bodytags); } // SELF-REPORTING SECTION @@ -614,7 +608,7 @@ class page_course extends page_base { return parent::get_format_name(); } // This needs to reflect the path hierarchy under Moodle root. - return 'course-view-'.$this->courserecord->format; + return 'course-view-'.$this->course->format; } // This should return a fully qualified path to the URL which is responsible for displaying us. @@ -681,7 +675,7 @@ class page_course extends page_base { } // It's a normal course, so do it according to the course format else { - $pageformat = $this->courserecord->format; + $pageformat = $this->course->format; if (!empty($CFG->{'defaultblocks_'. $pageformat})) { $blocknames = $CFG->{'defaultblocks_'. $pageformat}; } @@ -731,7 +725,6 @@ class page_course extends page_base { */ class page_generic_activity extends page_base { var $activityname = NULL; - var $courserecord = NULL; var $modulerecord = NULL; var $activityrecord = NULL; @@ -747,10 +740,6 @@ class page_generic_activity extends page_base { if (!$this->modulerecord = get_coursemodule_from_instance($this->activityname, $this->id)) { print_error('cannotinitpager', 'debug', '', (object)array('name'=>$this->activityname, 'id'=>$this->id)); } - $this->courserecord = $DB->get_record('course', array('id'=>$this->modulerecord->course)); - if(empty($this->courserecord)) { - print_error('invalidcourseid'); - } $this->activityrecord = $DB->get_record($this->activityname, array('id'=>$this->id)); if(empty($this->activityrecord)) { print_error('cannotinitpager', 'debug', '', (object)array('name'=>$this->activityname, 'id'=>$this->id)); @@ -800,7 +789,7 @@ class page_generic_activity extends page_base { } if (empty($morenavlinks) && $this->user_allowed_editing()) { - $buttons = ''; + $buttons = '
'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', $this->activityname)).'
'; if (!empty($CFG->showblocksonmodpages)) { $buttons .= '
'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'
frametarget.' method="get" action="view.php">
'. ''. @@ -816,7 +805,7 @@ class page_generic_activity extends page_base { $morenavlinks = array(); } $navigation = build_navigation($morenavlinks, $this->modulerecord); - print_header($title, $this->courserecord->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->courserecord, $this->modulerecord), false, $bodytags); + print_header($title, $this->course->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->course, $this->modulerecord), false, $bodytags); } } diff --git a/mod/lesson/pagelib.php b/mod/lesson/pagelib.php index 0d25e9bffa..afd5ad0e4b 100644 --- a/mod/lesson/pagelib.php +++ b/mod/lesson/pagelib.php @@ -73,12 +73,12 @@ class page_lesson extends page_generic_activity { print_error('invalidpageid', 'lesson'); } if (empty($title)) { - $title = "{$this->courserecord->shortname}: $activityname"; + $title = "{$this->course->shortname}: $activityname"; } /// Build the buttons if (has_capability('mod/lesson:edit', $context)) { - $buttons = ''.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson')); + $buttons = ''.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', 'lesson')); if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) { $buttons .= 'frametarget.' method="get" action="'.$CFG->wwwroot.'/mod/lesson/lesson.php">'. @@ -125,13 +125,13 @@ class page_lesson extends page_generic_activity { // } $navigation = build_navigation($morenavlinks, $this->modulerecord); - print_header($title, $this->courserecord->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->courserecord, $this->modulerecord)); + print_header($title, $this->course->fullname, $navigation, '', $meta, true, $buttons, navmenu($this->course, $this->modulerecord)); if (has_capability('mod/lesson:manage', $context)) { print_heading_with_help($activityname, 'overview', 'lesson'); // Rename our objects for the sake of the tab code - list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord, &$this->courserecord, &$this->activityrecord, 'view'); + list($cm, $course, $lesson, $currenttab) = array(&$this->modulerecord, &$this->course, &$this->activityrecord, 'view'); include($CFG->dirroot.'/mod/lesson/tabs.php'); } else { print_heading($activityname); -- 2.39.5