]> git.mjollnir.org Git - moodle.git/commitdiff
Merged $course -> $COURSE fixes from 1.6 stable
authormoodler <moodler>
Mon, 29 May 2006 08:17:57 +0000 (08:17 +0000)
committermoodler <moodler>
Mon, 29 May 2006 08:17:57 +0000 (08:17 +0000)
blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
blocks/course_summary/block_course_summary.php
blocks/glossary_random/block_glossary_random.php
blocks/news_items/block_news_items.php
blocks/online_users/block_online_users.php
blocks/recent_activity/block_recent_activity.php
blocks/rss_client/block_rss_client.php

index 9c796b90985e0107c10ea2f608b69e73ba2f4824..424e1fbf1c085a4db25de4294a7ce64e04b013a8 100644 (file)
@@ -11,7 +11,7 @@ class block_calendar_month extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG, $SESSION;
+        global $USER, $CFG, $SESSION, $COURSE;
         $cal_m = optional_param( 'cal_m', 0, PARAM_INT );
         $cal_y = optional_param( 'cal_y', 0, PARAM_INT );
 
@@ -28,12 +28,7 @@ class block_calendar_month extends block_base {
         // [pj] To me it looks like this if would never be needed, but Penny added it 
         // when committing the /my/ stuff. Reminder to discuss and learn what it's about.
         // It definitely needs SOME comment here!
-        if (!empty($this->instance->pageid)) {
-            $courseshown = $this->instance->pageid;
-        }
-        else {
-            $courseshown = SITEID;
-        }
+        $courseshown = $COURSE->id;
 
         if($courseshown == SITEID) {
             // Being displayed at site level. This will cause the filter to fall back to auto-detecting
@@ -58,13 +53,12 @@ class block_calendar_month extends block_base {
             $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
             // No filters for now
 
-        } elseif (!empty($courseshown)) {
+        } else {
             // For any other course
             $this->content->text .= calendar_overlib_html();
             $this->content->text .= calendar_top_controls('course', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
             $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
-            $course = get_record('course', 'id', $this->instance->pageid);
-            $this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $course).'</div>';
+            $this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $COURSE).'</div>';
             
         }
 
index 8be39db96fb252a4ccbfe95b4f9878b72c968bb6..b69b932329ef6b1180c865b2e4ce26029533f32c 100644 (file)
@@ -7,7 +7,7 @@ class block_calendar_upcoming extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG, $SESSION;
+        global $USER, $CFG, $SESSION, $COURSE;
         $cal_m = optional_param( 'cal_m', 0, PARAM_INT );
         $cal_y = optional_param( 'cal_y', 0, PARAM_INT );
 
@@ -27,12 +27,7 @@ class block_calendar_upcoming extends block_base {
             $this->content->footer = '';
 
         } else {
-            if (!empty($this->instance->pageid)) {
-                $courseshown = $this->instance->pageid;
-            }
-            else {
-                $courseshown = SITEID;
-            }
+            $courseshown = $COURSE->id;
             $this->content->footer = '<br /><a href="'.$CFG->wwwroot.
                                      '/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
                                       get_string('gotocalendar', 'calendar').'</a>...';
index d86982243d0acdbbd4f0042c3d77186b2b60a8b7..ebe8b1d96c2aead2ef255c86e182d5737f9fa1d6 100644 (file)
@@ -7,13 +7,14 @@ class block_course_summary extends block_base {
     }
 
     function specialization() {
-        if($this->instance->pagetype == PAGE_COURSE_VIEW && $this->instance->pageid != SITEID) {
+        global $COURSE;
+        if($this->instance->pagetype == PAGE_COURSE_VIEW && $COURSE->id != SITEID) {
             $this->title = get_string('coursesummary', 'block_course_summary');
         }
     }
 
     function get_content() {
-        global $CFG, $THEME;
+        global $CFG, $COURSE;
 
         if($this->content !== NULL) {
             return $this->content;
@@ -23,19 +24,14 @@ class block_course_summary extends block_base {
             return '';
         }
 
-        if (empty($this->instance->pageid)) {
-            $this->instance->pageid = SITEID;
-        }
-        $course  = get_record('course', 'id', $this->instance->pageid);
-        
         $this->content = New stdClass;
         $options->noclean = true;    // Don't clean Javascripts etc
-        $this->content->text = format_text($course->summary, FORMAT_HTML, $options);
-        if(isediting($this->instance->pageid)) {
-            if($this->instance->pageid == SITEID) {
+        $this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
+        if(isediting($COURSE->id)) {
+            if($COURSE->id == SITEID) {
                 $editpage = $CFG->wwwroot.'/'.$CFG->admin.'/site.php';
             } else {
-                $editpage = $CFG->wwwroot.'/course/edit.php?id='.$this->instance->pageid;
+                $editpage = $CFG->wwwroot.'/course/edit.php?id='.$COURSE->id;
             }
             $this->content->text .= "<div align=\"right\"><a href=\"$editpage\"><img src=\"$CFG->pixpath/t/edit.gif\" alt=\"\" /></a></div>";
         }
index c7b7a244c29d0605a88a9768a133202797df83b3..eb2dbb55a126bc291dd6ac05de368fcfc04753cb 100644 (file)
@@ -13,8 +13,8 @@ class block_glossary_random extends block_base {
     }
 
     function specialization() {
-        global $CFG;
-        $this->course = get_record('course', 'id', $this->instance->pageid);
+        global $CFG, $COURSE;
+        $this->course = $COURSE;
 
         // load userdefined title and make sure it's never empty
         if (empty($this->config->title)) {
index a928809aa4e624924675d5dd89104c9cdb938a8e..ac8cdb0e5e669a0ebe6953a5d86680be34f8476c 100644 (file)
@@ -7,7 +7,7 @@ class block_news_items extends block_base {
     }
 
     function get_content() {
-        global $CFG, $USER;
+        global $CFG, $USER, $COURSE;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -22,44 +22,39 @@ class block_news_items extends block_base {
         }
 
 
-        if ($this->instance->pageid == 0) {
-            $this->instance->pageid = SITEID;
-        }
-        $course = get_record('course', 'id', $this->instance->pageid);
-
-        if ($course->newsitems) {   // Create a nice listing of recent postings
+        if ($COURSE->newsitems) {   // Create a nice listing of recent postings
 
             require_once($CFG->dirroot.'/mod/forum/lib.php');   // We'll need this
            
             $text = '';
 
-            if (!$forum = forum_get_course_forum($course->id, 'news')) {
+            if (!$forum = forum_get_course_forum($COURSE->id, 'news')) {
                 return $this->content;
             }
 
 
         /// First work out whether we can post to this group and if so, include a link
 
-            if (isteacheredit($course->id)) {     /// Teachers can always post
+            if (isteacheredit($COURSE->id)) {     /// Teachers can always post
                 $visiblegroups = -1; 
 
                 $text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
                           get_string('addanewtopic', 'forum').'</a>...</div>';
 
             } else {                              /// Check the group situation
-                $currentgroup = get_current_group($course->id);
+                $currentgroup = get_current_group($COURSE->id);
 
                 if (forum_user_can_post_discussion($forum, $currentgroup)) {
                     $text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
                               get_string('addanewtopic', 'forum').'</a>...</div>';
                 }
 
-                if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
+                if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $COURSE->id)) {
                     $this->content->text = $text;
                     return $this->content;
                 }
     
-                $groupmode = groupmode($course, $cm);
+                $groupmode = groupmode($COURSE, $cm);
     
                 /// Decides if current user is allowed to see ALL the current discussions or not
     
@@ -73,7 +68,7 @@ class block_news_items extends block_base {
         /// Get all the recent discussions we're allowed to see
 
             if (! $discussions = forum_get_discussions($forum->id, 'p.modified DESC', 0, false, 
-                                                       $visiblegroups, $course->newsitems) ) {
+                                                       $visiblegroups, $COURSE->newsitems) ) {
                 $text .= '('.get_string('nonews', 'forum').')';
                 $this->content->text = $text;
                 return $this->content;
@@ -119,7 +114,7 @@ class block_news_items extends block_base {
                 } else {
                     $userid = $USER->id;
                 }
-                $this->content->footer .= '<br />'.rss_get_link($course->id, $userid, 'forum', $forum->id, $tooltiptext);
+                $this->content->footer .= '<br />'.rss_get_link($COURSE->id, $userid, 'forum', $forum->id, $tooltiptext);
             }
 
         }
index be9b96263e9620ca14fdb67133f67d084a62ec28..7eb84ffda0b933de4f959729212e8449010a5b15 100644 (file)
@@ -9,7 +9,7 @@ class block_online_users extends block_base {
     function has_config() {return true;}
 
     function get_content() {
-        global $USER, $CFG;
+        global $USER, $CFG, $COURSE;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -23,8 +23,6 @@ class block_online_users extends block_base {
             return $this->content;
         }
     
-        $course = get_record('course', 'id', $this->instance->pageid);
-
         $timetoshowusers = 300; //Seconds default
         if (isset($CFG->block_online_users_timetosee)) {
             $timetoshowusers = $CFG->block_online_users_timetosee * 60;
@@ -32,10 +30,10 @@ class block_online_users extends block_base {
         $timefrom = time()-$timetoshowusers;
 
         //Calculate if we are in separate groups
-        $isseparategroups = ($course->groupmode == SEPARATEGROUPS && $course->groupmodeforce && !isteacheredit($this->instance->pageid));
+        $isseparategroups = ($COURSE->groupmode == SEPARATEGROUPS && $COURSE->groupmodeforce && !isteacheredit($COURSE->id));
 
         //Get the user current group
-        $currentgroup = $isseparategroups ? get_current_group($this->instance->pageid) : NULL;
+        $currentgroup = $isseparategroups ? get_current_group($COURSE->id) : NULL;
 
         $groupmembers = "";
         $groupselect = "";
@@ -46,11 +44,11 @@ class block_online_users extends block_base {
             $groupselect .= " AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
         }
 
-        if ($this->instance->pageid == SITEID) {  // Site-level
+        if ($COURSE->id == SITEID) {  // Site-level
             $courseselect = '';
             $timeselect = "AND (s.timeaccess > $timefrom OR u.lastaccess > $timefrom)";
         } else {
-            $courseselect = "AND s.course = '".$this->instance->pageid."'";
+            $courseselect = "AND s.course = '".$COURSE->id."'";
             $timeselect = "AND s.timeaccess > $timefrom";
         }
 
@@ -69,7 +67,7 @@ class block_online_users extends block_base {
             }
         }
 
-        if ($this->instance->pageid == SITEID && $CFG->allusersaresitestudents) {
+        if ($COURSE->id == SITEID && $CFG->allusersaresitestudents) {
             if ($siteusers = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.picture, u.lastaccess
                                      FROM {$CFG->prefix}user u
                                      WHERE u.lastaccess > $timefrom AND u.username <> 'guest'
@@ -88,7 +86,7 @@ class block_online_users extends block_base {
                                           $groupmembers
                                      WHERE u.id = s.userid $courseselect $groupselect $timeselect ";
 
-        if (!isteacher($course->id)) {
+        if (!isteacher($COURSE->id)) {
             // Hide hidden teachers from students.
             $findteacherssql .= 'AND s.authority > 0 ';
         }
@@ -116,8 +114,8 @@ class block_online_users extends block_base {
             foreach ($users as $user) {
                 $this->content->text .= '<li class="listentry">';
                 $timeago = format_time(time() - max($user->timeaccess, $user->lastaccess)); //bruno to calculate correctly on frontpage 
-                $this->content->text .= print_user_picture($user->id, $this->instance->pageid, $user->picture, 16, true).' ';
-                $this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->instance->pageid.'" title="'.$timeago.'">'.$user->fullname.'</a>';
+                $this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true).' ';
+                $this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$COURSE->id.'" title="'.$timeago.'">'.$user->fullname.'</a>';
                 if (!empty($USER->id) and ($USER->id != $user->id) and !empty($CFG->messaging) and !isguest()) {  // Only when logged in
                     $this->content->text .= "\n".' <a title="'.get_string('messageselectadd').'" target="message_'.$user->id.'" href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'
                         .'<img class="icon message" src="'.$CFG->pixpath.'/t/message.gif" alt="'. get_string('messageselectadd') .'" /></a>';
index 7a075bcb48abc5511517541c4146a89d36dc71fc..06516b359c9413864bb2403ea975d5f79ab88527 100644 (file)
@@ -7,6 +7,7 @@ class block_recent_activity extends block_base {
     }
 
     function get_content() {
+        global $COURSE;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -21,11 +22,9 @@ class block_recent_activity extends block_base {
         $this->content->text = '';
         $this->content->footer = '';
 
-        $course = get_record('course', 'id', $this->instance->pageid);
-
         // Slightly hacky way to do it but...
         ob_start();
-        print_recent_activity($course);
+        print_recent_activity($COURSE);
         $this->content->text = ob_get_contents();
         ob_end_clean();
 
index 5b23469a9dc4e1d271691d774e8388bf8ea929ce..555eaa6f4fe8b02d78dcb29fc6374209f1bd2de3 100644 (file)
@@ -42,7 +42,7 @@
     }
 
     function get_content() {
-        global $CFG, $editing;
+        global $CFG, $editing, $COURSE;
 
         require_once($CFG->libdir .'/rsslib.php');
 
@@ -89,7 +89,7 @@
         $isteacher = false;
         $this->courseid = SITEID;
         if ($this->instance->pagetype == PAGE_COURSE_VIEW) {
-            $this->courseid = $this->instance->pageid;
+            $this->courseid = $COURSE->id;
             $isteacher = isteacher($this->courseid);
         }