Moodle

Making a Help button available for new plugin questions export/import formats.

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Questions
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Moodle Improvement
------------------
Moodle Questions.
Making a Help button available for new plugin questions export/import formats.
-----------------
See forum discussion: http://moodle.org/mod/forum/discuss.php?d=94739
-----------------
Work done so far:

1- in file lib/moodlelib.php added
'qformat_' => array('question/format') (as suggested by Tim in forum discussion)

2- in file question/format.php added
function has_import_help_file() {
return false;
}
function has_export_help_file() {
return false;
}
NOTE.- New plugins will have to declare their existence of their help file for import or export as true.

3- in file lib/questionlib.php
introduced $hashelpfile, $fileformat and $formatname, now returns $fileformatnames as an array of arrays. See attached patch file for details

4- in file questions/export_form.php
Added setHelpButton for those plugin formats which have their own lang files... See patch file for more details...

NOTE.- If we managed to get the export_form new help buttons to work, similar changes will have to be made to file import_form.php of course.
-----------------
I am currently stumped by the following problem...
I am testing this with my own clozejr export format type, and I have also provisionally made XHTML format a "new" plugin format for testing purposes.
The necessary Help buttons are correctly created for each plugin format type not included in the moodle distribution.
They are displayed when I dump the $mform array and they do work as expected when clicked (see attached screenshot) but... the individual radio buttons Help buttons are **not displayed** within the $radioarray,'format' group!

DIAGNOSTIC

It seems that it is not possible for moodleforms to attach Help buttons to those radio buttons because they all have the same name 'format'... even though those Help buttons are indeed present in $mform...

SOLUTIONS

One solution would be to give each individual button a different name (instead of naming them all 'format'), e.g. name them after their formatname. Plus, they should be added as single elements to $mform, not as a group.
RESULT: this works as far as the individual Help buttons are displayed where relevant, but... it does not work because then those radio buttons are not inside a group, and can all be clicked... And even when one radio button only is clicked, its name is sent as form data, instead of the expected 'format' key, so things go wrong in question/export.php...

WISHED SOLUTION (if it exists)...
moodle forms should display Help buttons which have been correctly created even if those buttons reside within groups and even if they have identical names (maybe Help buttons should be lined to IDs, not names???)

Joseph

  1. question_format_help_patch_2.txt
    20/Apr/08 9:40 PM
    7 kB
    Joseph Rézeau
  2. question_format_help_patch.txt
    19/Apr/08 10:31 PM
    6 kB
    Joseph Rézeau
  1. screenshot-1.jpg
    49 kB
    19/Apr/08 10:32 PM
  2. screenshot-2.jpg
    25 kB
    20/Apr/08 9:39 PM

Issue Links

Activity

Hide
Joseph Rézeau added a comment -

I have finally found a solution to solve this conundrum.

In file question/export_form.php, for each relevant format plugin, I retrieve the Help button code from current($radioarray)>_helpbutton and add it to current($radioarray)>_text... That way, the Helpbutton is added to the right of the plugin's name. Not so neat as if it could be added to the left of its radio button, but... it works.

I am attaching all the relevant patches (for 5 moodle files) in question_format_help_patch_2.txt. And screenshot-2 shows the result...

I have made all of those changes on my moodle test site at http://rezeau.info/moodle/ BE PATIENT, my test site is rather slow...
log in as teacher1, password teacher1, go to Demo course, go to Administration / Questions database. Go to category Rezeau, sub-category What is Moodle?.
Click on the Export questions to file tab, see the Help buttons for the clozejr plugin (and notice that for demo purposes XHTML Format has been provided with its own Help file too).
In the Import questions from file tab, the Learnwise format has been provided with its own Help files too...

Tim, could you please test these proposed changes and commit to 1.9 and HEAD if you agree that they work?

Thanks in advance,
Joseph

Show
Joseph Rézeau added a comment - I have finally found a solution to solve this conundrum. In file question/export_form.php, for each relevant format plugin, I retrieve the Help button code from current($radioarray)>_helpbutton and add it to current($radioarray)>_text... That way, the Helpbutton is added to the right of the plugin's name. Not so neat as if it could be added to the left of its radio button, but... it works. I am attaching all the relevant patches (for 5 moodle files) in question_format_help_patch_2.txt. And screenshot-2 shows the result... I have made all of those changes on my moodle test site at http://rezeau.info/moodle/ BE PATIENT, my test site is rather slow... log in as teacher1, password teacher1, go to Demo course, go to Administration / Questions database. Go to category Rezeau, sub-category What is Moodle?. Click on the Export questions to file tab, see the Help buttons for the clozejr plugin (and notice that for demo purposes XHTML Format has been provided with its own Help file too). In the Import questions from file tab, the Learnwise format has been provided with its own Help files too... Tim, could you please test these proposed changes and commit to 1.9 and HEAD if you agree that they work? Thanks in advance, Joseph
Hide
Joseph Rézeau added a comment -

A working solution!

Show
Joseph Rézeau added a comment - A working solution!
Hide
Joseph Rézeau added a comment -

Added Howard to the watchers list. Howard, could you test this please?

Show
Joseph Rézeau added a comment - Added Howard to the watchers list. Howard, could you test this please?
Hide
Howard Miller added a comment -

Hi,

I'm just back from the USA and too jet-lagged to do anything that matters But, yes, I'll catch up with this as soon as I can.

Show
Howard Miller added a comment - Hi, I'm just back from the USA and too jet-lagged to do anything that matters But, yes, I'll catch up with this as soon as I can.
Hide
Howard Miller added a comment -

This all sounds fair to me. I'm happy to test it, but it won't be today (sorry - not enough hours for anything at the moment). My only slight worry is that from a user's point of view there are now two places to get help for no apparent reason. I guess the "big" answer is that there is no facility in the help infrastructure to aggregate help files for optional plugins - is this worth thinking about?

Please make sure that if this goes in there is some explanation in the docs.

Show
Howard Miller added a comment - This all sounds fair to me. I'm happy to test it, but it won't be today (sorry - not enough hours for anything at the moment). My only slight worry is that from a user's point of view there are now two places to get help for no apparent reason. I guess the "big" answer is that there is no facility in the help infrastructure to aggregate help files for optional plugins - is this worth thinking about? Please make sure that if this goes in there is some explanation in the docs.
Hide
Joseph Rézeau added a comment -

Thanks Howard.
You are quite right about the "two places to get help from". The problem is different for "mod plugins" which have their own lang files in their own folder. Or the question types which can also have their own help files. At the moment, however, the existence of "3rd-party" question formats (used by questions import/export) had not been imagined, hence the problem... for which I have a solution.
Joseph

Show
Joseph Rézeau added a comment - Thanks Howard. You are quite right about the "two places to get help from". The problem is different for "mod plugins" which have their own lang files in their own folder. Or the question types which can also have their own help files. At the moment, however, the existence of "3rd-party" question formats (used by questions import/export) had not been imagined, hence the problem... for which I have a solution. Joseph
Hide
Howard Miller added a comment -

Thinking some more about this, can we simply have a help button per-format alongside each select box. I don't think it would be too cluttered and it would make the issue a lot easier to solve. Import/export plugins can then have a lang subdirectory and be added to the language pack search regime making them properly pluggable.

Show
Howard Miller added a comment - Thinking some more about this, can we simply have a help button per-format alongside each select box. I don't think it would be too cluttered and it would make the issue a lot easier to solve. Import/export plugins can then have a lang subdirectory and be added to the language pack search regime making them properly pluggable.
Hide
Tim Hunt added a comment -

Sounds like a good solution to me.

Show
Tim Hunt added a comment - Sounds like a good solution to me.
Hide
Joseph Rézeau added a comment -

Howard, your solution (a help button per-format alongside each select box) sounds OK with me too. Will you be working at it any time soon?
Joseph

Show
Joseph Rézeau added a comment - Howard, your solution (a help button per-format alongside each select box) sounds OK with me too. Will you be working at it any time soon? Joseph
Hide
Howard Miller added a comment -

Ok... I'm going to change this to 2.0 as it will mean quite a lot of messing with the help files structure. This sounds do-able now though.

Show
Howard Miller added a comment - Ok... I'm going to change this to 2.0 as it will mean quite a lot of messing with the help files structure. This sounds do-able now though.
Hide
Howard Miller added a comment -

Mmm..... first problem. I can't see any way (using the formslib anyway) of attaching help icons to discrete radio buttons. The radio button "thing" seems to be one form element

Show
Howard Miller added a comment - Mmm..... first problem. I can't see any way (using the formslib anyway) of attaching help icons to discrete radio buttons. The radio button "thing" seems to be one form element
Hide
Joseph Rézeau added a comment -

Howard,
Maybe this is the problem I described earlier:
DIAGNOSTIC
> It seems that it is not possible for moodleforms to attach Help buttons to those radio buttons because they all have the same name 'format'... even though those Help buttons are indeed present in $mform...
Joseph

Show
Joseph Rézeau added a comment - Howard, Maybe this is the problem I described earlier: DIAGNOSTIC > It seems that it is not possible for moodleforms to attach Help buttons to those radio buttons because they all have the same name 'format'... even though those Help buttons are indeed present in $mform... Joseph
Hide
Howard Miller added a comment -

Ahh I see. I'm no expert on the formslib, but as setHelpButton is overidden by each element type it may not be too hard to add this functionality to formslib. Maybe Tomorrow's job!

Show
Howard Miller added a comment - Ahh I see. I'm no expert on the formslib, but as setHelpButton is overidden by each element type it may not be too hard to add this functionality to formslib. Maybe Tomorrow's job!
Hide
Howard Miller added a comment -

Ok, that's the formslib stuff sorted out. It now displays the help icon alongside the radio button.

My current sticking point is that I can't understand how the function places_to_search_for_lang_strings() in moodleib is supposed to work for help files. I'm not convinced it does Anybody understand what this is supposed to do?

Show
Howard Miller added a comment - Ok, that's the formslib stuff sorted out. It now displays the help icon alongside the radio button. My current sticking point is that I can't understand how the function places_to_search_for_lang_strings() in moodleib is supposed to work for help files. I'm not convinced it does Anybody understand what this is supposed to do?
Hide
Joseph Rézeau added a comment -

the function places_to_search_for_lang_strings() ... is it not supposed to work for langstrings only, not the Help files? I cannot remember from when I was working on this.
Maybe Tim has an idea?
Joseph

Show
Joseph Rézeau added a comment - the function places_to_search_for_lang_strings() ... is it not supposed to work for langstrings only, not the Help files? I cannot remember from when I was working on this. Maybe Tim has an idea? Joseph
Hide
Howard Miller added a comment -

It says it works for help files. It probably does. My brain is melted from looking at the formslib. Tomorrow will do

Show
Howard Miller added a comment - It says it works for help files. It probably does. My brain is melted from looking at the formslib. Tomorrow will do
Hide
Tim Hunt added a comment -

Well, places_to_search_for_lang_strings is called from two places: get_string in lib/moodlelib.php and help.php. So it is used for help files.

Show
Tim Hunt added a comment - Well, places_to_search_for_lang_strings is called from two places: get_string in lib/moodlelib.php and help.php. So it is used for help files.
Hide
Howard Miller added a comment -

I'm not getting anyway with this. I just can't see how to add the import/export formats to the language search locations. There's no documentation for that feature (Grrrrrr.....) and I just don't see what the code is trying to do.

Show
Howard Miller added a comment - I'm not getting anyway with this. I just can't see how to add the import/export formats to the language search locations. There's no documentation for that feature (Grrrrrr.....) and I just don't see what the code is trying to do.
Hide
Tim Hunt added a comment -

Add something like

'qformat_' => array('question/format'),

to places_to_search_for_lang_strings.

Then put in a call to print a help button button 'qformat_myformat', or something like that.

Then in help.php, inside the two while loops, just after it sets $filepath = ..., put in the debugging line

print_object($filepath);

Then go and click the help button you just inserted, and you should be able to see exactly where it searches, and so where you have to put the help file.

Or you could look at another plugin that does this. For example I made it work in http://cvs.moodle.org/contrib/plugins/question/type/opaque/. Look at the structure of the lang folder there, and the print help button calls.

Finally, once you understand it, you can add to the docs. The best docs currently is here: http://docs.moodle.org/en/Translation#Translation_of_contributed_code

Show
Tim Hunt added a comment - Add something like 'qformat_' => array('question/format'), to places_to_search_for_lang_strings. Then put in a call to print a help button button 'qformat_myformat', or something like that. Then in help.php, inside the two while loops, just after it sets $filepath = ..., put in the debugging line print_object($filepath); Then go and click the help button you just inserted, and you should be able to see exactly where it searches, and so where you have to put the help file. Or you could look at another plugin that does this. For example I made it work in http://cvs.moodle.org/contrib/plugins/question/type/opaque/. Look at the structure of the lang folder there, and the print help button calls. Finally, once you understand it, you can add to the docs. The best docs currently is here: http://docs.moodle.org/en/Translation#Translation_of_contributed_code
Hide
Howard Miller added a comment -

Thanks Tim. I was looking at qtype_. Am I right in thinking that this is only partially implemented? There are only two entries in help that look like qtype_something (qtype_multichoice and qtype_truefalse). I was also a bit surprised that each help flle was now inside it's own qtype_ directory. My issue is that I want it to find the help for non-core formats automagically, so they all need to follow the same/correct format. Nightmare

Show
Howard Miller added a comment - Thanks Tim. I was looking at qtype_. Am I right in thinking that this is only partially implemented? There are only two entries in help that look like qtype_something (qtype_multichoice and qtype_truefalse). I was also a bit surprised that each help flle was now inside it's own qtype_ directory. My issue is that I want it to find the help for non-core formats automagically, so they all need to follow the same/correct format. Nightmare
Hide
Howard Miller added a comment -

"Sound of penny dropping"... of course, these things have to be all complete discrete "modules" now, so for help the the file will probably be index.php (say) and the module is qformat_aiken. All the formats need their own folder in help Fair enough!

Show
Howard Miller added a comment - "Sound of penny dropping"... of course, these things have to be all complete discrete "modules" now, so for help the the file will probably be index.php (say) and the module is qformat_aiken. All the formats need their own folder in help Fair enough!
Hide
Howard Miller added a comment -

I'm going to check with Koen if this will upset him/anybody if I start relocating all those help files.

Show
Howard Miller added a comment - I'm going to check with Koen if this will upset him/anybody if I start relocating all those help files.
Hide
Howard Miller added a comment -

Ok, this now should all work. I have given the plugins/question/format/questionmark format plug a suitably configured help file to demonstrate how it can be used.

Show
Howard Miller added a comment - Ok, this now should all work. I have given the plugins/question/format/questionmark format plug a suitably configured help file to demonstrate how it can be used.
Hide
Howard Miller added a comment -

Whoops - qti2 format doesn't work. Digits are not permitted in module names. I'll need to change the name of the format.

Show
Howard Miller added a comment - Whoops - qti2 format doesn't work. Digits are not permitted in module names. I'll need to change the name of the format.
Hide
Tim Hunt added a comment -

Howard, you are right that the help stuff is only partially implemented for question types. That was intentional, so as not to break backwards compatibility. Have a look at the code in get_heading in /question/type/questiontype.php.

Because of the issue that moving stuff might annoy translators (and becuase it is a boring, thankless task!) I have been slow to re-arrange the lang strings for existing question types. Let me know what you find out about moving the question formats help, in case I do ever decide to do the same for the question types.

Show
Tim Hunt added a comment - Howard, you are right that the help stuff is only partially implemented for question types. That was intentional, so as not to break backwards compatibility. Have a look at the code in get_heading in /question/type/questiontype.php. Because of the issue that moving stuff might annoy translators (and becuase it is a boring, thankless task!) I have been slow to re-arrange the lang strings for existing question types. Let me know what you find out about moving the question formats help, in case I do ever decide to do the same for the question types.
Hide
Joseph Rézeau added a comment -

Howard, thanks for all your hard work. I will test it on 2.0 ASAP.
Tim and Howard, the problem with relocating Help files is the following, as far as I can see:

1- standard moodle distribution modules have their lang string and Help files in moodle/lang/...
2- third-party modules & plugins have their own lang string and Help files sitting in their own folders.
3- option 2 is also used by 3rd-party question types, which is OK

Ideally formats should follow the same pattern as 3rd-party modules and plugins. But all those which are at the moment part of core Moodle files are considered as "Moodle core". Actually, all import/export formats should behave like non-core modules, and do have their own lang files inside their own folders.

I agree that this is going to be disliked by language maintainers, but it is certainly the logical way to go...

Joseph

Show
Joseph Rézeau added a comment - Howard, thanks for all your hard work. I will test it on 2.0 ASAP. Tim and Howard, the problem with relocating Help files is the following, as far as I can see: 1- standard moodle distribution modules have their lang string and Help files in moodle/lang/... 2- third-party modules & plugins have their own lang string and Help files sitting in their own folders. 3- option 2 is also used by 3rd-party question types, which is OK Ideally formats should follow the same pattern as 3rd-party modules and plugins. But all those which are at the moment part of core Moodle files are considered as "Moodle core". Actually, all import/export formats should behave like non-core modules, and do have their own lang files inside their own folders. I agree that this is going to be disliked by language maintainers, but it is certainly the logical way to go... Joseph
Hide
Howard Miller added a comment -

changed qti2 to qti_two as required.

Show
Howard Miller added a comment - changed qti2 to qti_two as required.
Hide
Tim Hunt added a comment -

Good work. Particularly on updating the docs.

Show
Tim Hunt added a comment - Good work. Particularly on updating the docs.
Hide
Koen Roggemans added a comment -

My thoughts: The main problem I see with moving the lang files so they work as 3th party modules, is that translators are not able to put the langfiles there, since no rights in all those CVS folders. As a result, they will end up in the langpack anyway, like now with a lot of langfiles for popular 3th party modules (book, questionnaire, ...).

Show
Koen Roggemans added a comment - My thoughts: The main problem I see with moving the lang files so they work as 3th party modules, is that translators are not able to put the langfiles there, since no rights in all those CVS folders. As a result, they will end up in the langpack anyway, like now with a lot of langfiles for popular 3th party modules (book, questionnaire, ...).
Hide
Tim Hunt added a comment -

For things in core moodle, the lang files should stay in lang. Moving them into the plugin folder only affects third-party plugins.

I think what Howard is saying is that the files need to me moved within lang/en_utf8/help.

Show
Tim Hunt added a comment - For things in core moodle, the lang files should stay in lang. Moving them into the plugin folder only affects third-party plugins. I think what Howard is saying is that the files need to me moved within lang/en_utf8/help.
Hide
Howard Miller added a comment -

Yes - that's what I was saying In no way do I think that the language files should be moved out of the normal language folders.

On reflection, the situation with the import/export plugins is probably unusual. The help is generated for all the plugins by code outside of the plugin itself. So the structure for the language files had to be all or nothing. I had to move all the existing help to qformat_xxxxx style. I would have thought that this is rarely the case for other plugins - this point confused me for a couple of hours as it happened

Show
Howard Miller added a comment - Yes - that's what I was saying In no way do I think that the language files should be moved out of the normal language folders. On reflection, the situation with the import/export plugins is probably unusual. The help is generated for all the plugins by code outside of the plugin itself. So the structure for the language files had to be all or nothing. I had to move all the existing help to qformat_xxxxx style. I would have thought that this is rarely the case for other plugins - this point confused me for a couple of hours as it happened
Hide
Joseph Rézeau added a comment -

I have just tested this fix with my clozejr format plugin and am sorry to report that it does not work.
The Help button is displayed, with this link:
.../moodle/help.php?module=qformat_clozejr&file=clozejr.html&forcelang=
I have installed the help file in
...\moodle\question\format\clozejr\lang\en_utf8\help\qformat_clozejr\clozejr.html
But moodle does not find it...

If I installed my clozejr.html help file in
...\moodle\lang\en_utf8\help\qformat_clozejr\clozejr.html
of course it would work, but that's precisely what is not allowed for a third-party plugin, its help files should reside within its own directory.

Joseph

Show
Joseph Rézeau added a comment - I have just tested this fix with my clozejr format plugin and am sorry to report that it does not work. The Help button is displayed, with this link: .../moodle/help.php?module=qformat_clozejr&file=clozejr.html&forcelang= I have installed the help file in ...\moodle\question\format\clozejr\lang\en_utf8\help\qformat_clozejr\clozejr.html But moodle does not find it... If I installed my clozejr.html help file in ...\moodle\lang\en_utf8\help\qformat_clozejr\clozejr.html of course it would work, but that's precisely what is not allowed for a third-party plugin, its help files should reside within its own directory. Joseph
Hide
Tim Hunt added a comment -

Rather confusingly, you need to put the help file in

...\moodle\question\format\clozejr\lang\en_utf8\help\clozejr\clozejr.html

instead of

...\moodle\question\format\clozejr\lang\en_utf8\help\qformat_clozejr\clozejr.html

Show
Tim Hunt added a comment - Rather confusingly, you need to put the help file in ...\moodle\question\format\clozejr\lang\en_utf8\help\clozejr\clozejr.html instead of ...\moodle\question\format\clozejr\lang\en_utf8\help\qformat_clozejr\clozejr.html
Hide
Joseph Rézeau added a comment -

Sorry, just read the Documentation after testing Howard's fix...
It does work, without the prefix as stated in the doc: "the help directory name should not have the type_ part of the module name (this might be a bug really!)"
Closing bug report again,
Joseph

Show
Joseph Rézeau added a comment - Sorry, just read the Documentation after testing Howard's fix... It does work, without the prefix as stated in the doc: "the help directory name should not have the type_ part of the module name (this might be a bug really!)" Closing bug report again, Joseph
Hide
Tim Hunt added a comment -

Well, it is inconsistent and weird, but it has been like that for a while now, so I think it would cause more pain to change it at this point, than to live with it. However, it might be worth proposing this in the Languages forum. Enough other things will be changing for Moodle 2.0 that requiring people to move the help files in their plugins would be a small addition, so this might be the moment to seize.

Show
Tim Hunt added a comment - Well, it is inconsistent and weird, but it has been like that for a while now, so I think it would cause more pain to change it at this point, than to live with it. However, it might be worth proposing this in the Languages forum. Enough other things will be changing for Moodle 2.0 that requiring people to move the help files in their plugins would be a small addition, so this might be the moment to seize.
Hide
Howard Miller added a comment -

Phew!

Yes.... I suspect that's a bit of a bug in the language search thing. It's the kind of bug you can't change easily I suppose

Show
Howard Miller added a comment - Phew! Yes.... I suspect that's a bit of a bug in the language search thing. It's the kind of bug you can't change easily I suppose
Hide
Tim Hunt added a comment -
Show
Tim Hunt added a comment - OK, I posted http://moodle.org/mod/forum/discuss.php?d=101422

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: