]> git.mjollnir.org Git - moodle.git/commitdiff
blocklib: MDL-19010 Fix blocks that were relying on ->instance in an unfortunate way
authortjhunt <tjhunt>
Wed, 6 May 2009 09:15:33 +0000 (09:15 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 09:15:33 +0000 (09:15 +0000)
22 files changed:
blocks/activity_modules/block_activity_modules.php
blocks/admin/block_admin.php
blocks/blog_menu/block_blog_menu.php
blocks/blog_tags/block_blog_tags.php
blocks/calendar_upcoming/block_calendar_upcoming.php
blocks/course_summary/block_course_summary.php
blocks/html/block_html.php
blocks/html/config_instance.html
blocks/messages/block_messages.php
blocks/moodleblock.class.php
blocks/online_users/block_online_users.php
blocks/participants/block_participants.php
blocks/quiz_results/block_quiz_results.php
blocks/quiz_results/config_instance.html
blocks/rss_client/block_rss_client.php
blocks/rss_client/config_instance.html
blocks/rss_client/config_instance_tabs.php
blocks/search_forums/block_search_forums.php
blocks/section_links/block_section_links.php
blocks/site_main_menu/block_site_main_menu.php
blocks/social_activities/block_social_activities.php
blog/header.php

index 00f4f27ec601adcdf03dab98f979c9c4734125bc..bf9c770e823b9036d6ac10c653da84dd31941409 100644 (file)
@@ -18,15 +18,7 @@ class block_activity_modules extends block_list {
         $this->content->icons = array();
         $this->content->footer = '';
 
-        if ($COURSE->id == $this->instance->pageid) {
-            $course = $COURSE;
-        } else {
-            $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
-        }
-
-        if (empty($course)) {
-            return '';
-        }
+        $course = $this->page->course;
 
         require_once($CFG->dirroot.'/course/lib.php');
 
@@ -44,7 +36,7 @@ class block_activity_modules extends block_list {
 
         foreach ($modfullnames as $modname => $modfullname) {
             if ($modname != 'label') {
-                $this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modfullname.'</a>';
+                $this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$course->id.'">'.$modfullname.'</a>';
                 $this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" class="icon" alt="" />';
             }
         }
index 0b78486b3f5be2d5be41e63341ad00f0d32ad60f..bb82b72713797befe32e206b92ea0c7bf04dd678 100644 (file)
@@ -7,8 +7,7 @@ class block_admin extends block_list {
     }
 
     function get_content() {
-
-        global $CFG, $USER, $SITE, $COURSE, $DB, $PAGE;
+        global $CFG, $USER, $DB;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -19,29 +18,8 @@ class block_admin extends block_list {
         $this->content->icons = array();
         $this->content->footer = '';
 
-        if (empty($this->instance->pageid)) { // sticky
-            if (!empty($COURSE)) {
-                $this->instance->pageid = $COURSE->id;
-            }
-        }
-
-        if (empty($this->instance)) {
-            return $this->content = '';
-        } else if ($this->instance->pageid == SITEID) {
-            // return $this->content = '';
-        }
-
-        if (!empty($this->instance->pageid)) {
-            $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
-            if ($COURSE->id == $this->instance->pageid) {
-                $course = $COURSE;
-            } else {
-                $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
-            }
-        } else {
-            $context = get_context_instance(CONTEXT_SYSTEM);
-            $course = $SITE;
-        }
+        $context = $this->page->context;
+        $course = $this->page->course;
 
         if (!has_capability('moodle/course:view', $context)) {  // Just return
             return $this->content;
@@ -54,21 +32,19 @@ class block_admin extends block_list {
         }
 
     /// Course editing on/off
-
         if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
-            if ($PAGE->user_is_editing()) {
-                $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
+            if ($this->page->user_is_editing()) {
+                $this->content->items[]='<a href="view.php?id='.$course->id.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
             } else {
-                $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
+                $this->content->items[]='<a href="view.php?id='.$course->id.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
             }
 
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/edit.php?id='.$this->instance->pageid.'">'.get_string('settings').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/edit.php?id='.$course->id.'">'.get_string('settings').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/settings.gif" class="icon" alt="" />';
         }
 
     /// Assign roles to the course
-
         if ($course->id != SITEID) {
             if (has_capability('moodle/role:assign', $context)) {
                 $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
@@ -99,7 +75,7 @@ class block_admin extends block_list {
             }
 
             if ($reportavailable) {
-                $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
+                $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$course->id.'">'.get_string('grades').'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
             }
         }
@@ -107,7 +83,7 @@ class block_admin extends block_list {
     /// Course outcomes (to help give it more prominence because it's important)
         if (!empty($CFG->enableoutcomes)) {
             if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
-                $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
+                $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$course->id.'">'.get_string('outcomes', 'grades').'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
             }
         }
@@ -116,7 +92,7 @@ class block_admin extends block_list {
         if ($course->metacourse) {
             if (has_capability('moodle/course:managemetacourse', $context)) {
                 $strchildcourses = get_string('childcourses');
-                $this->content->items[]='<a href="importstudents.php?id='.$this->instance->pageid.'">'.$strchildcourses.'</a>';
+                $this->content->items[]='<a href="importstudents.php?id='.$course->id.'">'.$strchildcourses.'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
             } else if (has_capability('moodle/role:assign', $context)) {
                 $strchildcourses = get_string('childcourses');
@@ -127,41 +103,39 @@ class block_admin extends block_list {
 
 
     /// Manage groups in this course
-
         if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
             $strgroups = get_string('groups');
-            $this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
+            $this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$course->id.'">'.$strgroups.'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
         }
 
     /// Backup this course
-
         if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$course->id.'">'.get_string('backup').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
         }
 
     /// Restore to this course
         if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$course->id.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
         }
 
     /// Import data from other courses
         if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$course->id.'">'.get_string('import').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
         }
 
     /// Reset this course
         if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$course->id.'">'.get_string('reset').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
         }
 
     /// View course reports
         if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) { // basic capability for listing of reports
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$course->id.'">'.get_string('reports').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
         }
 
@@ -187,7 +161,7 @@ class block_admin extends block_list {
             }
             if ($questionlink) {
                 $this->content->items[]='<a href="'.$CFG->wwwroot.'/question/'.$questionlink.
-                        '?courseid='.$this->instance->pageid.'">'.get_string('questions', 'quiz').'</a>';
+                        '?courseid='.$course->id.'">'.get_string('questions', 'quiz').'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/questions.gif" class="icon" alt="" />';
             }
         }
@@ -202,7 +176,7 @@ class block_admin extends block_list {
 
     /// Manage files
         if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
-            $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$course->id.'">'.get_string('files').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt=""/>';
         }
 
@@ -222,10 +196,10 @@ class block_admin extends block_list {
     /// Unenrol link
         if (empty($course->metacourse) && ($course->id!==SITEID)) {
             if (has_capability('moodle/legacy:guest', $context, NULL, false)) {   // Are a guest now
-                $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/enrol.php?id='.$this->instance->pageid.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
+                $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/enrol.php?id='.$course->id.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
             } else if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id, false)) {  // Have some role
-                $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/unenrol.php?id='.$this->instance->pageid.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
+                $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/unenrol.php?id='.$course->id.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
             }
         }
index 04aed2e2e8e07704e2652c2db8d1a2a7ae93e1db..4bbd378dd8ddd88fffdea38b275ea684aaa69d61 100755 (executable)
@@ -39,12 +39,6 @@ class block_blog_menu extends block_base {
 
         $this->content = new stdClass;
         $this->content->footer = '';
-        if (empty($this->instance) /*|| empty($CFG->blog_version)*/) {
-            // Either we're being asked for content without
-            // an associated instance of the Blog module has never been installed.
-            $this->content->text = $output;
-            return $this->content;
-        }
 
         //if ( blog_isLoggedIn() && !isguest() ) {
             $courseviewlink = '';
index 3d03badddcf25df530f7aad8b0a37a91da0dfd74..c230a743eb67775010def8c5f23d13f1c1c493d8 100644 (file)
@@ -60,11 +60,6 @@ class block_blog_tags extends block_base {
             return $this->content;
         }
 
-        if (empty($this->instance)) {
-            $this->content = '';
-            return $this->content;
-        }
-
         $this->content = new stdClass;
         $this->content->text = '';
         $this->content->footer = '';
@@ -140,11 +135,7 @@ class block_blog_tags extends block_base {
 
                     case BLOG_COURSE_LEVEL:
                         $filtertype = 'course';
-                        if (isset($COURSE->id)) {
-                            $filterselect = $COURSE->id;
-                        } else {
-                            $filterselect = $this->instance->pageid;
-                        }
+                        $filterselect = $COURSE->id;
                     break;
 
                     default:
index b47559593fd991fb0ecc19dfed5aa514a3945444..f7060527f88c777b4265f5d5e4b545485b235c5e 100644 (file)
@@ -22,7 +22,6 @@ class block_calendar_upcoming extends block_base {
         $this->content->text = '';
 
         if (empty($this->instance)) { // Overrides: use no course at all
-        
             $courseshown = false;
             $filtercourse = array();
             $this->content->footer = '';
index 8ffc2448d8d54e09fe1cfe81a02c088b2408254f..55cde01dd25d9cfe5b5e47d25d178f2b716624ac 100644 (file)
@@ -7,8 +7,7 @@ class block_course_summary extends block_base {
     }
 
     function specialization() {
-        global $COURSE;
-        if($this->instance->pagetype == PAGE_COURSE_VIEW && $COURSE->id != SITEID) {
+        if($this->page->pagetype == PAGE_COURSE_VIEW && $PAGE->course->id != SITEID) {
             $this->title = get_string('coursesummary', 'block_course_summary');
         }
     }
index e7c0aebe6e182731420756faff4c43a5a27b990f..e55f5785dbbb9569761e6a45fad6bc813d797e71 100755 (executable)
@@ -24,7 +24,7 @@ class block_html extends block_base {
             return $this->content;
         }
 
-        if (!empty($this->instance->pinned) or $this->instance->pagetype === 'course-view') {
+        if ($this->content_is_trusted()) {
             // fancy html allowed only on course page and in pinned blocks for security reasons
             $filteropt = new stdClass;
             $filteropt->noclean = true;
@@ -41,6 +41,10 @@ class block_html extends block_base {
         return $this->content;
     }
 
+    function content_is_trusted() {
+        return in_array($this->page->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM));
+    }
+
     /**
      * Will be called before an instance of this block is backed up, so that any links in
      * any links in any HTML fields on config can be encoded.
index 0d5feabc6fe4eb0bd3130641a009e846d0d938e8..cbbac9c5f675d9feddcc44543026c3e81b64c23b 100755 (executable)
@@ -2,7 +2,7 @@
     $usehtmleditor = can_use_html_editor();
 
     $text = isset($this->config->text) ? $this->config->text : '';
-    if (empty($this->instance->pinned) and $this->instance->pagetype !== 'course-view') {
+    if (!$this->content_is_trusted()) {
         $text = clean_text($text, FORMAT_HTML);
     }
 ?>
index 0c669bbb97c03c358d3d1ae9abb2342cedb9cdb1..9304276f1822ecc81e0c07012aaff69dfe092209 100644 (file)
@@ -20,7 +20,7 @@ class block_messages extends block_base {
         $this->content = new stdClass;
         $this->content->text = '';
         $this->content->footer = '';
-        
+
         if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) {
             return $this->content;
         }
index 906496103d8ec2e32777f6dad95d67e704b7cc0e..004e9702ff75b61d18315dcfacfb57a613bb1d11 100644 (file)
@@ -71,6 +71,12 @@ class block_base {
      */
     var $instance      = NULL;
 
+    /**
+     * The page that this block is appearing on.
+     * @var moodle_page
+     */
+    public $page       = NULL;
+
     /**
      * An object containing the instance configuration information for the current instance of this block.
      * @var stdObject $config
@@ -297,12 +303,13 @@ class block_base {
      */
     function is_empty() {
 
+        // TODO
         if (empty($this->instance->pinned)) {
             $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
         } else {
             $context = get_context_instance(CONTEXT_SYSTEM); // pinned blocks do not have own context
         }
-        
+
         if ( !has_capability('moodle/block:view', $context) ) {
             return true;
         }
@@ -400,29 +407,22 @@ class block_base {
      */
     function _add_edit_controls($options) {
         global $CFG, $USER, $PAGE;
-        
+
+        // TODO
         if (empty($this->instance->pinned)) {
             $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
         } else {
             $context = get_context_instance(CONTEXT_SYSTEM); // pinned blocks do not have own context
         }
-        
+
         // context for site or course, i.e. participant list etc
         // check to see if user can edit site or course blocks.
         // blocks can appear on other pages such as mod and blog pages...
 
-        switch ($this->instance->pagetype) {
-            case 'course-view':
-                if (!has_capability('moodle/site:manageblocks', $context)) {
-                    return null;
-                }
-            break;
-            default:
-            
-            break;  
+        if (!$this->page->user_can_edit_blocks()) {
+            return null;
         }
-        
-        
+
         if (!isset($this->str)) {
             $this->str->delete    = get_string('delete');
             $this->str->moveup    = get_string('moveup');
@@ -454,24 +454,12 @@ class block_base {
             $title = $this->str->show;
         }
 
-        if (empty($this->instance->pageid)) {
-            $this->instance->pageid = 0;
-        }
-
-        if (($this->instance->pagetype == $PAGE->pagetype) and $this->instance->pageid == $PAGE->id) {
-            $page = $PAGE;
-        } else {
-            $page = new moodle_page();
-            $page->set_pagetype($this->instance->pagetype);
-            $page->pageid = $this->instance->pageid;
-        }
+        $page = $this->page;
         $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey()));
 
-        if (empty($this->instance->pinned)) {
-            $movebuttons .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">' .
-                            '<img src="'.$CFG->pixpath.'/i/roles.gif" alt="'.$this->str->assignroles.'" /></a>';
-        }
-     
+        $movebuttons .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">' .
+                        '<img src="'.$CFG->pixpath.'/i/roles.gif" alt="'.$this->str->assignroles.'" /></a>';
+
         if ($this->user_can_edit()) {
             $movebuttons .= '<a class="icon hide" title="'. $title .'" href="'.$script.'&amp;blockaction=toggle">' .
                             '<img src="'. $CFG->pixpath.$icon .'" alt="'.$title.'" /></a>';
@@ -643,7 +631,7 @@ class block_base {
      * @param block $instance
      * @todo add additional documentation to further explain the format of instance and config
      */
-    function _load_instance($instance) {
+    function _load_instance($instance, $page) {
         if (!empty($instance->configdata)) {
             $this->config = unserialize(base64_decode($instance->configdata));
         }
@@ -653,6 +641,7 @@ class block_base {
         // so it won't work correctly. Thus it's commented out.
         // unset($instance->configdata);
         $this->instance = $instance;
+        $this->page = $page;
         $this->specialization();
     }
 
@@ -812,12 +801,13 @@ class block_list extends block_base {
 
     function is_empty() {
 
+        // TODO
         if (empty($this->instance->pinned)) {
             $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
         } else {
             $context = get_context_instance(CONTEXT_SYSTEM); // pinned blocks do not have own context
         }
-        
+
         if ( !has_capability('moodle/block:view', $context) ) {
             return true;
         }
index 5d2a5c6b820bdeef510dea55123afb744c69e57c..17112c414e23d1354f2c25679eca7667f464b59c 100644 (file)
@@ -37,6 +37,7 @@ class block_online_users extends block_base {
         // Get context so we can check capabilities.
         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
 
+        // TODO
         if (empty($this->instance->pinned)) {
             $blockcontext = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
         } else {
index 02d55a659580b7e5ee7540535d0c71fc026534e6..eb99df915975fe68a12c2ea8082fa423a2607003 100644 (file)
@@ -15,22 +15,14 @@ class block_participants extends block_list {
             return $this->content;
         }
 
-        // the following 3 lines is need to pass _self_test();
-        if (empty($this->instance->pageid)) {
-            return '';
-        }
-        
         $this->content = new object();
         $this->content->items = array();
         $this->content->icons = array();
         $this->content->footer = '';
-        
+
         /// MDL-13252 Always get the course context or else the context may be incorrect in the user/index.php
-        if (!$currentcontext = get_context_instance(CONTEXT_COURSE, $COURSE->id)) {
-            $this->content = '';
-            return $this->content;
-        }
-        
+        $currentcontext = $this->page->context;
+
         if ($COURSE->id == SITEID) {
             if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
                 $this->content = '';
index 9c64fa4bfc423ac70ae9bfa9236002e0c4caf529..d24acf95d236f992dcb18507a21cf2e8b963884b 100644 (file)
@@ -32,37 +32,33 @@ class block_quiz_results extends block_base {
             return $this->content;
         }
 
-        if($this->instance->pagetype == '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;
-        }
-        else {
-            // Assuming we are displayed in the quiz view page
-            $quizid    = $this->instance->pageid;
-
-            // A trick to take advantage of instance config and save queries
-            if (empty($this->config->courseid)) {
-                $modrecord = $DB->get_record('modules', array('name'=>'quiz'));
-                $cmrecord  = $DB->get_record('course_modules', array('module'=>$modrecord->id, 'instance'=>$quizid));
-                $this->config->courseid = intval($cmrecord->course);
-                $this->instance_config_commit();
+        if ($this->page->activityname == 'quiz') {
+            $quiz = $this->page->activityrecord;
+            $quizid = $quiz->id;
+            $courseid = $this->page->course->id;
+            $inquiz = true;
+        } else if (!empty($this->config->quizid)) {
+            $quizid = $this->config->quizid;
+            $quiz = $DB->get_record('quiz', array('id' => $quizid));
+            if (empty($quiz)) {
+                $this->content->text = get_string('error_emptyquizrecord', 'block_quiz_results');
+                return $this->content;
             }
-            $courseid = $this->config->courseid;
+            $courseid = $quiz->course;
+            $inquiz = false;
+        } else {
+            $quizid = 0;
         }
 
-        $context = get_context_instance(CONTEXT_COURSE, $courseid);
-
+        $context = $this->page->context;
 
         if (empty($quizid)) {
             $this->content->text = get_string('error_emptyquizid', 'block_quiz_results');
             return $this->content;
         }
 
-        // Get the quiz record
-        $quiz = $DB->get_record('quiz', array('id' => $quizid));
-        if (empty($quiz)) {
-            $this->content->text = get_string('error_emptyquizrecord', 'block_quiz_results');
+        if (empty($this->config->showbest) && empty($this->config->showworst)) {
+            $this->content->text = get_string('configuredtoshownothing', 'block_quiz_results');
             return $this->content;
         }
 
@@ -75,20 +71,23 @@ class block_quiz_results extends block_base {
             return $this->content;
         }
 
-        if (empty($this->config->showbest) && empty($this->config->showworst)) {
-            $this->content->text = get_string('configuredtoshownothing', 'block_quiz_results');
-            return $this->content;
-        }
-
         $groupmode = NOGROUPS;
         $best      = array();
         $worst     = array();
 
-        $nameformat = intval(empty($this->config->nameformat)  ? B_QUIZRESULTS_NAME_FORMAT_FULL : $this->config->nameformat);
+        if (!empty($this->config->nameformat)) {
+            $nameformat = $this->config->nameformat;
+        } else {
+            $nameformat = B_QUIZRESULTS_NAME_FORMAT_FULL;
+        }
 
-        if(!empty($this->config->usegroups)) {
-            $groupmode = groups_get_activity_groupmode(
-                    get_coursemodule_from_instance('quiz', $quizid, $courseid), $courseid);
+        if (!empty($this->config->usegroups)) {
+            if ($inquiz) {
+                $cm = $this->page->cm;
+            } else {
+                $cm = get_coursemodule_from_instance('quiz', $quizid, $courseid);
+            }
+            $groupmode = groups_get_activity_groupmode($cm);
         }
 
         if (has_capability('moodle/site:accessallgroups', $context) && $groupmode == SEPARATEGROUPS) {
@@ -96,7 +95,7 @@ class block_quiz_results extends block_base {
             $groupmode = VISIBLEGROUPS;
         }
 
-        switch($groupmode) {
+        switch ($groupmode) {
             case VISIBLEGROUPS:
             // Display group-mode results
             $groups = groups_get_all_groups($courseid);
@@ -110,7 +109,7 @@ class block_quiz_results extends block_base {
             // Find out all the userids which have a submitted grade
             $userids = array();
             $gradeforuser = array();
-            foreach($grades as $grade) {
+            foreach ($grades as $grade) {
                 $userids[] = $grade->userid;
                 $gradeforuser[$grade->userid] = (float)$grade->grade;
             }
@@ -152,14 +151,14 @@ class block_quiz_results extends block_base {
             // Collect all the group results we are going to use in $best and $worst
             $remaining = $numbest;
             $groupgrade = end($groupgrades);
-            while($remaining--) {
+            while ($remaining--) {
                 $best[key($groupgrades)] = $groupgrade['average'];
                 $groupgrade = prev($groupgrades);
             }
 
             $remaining = $numworst;
             $groupgrade = reset($groupgrades);
-            while($remaining--) {
+            while ($remaining--) {
                 $worst[key($groupgrades)] = $groupgrade['average'];
                 $groupgrade = next($groupgrades);
             }
@@ -167,7 +166,7 @@ class block_quiz_results extends block_base {
             // Ready for output!
             $gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
 
-            if($this->instance->pagetype != 'mod-quiz-view') {
+            if (!$inquiz) {
                 // Don't show header and link to the quiz if we ARE at the quiz...
                 $this->content->text .= '<h1><a href="'.$CFG->wwwroot.'/mod/quiz/view.php?q='.$quizid.'">'.$quiz->name.'</a></h1>';
             }
@@ -319,7 +318,7 @@ class block_quiz_results extends block_base {
 
             $gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
 
-            if($this->instance->pagetype != 'mod-quiz-view') {
+            if(!$inquiz) {
                 // Don't show header and link to the quiz if we ARE at the quiz...
                 $this->content->text .= '<h1><a href="'.$CFG->wwwroot.'/mod/quiz/view.php?q='.$quizid.'">'.$quiz->name.'</a></h1>';
             }
index ac4c324c3c2461b9ad48cccce022d13fd0881bee..cd9ffa9a75fe2b23e234c62e4573ae6aeb28b9d8 100644 (file)
@@ -1,12 +1,12 @@
 <table cellpadding="9" cellspacing="0">
-<?php if($this->instance->pagetype != 'mod-quiz-view') { ?>
+<?php if ($this->page->activityname != 'quiz') { ?>
 <tr valign="top">
     <td align="right">
         <?php print_string('config_select_quiz', 'block_quiz_results') ?>
     </td>
     <td>
         <?php
-            $quizzes = $DB->get_records('quiz', array('course'=>$this->instance->pageid), '', 'id, name');
+            $quizzes = $DB->get_records('quiz', array('course' => $this->page->course->id), '', 'id, name');
             if(empty($quizzes)) {
                 echo '<strong>'.get_string('config_no_quizzes_in_course', 'block_quiz_results').'</strong>';
                 echo '<p><input type="hidden" name="quizid" value="0" /></p>';
@@ -21,7 +21,7 @@
         ?>
     </td>
 </tr>
-<?php } // end if($this->instance->pagetype != PAGE_QUIZ_VIEW) ?>
+<?php } // end if in quiz ?>
 <tr valign="top">
     <td align="right">
         <?php print_string('config_show_best', 'block_quiz_results') ?>
index dcceaf4f17b9b99b9feb32e72e4ef9a425069b60..a3dfaec1b550c7ae8a5386d670111c03396fad16 100644 (file)
@@ -96,6 +96,7 @@
             }
         }
 
+        // TODO
         if (empty($this->instance->pinned)) {
             $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
         } else {
         }
 
         if (has_capability('block/rss_client:createsharedfeeds', $context)
-                    || has_capability('block/rss_client:createprivatefeeds', $context)) {
+                || has_capability('block/rss_client:createprivatefeeds', $context)) {
 
-            $page = page_create_object($this->instance->pagetype, $this->instance->pageid);
+            $page = $this->page;
             //if ($page->user_allowed_editing()) { // for SUBMITTERS_ALL_ACCOUNT_HOLDERS we're going to run into trouble later if we show it and then they don't have write access to the page.
             if (isset($this->config)) {
                 // This instance is configured - show Add/Edit feeds link.
index 83f6d76ef35fc926c9f49b8be1c573d0fa9e37f7..3afe111524503e3bcff5919721764b44a4ca2a82 100644 (file)
@@ -4,7 +4,7 @@ require_once($CFG->libdir .'/rsslib.php');
 $id = optional_param('id', SITEID, PARAM_INT);
 
 //create a page object for url_get_full()
-$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
+$page = $this->page;
 
 
 /// Print tabs at top
@@ -93,6 +93,7 @@ print_box_start();
                     print $checkbox . $feedtitle .'<br />'."\n";
                 }
             } else {
+                // TODO
                 if (empty($this->instance->pinned)) {
                     $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
                 } else {
@@ -173,6 +174,7 @@ print_box_start();
 } else {
   global $act, $url, $rssid, $preferredtitle, $shared;
   print '</div></form></div>';   // Closes off page form
+  // TODO
   if (empty($this->instance->pinned)) {
     $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
   } else {
index e8541e0d0b5273832208cbbb3d7f88787f4e84b8..a71be2a9ca31b6e516cab7384f09bd396216e489 100644 (file)
@@ -5,7 +5,7 @@
 global $USER;
 $tabs = $row = array();
 
-
+// TODO
 if (empty($this->instance->pinned)) {
     $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
 } else {
index 1f4cbae77fb04a880db086c3ba93f73cde17fb2a..0fbc286f4ab017993ba0baf243979321426bc1ee 100644 (file)
@@ -31,11 +31,11 @@ class block_search_forums extends block_base {
         
         $this->content->text  = '<div class="searchform">';
         $this->content->text .= '<form action="'.$CFG->wwwroot.'/mod/forum/search.php" style="display:inline"><fieldset class="invisiblefieldset">';
-        $this->content->text .= '<input name="id" type="hidden" value="'.$this->instance->pageid.'" />';  // course
+        $this->content->text .= '<input name="id" type="hidden" value="'.$this->page->course->id.'" />';  // course
         $this->content->text .= '<label class="accesshide" for="searchform_search">'.$search.'</label>'.
                                 '<input id="searchform_search" name="search" type="text" size="16" />';
         $this->content->text .= '<button id="searchform_button" type="submit" title="'.$search.'">'.$button.'</button><br />'; 
-        $this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/forum/search.php?id='.$this->instance->pageid.'">'.$advancedsearch.'</a>';
+        $this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/forum/search.php?id='.$this->page->course->id.'">'.$advancedsearch.'</a>';
         $this->content->text .= helpbutton('search', $advancedsearch, 'moodle', true, false, '', true);
         $this->content->text .= '</fieldset></form></div>';
 
index 7117ad925fa1b7a6fa81c6922945470fd0a0ca30..e7c1bdc06d5fbe25176a9a4d8820c824c038734a 100644 (file)
@@ -11,7 +11,7 @@ class block_section_links extends block_base {
         global $DB;
 
         parent::instance_config($instance);
-        $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
+        $course = $this->page->course;
         if (isset($course->format)) {
             if ($course->format == 'topics') {
                 $this->title = get_string('topics', 'block_section_links');
@@ -44,11 +44,7 @@ class block_section_links extends block_base {
             return $this->content;
         }
 
-        if ($this->instance->pageid == $COURSE->id) {
-            $course = $COURSE;
-        } else {
-            $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
-        }
+        $course = $this->page->course;
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
         if ($course->format == 'weeks' or $course->format == 'weekscss') {
@@ -70,10 +66,10 @@ class block_section_links extends block_base {
         }
 
         if (!empty($USER->id)) {
-            $display = $DB->get_field('course_display', 'display', array('course'=>$this->instance->pageid, 'userid'=>$USER->id));
+            $display = $DB->get_field('course_display', 'display', array('course'=>$this->page->course->id, 'userid'=>$USER->id));
         }
         if (!empty($display)) {
-            $link = $CFG->wwwroot.'/course/view.php?id='.$this->instance->pageid.'&amp;'.$sectionname.'=';
+            $link = $CFG->wwwroot.'/course/view.php?id='.$this->page->course->id.'&amp;'.$sectionname.'=';
         } else {
             $link = '#section-';
         }
index 144a6640d2e44445ac95106b990f51f68fba6097..8f7cb875fbac4ccbf79fe50079c8e9ed9793cc18 100644 (file)
@@ -26,14 +26,8 @@ class block_site_main_menu extends block_list {
             return $this->content;
         }
 
-        if ($COURSE->id == $this->instance->pageid) {
-            $course = $COURSE;
-        } else {
-            $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
-        }
-
+        $course = $this->page->course;
         require_once($CFG->dirroot.'/course/lib.php');
-
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         $isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
         $modinfo = get_fast_modinfo($course);
@@ -67,12 +61,11 @@ class block_site_main_menu extends block_list {
             return $this->content;
         }
 
-
 /// slow & hacky editing mode
-        $ismoving = ismoving($this->instance->pageid);
-        $section  = get_course_section(0, $this->instance->pageid);
+        $ismoving = ismoving($course->id);
+        $section  = get_course_section(0, $course->id);
 
-        get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
+        get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
 
         $groupbuttons = $course->groupmode;
         $groupbuttonslink = (!$course->groupmodeforce);
@@ -121,7 +114,7 @@ class block_site_main_menu extends block_list {
                         $this->content->icons[] = '';
                     }
                     $instancename = $modinfo->cms[$modnumber]->name;
-                    $instancename = format_string($instancename, true, $this->instance->pageid);
+                    $instancename = format_string($instancename, true, $course->id);
                     $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                     if (!empty($modinfo->cms[$modnumber]->extra)) {
                         $extra = $modinfo->cms[$modnumber]->extra;
index 06f29dfde35e4be1cfd610241e75cfbb5a9934d7..cf2777e69e105392bf581f672393f01ca96af86f 100644 (file)
@@ -26,11 +26,7 @@ class block_social_activities extends block_list {
             return $this->content;
         }
 
-        if ($COURSE->id == $this->instance->pageid) {
-            $course = $COURSE;
-        } else {
-            $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
-        }
+        $course = $this->page->course;
 
         require_once($CFG->dirroot.'/course/lib.php');
 
@@ -69,15 +65,15 @@ class block_social_activities extends block_list {
 
 
 /// slow & hacky editing mode
-        $ismoving = ismoving($this->instance->pageid);
-        $sections = get_all_sections($this->instance->pageid);
+        $ismoving = ismoving($course->id);
+        $sections = get_all_sections($course->id);
 
         if(!empty($sections) && isset($sections[0])) {
             $section = $sections[0];
         }
 
         if (!empty($section)) {
-            get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
+            get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
         }
 
         $groupbuttons = $course->groupmode;
@@ -127,7 +123,7 @@ class block_social_activities extends block_list {
                         $this->content->icons[] = '';
                     }
                     $instancename = $modinfo->cms[$modnumber]->name;
-                    $instancename = format_string($instancename, true, $this->instance->pageid);
+                    $instancename = format_string($instancename, true, $course->id);
                     $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                     if (!empty($modinfo->cms[$modnumber]->extra)) {
                         $extra = $modinfo->cms[$modnumber]->extra;
index 03a0be6f1cc6978f819c29c8fd8b48e8105aed49..3d8986422ef4a7e4774849e2ace26a6ce9ffcc16 100755 (executable)
@@ -76,23 +76,6 @@ $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_widt
 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
                                         BLOCK_R_MAX_WIDTH);
 
-// Display the blocks and allow blocklib to handle any block action requested
-$pageblocks = blocks_get_by_page($PAGE);
-
-if ($editing) {
-    if (!empty($blockaction) && confirm_sesskey()) {
-        if (!empty($blockid)) {
-            blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
-        } else if (!empty($instanceid)) {
-            $instance = blocks_find_instance($instanceid, $pageblocks);
-            blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
-        }
-        // This re-query could be eliminated by judicious programming in blocks_execute_action(),
-        // but I'm not sure if it's worth the complexity increase...
-        $pageblocks = blocks_get_by_page($PAGE);
-    }
-}
-
 if (!empty($tagid)) {
     $taginstance = $DB->get_record('tag', array('id'=>$tagid));
 } elseif (!empty($tag)) {