mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
MDL-26501 mod_glossary: Allow to specify visible tabs
This commit is contained in:
parent
77679fb2e5
commit
223d6cb3bf
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/glossary/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/glossary"
|
||||
<XMLDB PATH="mod/glossary/db" VERSION="20150602" COMMENT="XMLDB file for Moodle mod/glossary"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -112,6 +112,7 @@
|
||||
<FIELD NAME="popupformatname" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
|
||||
<FIELD NAME="showgroup" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
|
||||
<FIELD NAME="showtabs" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="defaultmode" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="defaulthook" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="sortkey" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
|
@ -68,6 +68,21 @@ function xmldb_glossary_upgrade($oldversion) {
|
||||
// Moodle v2.9.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2015060200) {
|
||||
|
||||
// Define field showtabs to be added to glossary_formats.
|
||||
$table = new xmldb_table('glossary_formats');
|
||||
$field = new xmldb_field('showtabs', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'showgroup');
|
||||
|
||||
// Conditionally launch add field showtabs.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Glossary savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2015060200, 'glossary');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,12 @@ if ( $mode == 'visible' and confirm_sesskey()) {
|
||||
$displayformat->sortkey = $form->sortkey;
|
||||
$displayformat->sortorder = $form->sortorder;
|
||||
|
||||
// Extract visible tabs from array into comma separated list.
|
||||
$visibletabs = implode(',', $form->visibletabs);
|
||||
// Include 'standard' tab by default along with other tabs.
|
||||
// This way we don't run into the risk of users not selecting any tab for displayformat.
|
||||
$displayformat->showtabs = GLOSSARY_STANDARD.','.$visibletabs;
|
||||
|
||||
$DB->update_record("glossary_formats",$displayformat);
|
||||
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
|
||||
die;
|
||||
@ -248,6 +254,37 @@ echo '<table width="90%" align="center" class="generalbox">';
|
||||
<?php print_string("cnfshowgroup", "glossary") ?><br /><br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" width="20%"><label for="visibletabs"><?php print_string("visibletabs", "glossary"); ?></label></td>
|
||||
<td>
|
||||
<?php
|
||||
// Get all glossary tabs.
|
||||
$glossarytabs = glossary_get_all_tabs();
|
||||
// Extract showtabs value in an array.
|
||||
$visibletabs = glossary_get_visible_tabs($displayformat->showtabs);
|
||||
$size = min(10, count($glossarytabs));
|
||||
?>
|
||||
<select id="visibletabs" name="visibletabs[]" size="<?php echo $size ?>" multiple="multiple">
|
||||
<?php
|
||||
$selected = "";
|
||||
foreach ($glossarytabs as $tabkey => $tabvalue) {
|
||||
if (in_array($tabkey, $visibletabs)) {
|
||||
?>
|
||||
<option value="<?php echo $tabkey ?>" selected="selected"><?php echo $tabvalue ?></option>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<option value="<?php echo $tabkey ?>"><?php echo $tabvalue ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="60%">
|
||||
<?php print_string("cnftabs", "glossary") ?><br/><br/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>" /></td>
|
||||
|
@ -80,6 +80,7 @@ $string['cnfshowgroup'] = 'Specify if the group break should be shown or not.';
|
||||
$string['cnfsortkey'] = 'Select the sorting key by default.';
|
||||
$string['cnfsortorder'] = 'Select the sorting order by default.';
|
||||
$string['cnfstudentcanpost'] = 'Define if the students can or cannot post entries by default';
|
||||
$string['cnftabs'] = 'Select visible tabs for this glossary format';
|
||||
$string['comment'] = 'Comment';
|
||||
$string['commentdeleted'] = 'The comment has been deleted.';
|
||||
$string['comments'] = 'Comments';
|
||||
@ -290,6 +291,7 @@ $string['studentcanpost'] = 'Students can add entries';
|
||||
$string['totalentries'] = 'Total entries';
|
||||
$string['usedynalink'] = 'Automatically link glossary entries';
|
||||
$string['usedynalink_help'] = 'If site-wide glossary auto-linking has been enabled by an administrator and this setting is enabled, the "Add a new entry" form includes the option to automatically link the entry wherever the concept words and phrases appear throughout the rest of the course.';
|
||||
$string['visibletabs'] = 'Visible tabs';
|
||||
$string['waitingapproval'] = 'Waiting approval';
|
||||
$string['warningstudentcapost'] = '(Applies only if the glossary is not the main one)';
|
||||
$string['withauthor'] = 'Concepts with author';
|
||||
|
@ -38,6 +38,17 @@ define("GLOSSARY_IMPORT_VIEW", 5);
|
||||
define("GLOSSARY_EXPORT_VIEW", 6);
|
||||
define("GLOSSARY_APPROVAL_VIEW", 7);
|
||||
|
||||
// Glossary tabs.
|
||||
define('GLOSSARY_STANDARD', 'standard');
|
||||
define('GLOSSARY_AUTHOR', 'author');
|
||||
define('GLOSSARY_CATEGORY', 'category');
|
||||
define('GLOSSARY_DATE', 'date');
|
||||
|
||||
// Glossary displayformats.
|
||||
define('GLOSSARY_CONTINUOUS', 'continuous');
|
||||
define('GLOSSARY_DICTIONARY', 'dictionary');
|
||||
define('GLOSSARY_FULLWITHOUTAUTHOR', 'fullwithoutauthor');
|
||||
|
||||
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @global object
|
||||
@ -908,6 +919,10 @@ function glossary_get_available_formats() {
|
||||
$gf->visible = 1;
|
||||
$DB->insert_record("glossary_formats",$gf);
|
||||
}
|
||||
|
||||
if(is_null($rec->showtabs)) {
|
||||
glossary_set_default_visible_tabs($rec);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3044,11 +3059,29 @@ function glossary_get_completion_state($course,$cm,$userid,$type) {
|
||||
}
|
||||
|
||||
function glossary_extend_navigation($navigation, $course, $module, $cm) {
|
||||
global $CFG;
|
||||
$navigation->add(get_string('standardview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'letter')));
|
||||
$navigation->add(get_string('categoryview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'cat')));
|
||||
$navigation->add(get_string('dateview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'date')));
|
||||
$navigation->add(get_string('authorview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'author')));
|
||||
global $CFG, $DB;
|
||||
|
||||
$glossarytabs = $DB->get_field('glossary_formats', 'showtabs', 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);
|
||||
|
||||
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')));
|
||||
break;
|
||||
case GLOSSARY_CATEGORY :
|
||||
$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')));
|
||||
break;
|
||||
case GLOSSARY_AUTHOR :
|
||||
$navigation->add(get_string('authorview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id' => $cm->id, 'mode' => 'author')));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3194,3 +3227,53 @@ function glossary_page_type_list($pagetype, $parentcontext, $currentcontext) {
|
||||
'mod-glossary-edit'=>get_string('page-mod-glossary-edit', 'glossary'));
|
||||
return $module_pagetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of all glossary tabs.
|
||||
* @return array
|
||||
* @throws coding_exception
|
||||
*/
|
||||
function glossary_get_all_tabs() {
|
||||
|
||||
return array (
|
||||
GLOSSARY_AUTHOR => get_string('authorview', 'glossary'),
|
||||
GLOSSARY_CATEGORY => get_string('categoryview', 'glossary'),
|
||||
GLOSSARY_DATE => get_string('dateview', 'glossary')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set 'showtabs' value for glossary formats
|
||||
* @param $glossaryformat
|
||||
*/
|
||||
function glossary_set_default_visible_tabs($glossaryformat) {
|
||||
global $DB;
|
||||
|
||||
switch($glossaryformat->name) {
|
||||
case GLOSSARY_CONTINUOUS:
|
||||
$showtabs = 'standard,category,date';
|
||||
break;
|
||||
case GLOSSARY_DICTIONARY:
|
||||
$showtabs = 'standard';
|
||||
break;
|
||||
case GLOSSARY_FULLWITHOUTAUTHOR:
|
||||
$showtabs = 'standard,category,date';
|
||||
break;
|
||||
default:
|
||||
$showtabs = 'standard,author,category,date';
|
||||
break;
|
||||
}
|
||||
|
||||
$DB->set_field('glossary_formats', 'showtabs', $showtabs, array('id' => $glossaryformat->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert 'showtabs' string to array
|
||||
* @param $glossarytabs
|
||||
* @return array
|
||||
*/
|
||||
function glossary_get_visible_tabs($glossarytabs) {
|
||||
$showtabs = preg_split('/,/', $glossarytabs, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
return $showtabs;
|
||||
}
|
||||
|
@ -20,22 +20,32 @@
|
||||
$tab = $defaulttab;
|
||||
}
|
||||
|
||||
// Get visible tabs for the format and check tab needs to be displayed.
|
||||
$dt = glossary_get_visible_tabs($dp->showtabs);
|
||||
|
||||
$browserow[] = new tabobject(GLOSSARY_STANDARD_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=letter',
|
||||
get_string('standardview', 'glossary'));
|
||||
if (in_array(GLOSSARY_STANDARD, $dt)) {
|
||||
$browserow[] = new tabobject(GLOSSARY_STANDARD_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=letter',
|
||||
get_string('standardview', 'glossary'));
|
||||
}
|
||||
|
||||
$browserow[] = new tabobject(GLOSSARY_CATEGORY_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=cat',
|
||||
get_string('categoryview', 'glossary'));
|
||||
if (in_array(GLOSSARY_CATEGORY, $dt)) {
|
||||
$browserow[] = new tabobject(GLOSSARY_CATEGORY_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=cat',
|
||||
get_string('categoryview', 'glossary'));
|
||||
}
|
||||
|
||||
$browserow[] = new tabobject(GLOSSARY_DATE_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=date',
|
||||
get_string('dateview', 'glossary'));
|
||||
if (in_array(GLOSSARY_DATE, $dt)) {
|
||||
$browserow[] = new tabobject(GLOSSARY_DATE_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=date',
|
||||
get_string('dateview', 'glossary'));
|
||||
}
|
||||
|
||||
$browserow[] = new tabobject(GLOSSARY_AUTHOR_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=author',
|
||||
get_string('authorview', 'glossary'));
|
||||
if (in_array(GLOSSARY_AUTHOR, $dt)) {
|
||||
$browserow[] = new tabobject(GLOSSARY_AUTHOR_VIEW,
|
||||
$CFG->wwwroot.'/mod/glossary/view.php?id='.$id.'&mode=author',
|
||||
get_string('authorview', 'glossary'));
|
||||
}
|
||||
|
||||
if ($tab < GLOSSARY_STANDARD_VIEW || $tab > GLOSSARY_AUTHOR_VIEW) { // We are on second row
|
||||
$inactive = array('edit');
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015051100; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2015060200; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2015050500; // Requires this Moodle version
|
||||
$plugin->component = 'mod_glossary'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
@ -73,6 +73,10 @@ 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)) ) {
|
||||
@ -80,12 +84,30 @@ if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayf
|
||||
switch ($dp->defaultmode) {
|
||||
case 'cat':
|
||||
$defaulttab = GLOSSARY_CATEGORY_VIEW;
|
||||
|
||||
// Handle defaultmode if 'category' tab is disabled. Fallback to 'standard' tab.
|
||||
if (!in_array(GLOSSARY_CATEGORY, $showtabs)) {
|
||||
$defaulttab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'date':
|
||||
$defaulttab = GLOSSARY_DATE_VIEW;
|
||||
|
||||
// Handle defaultmode if 'date' tab is disabled. Fallback to 'standard' tab.
|
||||
if (!in_array(GLOSSARY_DATE, $showtabs)) {
|
||||
$defaulttab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'author':
|
||||
$defaulttab = GLOSSARY_AUTHOR_VIEW;
|
||||
|
||||
// Handle defaultmode if 'author' tab is disabled. Fallback to 'standard' tab.
|
||||
if (!in_array(GLOSSARY_AUTHOR, $showtabs)) {
|
||||
$defaulttab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$defaulttab = GLOSSARY_STANDARD_VIEW;
|
||||
@ -159,6 +181,12 @@ break;
|
||||
|
||||
case 'cat': /// Looking for a certain cat
|
||||
$tab = GLOSSARY_CATEGORY_VIEW;
|
||||
|
||||
// Validation - we don't want to display 'category' tab if it is disabled.
|
||||
if (!in_array(GLOSSARY_CATEGORY, $showtabs)) {
|
||||
$tab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
if ( $hook > 0 ) {
|
||||
$category = $DB->get_record("glossary_categories", array("id"=>$hook));
|
||||
}
|
||||
@ -182,6 +210,12 @@ break;
|
||||
|
||||
case 'date':
|
||||
$tab = GLOSSARY_DATE_VIEW;
|
||||
|
||||
// Validation - we dont want to display 'date' tab if it is disabled.
|
||||
if (!in_array(GLOSSARY_DATE, $showtabs)) {
|
||||
$tab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
if ( !$sortkey ) {
|
||||
$sortkey = 'UPDATE';
|
||||
}
|
||||
@ -192,6 +226,12 @@ break;
|
||||
|
||||
case 'author': /// Looking for entries, browsed by author
|
||||
$tab = GLOSSARY_AUTHOR_VIEW;
|
||||
|
||||
// Validation - we dont want to display 'author' tab if it is disabled.
|
||||
if (!in_array(GLOSSARY_AUTHOR, $showtabs)) {
|
||||
$tab = GLOSSARY_STANDARD_VIEW;
|
||||
}
|
||||
|
||||
if ( !$hook ) {
|
||||
$hook = 'ALL';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user