$this->instance_config_commit();
}
+ // Get glossary instance, if not found then return without error, as this will be handled in get_content.
+ if (!$glossary = $DB->get_record('glossary', array('id' => $this->config->glossary))) {
+ return false;
+ }
+
+ $this->config->globalglossary = $glossary->globalglossary;
+
+ // Save course id in config, so we can get correct course module.
+ $this->config->courseid = $glossary->course;
+
// Get module and context, to be able to rewrite urls
- if (! $cm = get_coursemodule_from_instance("glossary", $this->config->glossary, $this->course->id)) {
+ if (! $cm = get_coursemodule_from_instance('glossary', $glossary->id, $this->config->courseid)) {
return false;
}
$glossaryctx = context_module::instance($cm->id);
}
require_once($CFG->dirroot.'/course/lib.php');
- $course = $this->page->course;
- $modinfo = get_fast_modinfo($course);
- $glossaryid = $this->config->glossary;
- if (!isset($modinfo->instances['glossary'][$glossaryid])) {
- // we can get here if the glossary has been deleted, so
- // unconfigure the glossary from the block..
+ // If $this->config->globalglossary is not set then get glossary info from db.
+ if (!isset($this->config->globalglossary)) {
+ if (!$glossary = $DB->get_record('glossary', array('id' => $this->config->glossary))) {
+ return '';
+ } else {
+ $this->config->courseid = $glossary->course;
+ $this->config->globalglossary = $glossary->globalglossary;
+ $this->instance_config_commit();
+ }
+ }
+
+ $modinfo = get_fast_modinfo($this->config->courseid);
+ // If deleted glossary or non-global glossary on different course page, then reset.
+ if (!isset($modinfo->instances['glossary'][$this->config->glossary])
+ || ((empty($this->config->globalglossary) && ($this->config->courseid != $this->page->course)))) {
$this->config->glossary = 0;
$this->config->cache = '';
$this->instance_config_commit();
return $this->content;
}
- $cm = $modinfo->instances['glossary'][$glossaryid];
-
+ $cm = $modinfo->instances['glossary'][$this->config->glossary];
if (!has_capability('mod/glossary:view', context_module::instance($cm->id))) {
return '';
}
}
$this->content = new stdClass();
- $this->content->text = $this->config->cache;
-
- // place link to glossary in the footer if the glossary is visible
- //Obtain the visible property from the instance
- if ($cm->uservisible) {
+ // Show glossary if visible and place links in footer.
+ if ($cm->visible) {
+ $this->content->text = $this->config->cache;
if (has_capability('mod/glossary:write', context_module::instance($cm->id))) {
$this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?cmid='.$cm->id
.'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';
$this->content->footer .= '<a href="'.$CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id
.'" title="'.$this->config->viewglossary.'">'.$this->config->viewglossary.'</a>';
- // otherwise just place some text, no link
+ // Otherwise just place some text, no link.
} else {
$this->content->footer = $this->config->invisible;
}
$mform->setType('config_title', PARAM_TEXT);
// Select glossaries to put in dropdown box ...
- $glossaries = $DB->get_records_menu('glossary', array('course' => $this->block->course->id), 'name', 'id,name');
+ $glossaries = $DB->get_records_select_menu('glossary', 'course = ? OR globalglossary = ?', array($this->block->course->id, 1), 'name', 'id,name');
foreach($glossaries as $key => $value) {
$glossaries[$key] = strip_tags(format_string($value, true));
}