Skip to content

Commit

Permalink
MDL-20131 Glossary: Global glossary can be added in Random glossary e…
Browse files Browse the repository at this point in the history
…ntry block.
  • Loading branch information
Rajesh Taneja committed Feb 11, 2013
1 parent 6319737 commit 95556ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
46 changes: 31 additions & 15 deletions blocks/glossary_random/block_glossary_random.php
Expand Up @@ -43,8 +43,18 @@ function specialization() {
$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);
Expand Down Expand Up @@ -144,13 +154,22 @@ function get_content() {
}

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();
Expand All @@ -161,8 +180,7 @@ function get_content() {
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 '';
}
Expand All @@ -176,12 +194,10 @@ function get_content() {
}

$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 />';
Expand All @@ -192,7 +208,7 @@ function get_content() {
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/glossary_random/edit_form.php
Expand Up @@ -41,7 +41,7 @@ protected function specific_definition($mform) {
$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));
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/glossary_random/version.php
Expand Up @@ -25,6 +25,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2012112902; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2013020400; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version
$plugin->component = 'block_glossary_random'; // Full name of the plugin (used for diagnostics)

0 comments on commit 95556ce

Please sign in to comment.