Skip to content

Commit

Permalink
MDL-32279 glossary filter: implement the setup() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 14, 2012
1 parent 6c5dbbb commit 3ffb739
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions filter/glossary/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,25 @@
*/
class filter_glossary extends moodle_text_filter {

public function setup($page, $context) {
// This only requires execution once per request.
static $jsinitialised = false;
if (empty($jsinitialised)) {
$page->requires->yui_module(
'moodle-filter_glossary-autolinker',
'M.filter_glossary.init_filter_autolinking',
array(array('courseid' => 0)));
$jsinitialised = true;
}
}

public function filter($text, array $options = array()) {
global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS, $PAGE;
global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS;

// Trivial-cache - keyed on $cachedcontextid
static $cachedcontextid;
static $conceptlist;

static $jsinitialised; // To control unique js init
static $nothingtodo; // To avoid processing if no glossaries / concepts are found

// Try to get current course
Expand Down Expand Up @@ -185,16 +196,6 @@ public function filter($text, array $options = array()) {
}

$conceptlist = filter_remove_duplicates($conceptlist);

if (empty($jsinitialised)) {
// Add a JavaScript event to open popup's here. This only ever need to be
// added once!
$PAGE->requires->yui_module(
'moodle-filter_glossary-autolinker',
'M.filter_glossary.init_filter_autolinking',
array(array('courseid' => $courseid)));
$jsinitialised = true;
}
}

if (!empty($GLOSSARY_EXCLUDECONCEPTS)) {
Expand Down

0 comments on commit 3ffb739

Please sign in to comment.