Perhaps another bug in course_menu_block?

Perhaps another bug in course_menu_block?

by Max Woodtli -
Number of replies: 11
Hi

I really enjoy the course_menu-block. But it seems that there is another bug when changing to another language, in my case German.

When I klick on a folder the correspondent course section does not appear. The url in the status bar is for example: http://moodle.kbz-zug.ch/course/view.php?id=11&Thema=4
The link: "show all sections" works correctly.

But when I change to English everything works well. The url then in the status bar is showing:
http://moodle.kbz-zug.ch/course/view.php?id=11&topic=4

Any hints, updates or suggestions?

Thanks a lot

Max
Average of ratings: -
In reply to Max Woodtli

Re: Perhaps another bug in course_menu_block?

by L. Vandijck -
You're right: only when using English does the block function correctly. The reason is that the word 'topic' is translated in all language packs (German = Thema, French = thème, Dutch = onderwerp) but the item is hard coded into the block. So the code is actually looking for the string topic, and not for its value, such as here:
        $sections = get_all_sections($this->course->id); 
        if ($this->course->format == 'topics') {
            $format = 'topic';
        }
        else {
            $format = 'week';

        }
or here
        if ($sectiongroup !== 'tree') {         print_xtree_item('tree',$sectiongroup,ucwords($sectiongroup),
"$CFG->wwwroot/course/view.php?id={$this->course->id}&topic=all");

It is the last one that causes this malfunctioning.
I suppose the solution is to replace the word 'topic' by a reference to the string in the main moodle.php. Maybe something like get_string('topic') ? But I'm afraid as far as PHP programming is concerned I'm completely at a loss.
The team at Humboldt who developed this marvellous add on probably never realised how popular it would become and therefore didn't pay enough attention to the "international" item in their code. I hope they can tweak this in that direction.
In reply to L. Vandijck

Solution for bug in course_menu_block?

by Jan Dierckx -

Better to solve this the other way around. References to pages should not depend on the chosen language. Instead of replacing the word 'topic' with something language specific, make sure everywhere the words 'topic' or 'week' or used when referring to pages. (of course translating them when they are shown to the user)

I haven't tested this but I think the following is a solution:

  • open xtree.php in an editor

  • go to approx. line 240 and find $sectionname = get_string("name$course->format");

  • replace it with the following lines:

    if ($course->format == 'topics') { $sectionname = 'topic'; } else { $sectionname = 'week'; }

In reply to Jan Dierckx

Re: Solution for bug in course_menu_block?

by L. Vandijck -
I have tested it and I'm afraid this is not the solution. After changing the code as you suggested (though strangely enough not in line 240 but in line 56; are we using a different file tree.php ?) the course menu simply stays empty.
Proof that it is clearly related to the word 'topic' itself: when changing the string nametopics in moodle.php to 'topics' in any language pack, course menu behaves as expected.
In reply to L. Vandijck

Re: Solution for bug in course_menu_block?

by Jan Dierckx -
You are right. It is line 56 in xtree.php. Sorry about that.
I had another look and it seems the same line of code is also used in other parts of the block.
I tried changing line 46 (I double checked this one big grin) of block_course_menu.php as well.

$sectionname = get_string("name".$this->course->format);

should read...

if ($this->course->format == 'topics') {
$sectionname = 'topic';
} else {
$sectionname = 'week';
}

Unfortunately $sectionname is also used to name all the untitled topics in a course: 'topic 1', 'topic 2', etc.. Of course here Moodle should use the language string from the chosen language: 'Onderwerp 1', 'Onderwerp 2', etc...

This makes me think your solution of changing the language pack (then you should also change the string 'nameweeks' in moodle.php) is the easiest one after all!
In reply to Max Woodtli

Re: Perhaps another bug in course_menu_block?

by Jeff Graham -
Hi all,

Thanks for bringing this to my attention, and suggesting fixes. While they are not solutions they made fixing this much easier as it pointed out all of the flaws in the code. smile

I think I have fixed this bug. Could you please try the version now in CVS and let me know? I don't use UTF-8 or other international settings and I don't have time to try this out.

The links should now work regardless of language and the unnamed weeks/topics should render with the appropriate language. If they don't please let me know the status. ie. what link is showing in the status bar, and/or whether or not the topics/weeks are showing with the appropriate language.

regards,
Jeff
In reply to Jeff Graham

Re: Perhaps another bug in course_menu_block?

by L. Vandijck -
Hello Jeff,
I've given the version in CVS a try but there's no change in behaviour. Actually, I wonder if CVS really has a new version: most files are still dated 01/07/05 and some 07/07/05, although I updated from CVS about 5 minutes ago.
Regards,
Leo
In reply to L. Vandijck

Re: Perhaps another bug in course_menu_block?

by Jan Dierckx -
Dag Leo,
It usually takes some hours before new updates are available through anonymous cvs. You might have better luck tomorrow.

Hi Jeff,
Thanks for fixing this bug and for writing this nice block in the first place!

In reply to Jan Dierckx

Re: Perhaps another bug in course_menu_block?

by L. Vandijck -
Jan, you're absolutely right. Course menu is working fine now. Thanks for pointing out the time issue concerning CVS updates.
I second your compliment to Jeff!
In reply to Jeff Graham

Re: Perhaps another bug in course_menu_block?

by Jeff Graham -
Hi all,

I added a few more fixes in CVS as mentioned privately by Jan Dierckx.

  • Section items with quotes had slashes displayed preceding the quotes. (FIXED)
  • Additional use of translated string for variable names could cause potential problems with Javascript if characters such as (é , è , ä etc...) are used in the non-US translation. I think this is the last of this problem.
Thanks to Jan for taking the time to carefully review the code and forward detailed information; it saves a lot of time on my part.

regards,
Jeff
In reply to Jeff Graham

Re: Perhaps another bug in course_menu_block?

by Deleted user -

Hello,

would you know if anyone has done a xtree menu for the 'Show course categories' on the home page or 'My courses' from the 'All courses' button. My list is getting quite long now especially after adding sub categories.

Thanks  Gerald

In reply to Jeff Graham

Re: Perhaps another bug in course_menu_block?

by Max Woodtli -
Hi

Thank you for this update. I tested the course_menu_block with "German" and it works now perfectly.

Many thanks again.

regards

Max