diff --git a/mod/glossary/formats.php b/mod/glossary/formats.php index d40cf89f213..bf77eeb9840 100644 --- a/mod/glossary/formats.php +++ b/mod/glossary/formats.php @@ -261,7 +261,7 @@ echo ''; // Get all glossary tabs. $glossarytabs = glossary_get_all_tabs(); // Extract showtabs value in an array. - $visibletabs = glossary_get_visible_tabs($displayformat->showtabs); + $visibletabs = glossary_get_visible_tabs($displayformat); $size = min(10, count($glossarytabs)); ?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 4c21d15ba69..55b2d03240f 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -917,10 +917,11 @@ function glossary_get_available_formats() { $gf->name = $format; $gf->popupformatname = $format; $gf->visible = 1; - $DB->insert_record("glossary_formats",$gf); + $id = $DB->insert_record('glossary_formats', $gf); + $rec = $DB->get_record('glossary_formats', array('id' => $id)); } - if(is_null($rec->showtabs)) { + if (empty($rec->showtabs)) { glossary_set_default_visible_tabs($rec); } } @@ -3061,24 +3062,28 @@ function glossary_get_completion_state($course,$cm,$userid,$type) { function glossary_extend_navigation($navigation, $course, $module, $cm) { global $CFG, $DB; - $glossarytabs = $DB->get_field('glossary_formats', 'showtabs', array('name' => $module->displayformat)); + $displayformat = $DB->get_record('glossary_formats', array('name' => $module->displayformat)); // Get visible tabs for the format and check if the menu needs to be displayed. - $showtabs = glossary_get_visible_tabs($glossarytabs); + $showtabs = glossary_get_visible_tabs($displayformat); foreach ($showtabs as $showtabkey => $showtabvalue) { switch($showtabvalue) { case GLOSSARY_STANDARD : - $navigation->add(get_string('standardview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id' => $cm->id, 'mode' => 'letter'))); + $navigation->add(get_string('standardview', 'glossary'), new moodle_url('/mod/glossary/view.php', + array('id' => $cm->id, 'mode' => 'letter'))); break; case GLOSSARY_CATEGORY : - $navigation->add(get_string('categoryview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id' => $cm->id, 'mode' => 'cat'))); + $navigation->add(get_string('categoryview', 'glossary'), new moodle_url('/mod/glossary/view.php', + array('id' => $cm->id, 'mode' => 'cat'))); break; case GLOSSARY_DATE : - $navigation->add(get_string('dateview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id' => $cm->id, 'mode' => 'date'))); + $navigation->add(get_string('dateview', 'glossary'), new moodle_url('/mod/glossary/view.php', + array('id' => $cm->id, 'mode' => 'date'))); break; case GLOSSARY_AUTHOR : - $navigation->add(get_string('authorview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id' => $cm->id, 'mode' => 'author'))); + $navigation->add(get_string('authorview', 'glossary'), new moodle_url('/mod/glossary/view.php', + array('id' => $cm->id, 'mode' => 'author'))); break; } } @@ -3230,8 +3235,8 @@ function glossary_page_type_list($pagetype, $parentcontext, $currentcontext) { /** * Return list of all glossary tabs. - * @return array * @throws coding_exception + * @return array */ function glossary_get_all_tabs() { @@ -3244,7 +3249,7 @@ function glossary_get_all_tabs() { /** * Set 'showtabs' value for glossary formats - * @param $glossaryformat + * @param stdClass $glossaryformat record from 'glossary_formats' table */ function glossary_set_default_visible_tabs($glossaryformat) { global $DB; @@ -3255,25 +3260,38 @@ function glossary_set_default_visible_tabs($glossaryformat) { break; case GLOSSARY_DICTIONARY: $showtabs = 'standard'; + // Special code for upgraded instances that already had categories set up + // in this format - enable "category" tab. + // In new instances only 'standard' tab will be visible. + if ($DB->record_exists_sql("SELECT 1 + FROM {glossary} g, {glossary_categories} gc + WHERE g.id = gc.glossaryid and g.displayformat = ?", + array(GLOSSARY_DICTIONARY))) { + $showtabs .= ',category'; + } break; case GLOSSARY_FULLWITHOUTAUTHOR: $showtabs = 'standard,category,date'; break; default: - $showtabs = 'standard,author,category,date'; + $showtabs = 'standard,category,date,author'; break; } $DB->set_field('glossary_formats', 'showtabs', $showtabs, array('id' => $glossaryformat->id)); + $glossaryformat->showtabs = $showtabs; } /** * Convert 'showtabs' string to array - * @param $glossarytabs + * @param stdClass $displayformat record from 'glossary_formats' table * @return array */ -function glossary_get_visible_tabs($glossarytabs) { - $showtabs = preg_split('/,/', $glossarytabs, -1, PREG_SPLIT_NO_EMPTY); +function glossary_get_visible_tabs($displayformat) { + if (empty($displayformat->showtabs)) { + glossary_set_default_visible_tabs($displayformat); + } + $showtabs = preg_split('/,/', $displayformat->showtabs, -1, PREG_SPLIT_NO_EMPTY); return $showtabs; } diff --git a/mod/glossary/tabs.php b/mod/glossary/tabs.php index d7013764d80..015312baef3 100644 --- a/mod/glossary/tabs.php +++ b/mod/glossary/tabs.php @@ -21,7 +21,7 @@ } // Get visible tabs for the format and check tab needs to be displayed. - $dt = glossary_get_visible_tabs($dp->showtabs); + $dt = glossary_get_visible_tabs($dp); if (in_array(GLOSSARY_STANDARD, $dt)) { $browserow[] = new tabobject(GLOSSARY_STANDARD_VIEW, @@ -62,12 +62,15 @@ $tabrows[] = $toolsrow; } - ?>
- + 1)) { + print_tabs($tabrows, $tab, $inactive, $activated); +} +?>
@@ -117,4 +120,4 @@ break; } echo html_writer::empty_tag('hr'); -?> +?> \ No newline at end of file diff --git a/mod/glossary/tests/behat/categories.feature b/mod/glossary/tests/behat/categories.feature index f42dc43c1de..cd8c16e21e3 100644 --- a/mod/glossary/tests/behat/categories.feature +++ b/mod/glossary/tests/behat/categories.feature @@ -17,9 +17,11 @@ Feature: Glossary entries can be organised in categories | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | displayformat | course | idnumber | + | glossary | MyGlossary | Test glossary description | encyclopedia | C1 | glossary1 | And the following "activities" exist: | activity | name | intro | course | idnumber | - | glossary | MyGlossary | Test glossary description | C1 | glossary1 | | label | name | check autolinking of CategoryAutoLinks and CategoryNoLinks text | C1 | label1 | # Log in as admin and enable autolinking filter And I log in as "admin" diff --git a/mod/glossary/tests/behat/search_entries.feature b/mod/glossary/tests/behat/search_entries.feature index c2f682328f0..a9e0939bdd0 100644 --- a/mod/glossary/tests/behat/search_entries.feature +++ b/mod/glossary/tests/behat/search_entries.feature @@ -16,12 +16,11 @@ Feature: Glossary entries can be searched or browsed by alphabet, category, date | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | displayformat | course | idnumber | + | glossary | Test glossary name | Test glossary description | fullwithauthor | C1 | g1 | And I log in as "teacher1" And I follow "Course 1" - And I turn editing mode on - And I add a "Glossary" to section "1" and I fill the form with: - | Name | Test glossary name | - | Description | Test glossary description | And I follow "Test glossary name" And I add a glossary entries category named "The ones I like" And I add a glossary entries category named "All for you" diff --git a/mod/glossary/view.php b/mod/glossary/view.php index c7b83e1ad6c..a616df1cd35 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -73,14 +73,11 @@ if ($page != 0 && $offset == 0) { $offset = $page * $entriesbypage; } -// Get visible tabs for this glossary format. -$glossarytabs = $DB->get_field('glossary_formats', 'showtabs', array('name' => $glossary->displayformat)); -$showtabs = glossary_get_visible_tabs($glossarytabs); - /// setting the default values for the display mode of the current glossary /// only if the glossary is viewed by the first time if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { /// Based on format->defaultmode, we build the defaulttab to be showed sometimes + $showtabs = glossary_get_visible_tabs($dp); switch ($dp->defaultmode) { case 'cat': $defaulttab = GLOSSARY_CATEGORY_VIEW; @@ -122,6 +119,7 @@ if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayf } } else { $defaulttab = GLOSSARY_STANDARD_VIEW; + $showtabs = array($defaulttab); $printpivot = 1; if ( $mode == '' and $hook == '' and $show == '') { $mode = 'letter';