moodle_page: MDL-12212 remove code in legacy page types that stores a course record

This commit is contained in:
tjhunt
2009-05-06 08:35:39 +00:00
parent f230ce19ea
commit 31940ba622
4 changed files with 25 additions and 43 deletions
+2 -9
View File
@@ -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;
+1 -1
View File
@@ -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;
+18 -29
View File
@@ -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 = '<table><tr><td>'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', $this->activityname)).'</td>';
$buttons = '<table><tr><td>'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', $this->activityname)).'</td>';
if (!empty($CFG->showblocksonmodpages)) {
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
@@ -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);
}
}
+4 -4
View File
@@ -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 = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'lesson'));
$buttons = '<span class="edit_buttons">'.update_module_button($this->modulerecord->id, $this->course->id, get_string('modulename', 'lesson'));
if (!empty($this->lessonpageid) and $this->lessonpageid != LESSON_EOL) {
$buttons .= '<form '.$CFG->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);