]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10132 improved random glossary blocks - now uses modinfo too + fixed some notices...
authorskodak <skodak>
Tue, 5 Feb 2008 23:34:20 +0000 (23:34 +0000)
committerskodak <skodak>
Tue, 5 Feb 2008 23:34:20 +0000 (23:34 +0000)
blocks/glossary_random/block_glossary_random.php

index 58e8642010efe4a6e7988f90d3b5d8aacf50edd6..681d0ca9e3346fea1314103ea1e24d61a658e4a9 100644 (file)
@@ -153,7 +153,7 @@ class block_glossary_random extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG;
+        global $USER, $CFG, $COURSE;
 
         if (empty($this->config->glossary)) {
             $this->content->text   = get_string('notyetconfigured','block_glossary_random');
@@ -163,7 +163,16 @@ class block_glossary_random extends block_base {
 
         $glossaryid = $this->config->glossary;
 
-        if(! $glossary = get_record('glossary', 'id', $glossaryid, 'course', $this->course->id) ){
+        if ($this->course->id == $COURSE->id) {
+            $course = $COURSE;
+        } else {
+            $course = get_record('course', 'id', $this->course->id); 
+        }
+
+        require_once($CFG->dirroot.'/course/lib.php');
+        $modinfo = get_fast_modinfo($course);
+
+        if (!isset($modinfo->instances['glossary'][$glossaryid])) {
             // we can get here if the glossary has been deleted, so
             // unconfigure the glossary from the block..
             $this->config->glossary = 0;
@@ -175,6 +184,7 @@ class block_glossary_random extends block_base {
             return $this->content;
         }
 
+        $cm = $modinfo->instances['glossary'][$glossaryid];
 
         if (empty($this->config->cache)) {
             $this->config->cache = '';
@@ -189,10 +199,8 @@ class block_glossary_random extends block_base {
 
         // place link to glossary in the footer if the glossary is visible
 
-        $cm = get_coursemodule_from_instance('glossary',$glossaryid, $this->course->id) ;
-
         //Obtain the visible property from the instance
-        if (coursemodule_visible_for_user($cm)) {
+        if ($cm->uservisible) {
             if (has_capability('mod/glossary:write', get_context_instance(CONTEXT_MODULE, $cm->id))) {
                 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?id='.$cm->id
                 .'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';