From 44acd8201d6ae9fdc1115cb61cf082065a348fc5 Mon Sep 17 00:00:00 2001 From: Vasilis Daloukas Date: Thu, 6 Jul 2017 13:30:50 +0300 Subject: [PATCH] New: support for global glossaries --- check.php | 2 +- cross/cross_class.php | 6 +++++- hangman/play.php | 3 ++- locallib.php | 6 +++++- mod_form.php | 9 +++++++-- showanswers.php | 2 +- snakes/play.php | 4 +++- version.php | 2 +- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/check.php b/check.php index 0d362b7..fb73c65 100644 --- a/check.php +++ b/check.php @@ -245,7 +245,7 @@ function game_check_common_problems_shortanswer_allowspaces( $game, &$warnings, } if (count( $ret) != 0) { - $warnings[] = get_string( 'common_problems_allowspaces', 'game').': '.count($ret).' ('.implode( ', ', $ret); + $warnings[] = get_string( 'common_problems_allowspaces', 'game').': '.count($ret).' ('.implode( ', ', $ret).')'; } } diff --git a/cross/cross_class.php b/cross/cross_class.php index e3b0f24..ea99d2e 100644 --- a/cross/cross_class.php +++ b/cross/cross_class.php @@ -770,6 +770,8 @@ class Cross * @param stdClass $game */ public function showhtml_base( $crossm, $crossd, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game) { + global $CFG, $DB; + $this->mLegendh = array(); $this->mLegendv = array(); @@ -790,7 +792,9 @@ class Cross $legendh = array(); if ($game->glossaryid) { - $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); + $sql = "SELECT id,course FROM {$CFG->prefix}glossary WHERE id={$game->glossaryid}"; + $glossary = $DB->get_record_sql( $sql); + $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $glossary->course); $contextglossary = game_get_context_module_instance( $cmglossary->id); } foreach ($crossd as $rec) { diff --git a/hangman/play.php b/hangman/play.php index 4b55838..ee36a53 100644 --- a/hangman/play.php +++ b/hangman/play.php @@ -366,7 +366,8 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$wordline, &$wordli $questiontext = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext); $query->questiontext = game_filterquestion($questiontext, $query->questionid, $context->id, $game->course); } else { - $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); + $glossary = $DB->get_record_sql( "SELECT id,course FROM {$CFG->prefix}glossary WHERE id={$game->glossaryid}"); + $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $glossary->course); $contextglossary = game_get_context_module_instance( $cmglossary->id); $query->questiontext = game_filterglossary(str_replace( '\"', '"', $query->questiontext), $query->glossaryentryid, $contextglossary->id, $game->course); diff --git a/locallib.php b/locallib.php index 74367e6..31b1bd3 100644 --- a/locallib.php +++ b/locallib.php @@ -2534,8 +2534,12 @@ function game_strpos( $haystack, $needle, $offset = 0) { * @param string $text */ function game_show_query( $game, $query, $text) { + global $CFG, $DB; + if ($game->glossaryid) { - $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); + $sql = "SELECT id,course FROM {$CFG->prefix}glossary WHERE id={$game->glossaryid}"; + $glossary = $DB->get_record_sql( $sql); + $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $glossary->course); $contextglossary = game_get_context_module_instance( $cmglossary->id); return game_filterglossary(str_replace( '\"', '"', $text), $query->glossaryentryid, $contextglossary->id, $game->course); } else if ($query->questionid) { diff --git a/mod_form.php b/mod_form.php index 1637fef..d740330 100644 --- a/mod_form.php +++ b/mod_form.php @@ -98,8 +98,13 @@ class mod_game_mod_form extends moodleform_mod { if ($hasglossary) { $a = array(); - if ($recs = $DB->get_records('glossary', array( 'course' => $COURSE->id), 'id,name')) { + $sql = "SELECT id,name,globalglossary,course FROM {$CFG->prefix}glossary ". + "WHERE course={$COURSE->id} OR globalglossary=1 ORDER BY globalglossary DESC,name"; + if ($recs = $DB->get_records_sql($sql)) { foreach ($recs as $rec) { + if( ($rec->globalglossary != 0) and ($rec->course != $COURSE->id)) { + $rec->name = '*'.$rec->name; + } $a[$rec->id] = $rec->name; } } @@ -429,7 +434,7 @@ class mod_game_mod_form extends moodleform_mod { $sql2 = "SELECT COUNT(*) ". " FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories gec". " WHERE gec.categoryid=gc.id AND gec.entryid=ge.id"; - $sql = "SELECT gc.id,gc.name,g.name as name2, ($sql2) as c ". + $sql = "SELECT gc.id,gc.name,g.name as name2,g.globalglossary,g.course, ($sql2) as c ". " FROM {$CFG->prefix}glossary_categories gc, {$CFG->prefix}glossary g". " WHERE $select AND gc.glossaryid=g.id". " ORDER BY g.name, gc.name"; diff --git a/showanswers.php b/showanswers.php index 0272ef0..d3b3356 100644 --- a/showanswers.php +++ b/showanswers.php @@ -475,7 +475,7 @@ function game_showanswers_glossary( $game) { if ($game->param8 == 0) { // Not allowed -. if (!( strpos( $question->concept, '-') === false)) { continue; - } + } } echo ''; diff --git a/snakes/play.php b/snakes/play.php index b73d81f..2005353 100644 --- a/snakes/play.php +++ b/snakes/play.php @@ -353,7 +353,9 @@ function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) { // Add a hidden field with glossaryentryid. echo '\n"; - $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); + $sql = "SELECT id,course FROM {$CFG->prefix}glossary WHERE id={$game->glossaryid}"; + $glossary = $DB->get_record_sql( $sql); + $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $glossary->course); $contextglossary = game_get_context_module_instance( $cmglossary->id); $s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course); diff --git a/version.php b/version.php index e1768e0..9f9009c 100644 --- a/version.php +++ b/version.php @@ -35,7 +35,7 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2017070601; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017070602; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->release = '2017-07-06';