Skip to content

Commit

Permalink
MDL-28048 glossary - add multilang support to categories
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 10, 2011
1 parent a938306 commit d5a8ec5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions mod/glossary/edit_form.php
Expand Up @@ -18,6 +18,11 @@ function definition() {
$definitionoptions = $this->_customdata['definitionoptions'];
$attachmentoptions = $this->_customdata['attachmentoptions'];

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);

//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));

Expand All @@ -30,6 +35,9 @@ function definition() {
$mform->addRule('definition_editor', get_string('required'), 'required', null, 'client');

if ($categories = $DB->get_records_menu('glossary_categories', array('glossaryid'=>$glossary->id), 'name ASC', 'id, name')){
foreach ($categories as $id => $name) {
$categories[$id] = format_string($name, true, $fmtoptions);
}
$categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
$categoriesEl = $mform->addElement('select', 'categories', get_string('categories', 'glossary'), $categories);
$categoriesEl->setMultiple(true);
Expand Down
8 changes: 6 additions & 2 deletions mod/glossary/editcategories.php
Expand Up @@ -79,6 +79,10 @@
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();

// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);

if ( $hook >0 ) {

if ( $action == "edit" ) {
Expand Down Expand Up @@ -118,7 +122,7 @@
echo "<p>" . get_string("delete"). " " . get_string("category","glossary"). "</p>";

echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div class=\"boxaligncenter deletecatconfirm\">".format_text($category->name, FORMAT_PLAIN)."<br/>";
echo "<div class=\"boxaligncenter deletecatconfirm\">".format_string($category->name, true, $fmtoptions)."<br/>";

$num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
if ( $num_entries ) {
Expand Down Expand Up @@ -215,7 +219,7 @@
<tr>
<td style="width:80%" align="left">
<?php
echo "<span class=\"bold\">".format_text($category->name, FORMAT_PLAIN)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
echo "<span class=\"bold\">".format_string($category->name, true, $fmtoptions)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
?>
</td>
<td style="width:19%" align="center" class="action">
Expand Down
8 changes: 6 additions & 2 deletions mod/glossary/lib.php
Expand Up @@ -1645,6 +1645,10 @@ function glossary_print_categories_menu($cm, $glossary, $hook, $category) {

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);

echo '<table border="0" width="100%">';
echo '<tr>';

Expand Down Expand Up @@ -1674,15 +1678,15 @@ function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
$selected = $url;
}
}
$menu[$url] = clean_text($currentcategory->name); //Only clean, not filters
$menu[$url] = format_string($currentcategory->name, true, $fmtoptions);
}
}
if ( !$selected ) {
$selected = GLOSSARY_SHOW_NOT_CATEGORISED;
}

if ( $category ) {
echo format_text($category->name, FORMAT_PLAIN);
echo format_string($category->name, true, $fmtoptions);
} else {
if ( $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {

Expand Down
7 changes: 6 additions & 1 deletion mod/glossary/print.php
Expand Up @@ -54,6 +54,10 @@
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);

// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);

$PAGE->set_pagelayout('print');
$PAGE->set_title(get_string("modulenameplural", "glossary"));
$PAGE->set_heading($course->fullname);
Expand Down Expand Up @@ -178,9 +182,11 @@
// Setting the pivot for the current entry
$pivot = $entry->glossarypivot;
$upperpivot = $textlib->strtoupper($pivot);
$pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions));
// Reduce pivot to 1cc if necessary
if ( !$fullpivot ) {
$upperpivot = $textlib->substr($upperpivot, 0, 1);
$pivottoshow = $textlib->substr($pivottoshow, 0, 1);
}

// If there's group break
Expand All @@ -190,7 +196,6 @@
if ( $printpivot ) {
$currentpivot = $upperpivot;

$pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors)
$user = $DB->get_record("user", array("id"=>$entry->userid));
Expand Down
7 changes: 6 additions & 1 deletion mod/glossary/view.php
Expand Up @@ -50,6 +50,10 @@
require_course_login($course->id, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);

// Prepare format_string/text options
$fmtoptions = array(
'context' => $context);

require_once($CFG->dirroot . '/comment/lib.php');
comment::init();

Expand Down Expand Up @@ -417,9 +421,11 @@
// Setting the pivot for the current entry
$pivot = $entry->glossarypivot;
$upperpivot = $textlib->strtoupper($pivot);
$pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions));
// Reduce pivot to 1cc if necessary
if ( !$fullpivot ) {
$upperpivot = $textlib->substr($upperpivot, 0, 1);
$pivottoshow = $textlib->substr($pivottoshow, 0, 1);
}

// if there's a group break
Expand All @@ -433,7 +439,6 @@
echo '<table cellspacing="0" class="glossarycategoryheader">';

echo '<tr>';
$pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors)
echo '<th align="left">';
Expand Down

0 comments on commit d5a8ec5

Please sign in to comment.