Need to add Help button for 3rd-party Questions Export format

Need to add Help button for 3rd-party Questions Export format

by Joseph Rézeau -
Number of replies: 7
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi,
I am currently re-working my clozejr small hack plugin for 1.8 and 1.9. I would like to add a Help button to explain its use, on the Export questions to file page. Unfortunately this does not seem possible because there is no "hook" to make questions/export.php aware of the need for Help buttons related to the various export formats available. At the moment there is only one Help file, which contains a description of all export (and import) formats available in core, no provision is made for Help for extra formats. Strangely, the same Help file is invoked by the two Help icons on that page (see screen shot).
Suggested changes:
maybe retain the General Help icon referring to the Help file with description of all "core" Moodle export formats
replace the other Help icon with either one Help icon referring to separate Help files for each format or, at least have the possibility to have a Help icon (and Help file) for those formats which are not in Moodle core (e.g. my own clozejr format).
I have tried to insert one Helpbutton for each format in the question/export_form.php file, but cannot get it to work, something like:
$n = 0;
foreach ($fileformatnames as $id => $fileformatname) {
$radioarray[] = &MoodleQuickForm::createElement('radio','format','',$fileformatname,$id);
$mform->setHelpButton($radioarray[$n], array($fileformatname, get_string('exportcategory','question'), 'quiz'));
$n++;
}
The correct path to Help files located within the specific format folder should be specified for the setHelpButton, of course.
Any suggestions?
Joseph

Attachment image00.jpg
Average of ratings: -
In reply to Joseph Rézeau

Re: Need to add Help button for 3rd-party Questions Export format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Seems like a reasonable idea.

There does not seem to be a prefix for question import formats in places_to_search_for_lang_strings.

Should we use qformat? That is, add

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

to function places_to_search_for_lang_strings in moodlelib.php?
In reply to Tim Hunt

Re: Need to add Help button for 3rd-party Questions Export format

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Tim,
Thanks for your suggestion.
1-
On my local moodle test site I have added 'qformat_' => array('question/format'), to function places_to_search_for_lang_strings in moodlelib.php. This makes the lang files within my own question/format/clozejr lang folder accessible, so it is fine.
Would you be willing to commit this small addition to moodle 1.8, 1.9 and Head?
2-
However, I am still stuck in the question/export_form.php file, as mentioned in my original post. I can add just one Help reference (to clozejr) and it works fine.
//--------------------------------------------------------------------------------
$mform->addElement('header','fileformat',get_string('fileformat','quiz'));
$fileformatnames = get_import_export_formats('export');
$radioarray = array();
foreach ($fileformatnames as $id => $fileformatname) {
$radioarray[] = &MoodleQuickForm::createElement('radio',$fileformatname,'',$fileformatname,$id);
}
$mform->addGroup($radioarray,'format','',array('<br />'),false);
$fileformatname = 'clozejr';
$mform->setHelpButton('format', array('export', get_string('export', 'qformat_'.$fileformatname), 'qformat_'.$fileformatname));
$mform->addRule('format',null,'required',null,'client');
----------------
But, to provide individual Help buttons for other, new export formats which might become available, we would need something like:
------
//--------------------------------------------------------------------------------
$mform->addElement('header','fileformat',get_string('fileformat','quiz'));
$fileformatnames = get_import_export_formats('export');
$radioarray = array();
foreach ($fileformatnames as $id => $fileformatname) {
$radioarray[] = &MoodleQuickForm::createElement('radio',$fileformatname,'',$fileformatname,$id);
if (exists lang files for this format name...
$radioarray[]->setHelpButton('format', array('export', get_string('export', 'qformat_'.$fileformatname), 'qformat_'.$fileformatname));

}
$mform->addGroup($radioarray,'format','',array('<br />'),false);
$mform->addRule('format',null,'required',null,'client');
The problems are in my lines in red above... I do not know a) how to set the if exists a lang folder for that particular format and b) I do not know how to access setHelpButton for each element in the radioarray[] array!
Any ideas?
Joseph
In reply to Joseph Rézeau

Re: Need to add Help button for 3rd-party Questions Export format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
1. should certainly be committed, but only after we have dealt with 2.

For 2. - well to start with you are starting with code that is missing a bugfix. Check out the latest 1.9+.

It would be easiest to do this in get_import_export_formats() in questionlib, but the problem is the return value from that function is an array with keys and values that are both significant, so it is hard to squeeze in extra information into the return value - I can only think of hacky ways to achieve it.

But if you went down this route, I would just add a has_help_file() method to the class that returns true or false (and define it in the base class to return false by default. This assumes that if you want help to appear on export, you want in on import too, which is reasonable.
In reply to Tim Hunt

Re: Need to add Help button for 3rd-party Questions Export format

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Tim,

1. should certainly be committed, but only after we have dealt with 2.

Of course. It would be useless otherwise...

For 2. - well to start with you are starting with code that is missing a bugfix. Check out the latest 1.9+.

I don't see any recent bugfix in file export_form.php ??? I am using the very latest version of all question files.

It would be easiest to do this in get_import_export_formats() in questionlib,...

I will look into it, but am having trouble understanding how these things work, and do not want to use too "hacky ways"...

3- Yes, help (if it exists) should appear for import formats as well as export formats.

Joseph


In reply to Joseph Rézeau

Re: Need to add Help button for 3rd-party Questions Export format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The kind of evil hack I was thinking off would be to add an optional parameter to get_import_export_formats, so it becomes

get_import_export_formats($type, $markformatswithhelp = false)

and if $markformatswithhelp is true, then determine whether the format has a help file by calling a new method $format_class->has_help_file(). If so, add a character to the end of the format name, for example a space. Then, when displaying the list of formats, look for a space, and if it is there, then add a help button.

Definitely not nice, and would need to be documented with lots of comments in the code, but actually the easiest way to implement this.
In reply to Tim Hunt

Re: Need to add Help button for 3rd-party Questions Export format

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Continuing discussion in MDL-14431.
As you can see I have made progress but am now stumped.
Joseph