Skip to content

Commit

Permalink
MDL-53728 question import/export: improve form structure
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Apr 6, 2016
1 parent aeccf4b commit f06eacd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
21 changes: 13 additions & 8 deletions question/export_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,33 @@
class question_export_form extends moodleform {

protected function definition() {
global $OUTPUT;

$mform = $this->_form;

$defaultcategory = $this->_customdata['defaultcategory'];
$contexts = $this->_customdata['contexts'];

// Choice of format, with help.
$mform->addElement('header', 'fileformat', get_string('fileformat', 'question'));

$fileformatnames = get_import_export_formats('export');
$radioarray = array();
$i = 0 ;
$separators = array();
foreach ($fileformatnames as $shortname => $fileformatname) {
$currentgrp1 = array();
$currentgrp1[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
$mform->addGroup($currentgrp1, "formathelp[{$i}]", '', array('<br />'), false);
$radioarray[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);

$separator = '';
if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
$mform->addHelpButton("formathelp[{$i}]", 'pluginname', 'qformat_' . $shortname);
$separator .= $OUTPUT->help_icon('pluginname', 'qformat_' . $shortname);
}

$i++ ;
$separator .= '<br>';
$separators[] = $separator;
}
$mform->addRule("formathelp[0]", null, 'required', null, 'client');

$radioarray[] = $mform->createElement('static', 'makelasthelpiconshowup', '');
$mform->addGroup($radioarray, "formatchoices", '', $separators, false);
$mform->addRule("formatchoices", null, 'required', null, 'client');

// Export options.
$mform->addElement('header', 'general', get_string('general', 'form'));
Expand Down
21 changes: 12 additions & 9 deletions question/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
class question_import_form extends moodleform {

protected function definition() {
global $COURSE;
global $OUTPUT;

$mform = $this->_form;

$defaultcategory = $this->_customdata['defaultcategory'];
Expand All @@ -49,19 +50,21 @@ protected function definition() {

$fileformatnames = get_import_export_formats('import');
$radioarray = array();
$i = 0 ;
$separators = array();
foreach ($fileformatnames as $shortname => $fileformatname) {
$currentgrp1 = array();
$currentgrp1[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
$mform->addGroup($currentgrp1, "formathelp[{$i}]", '', array('<br />'), false);
$radioarray[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);

$separator = '';
if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
$mform->addHelpButton("formathelp[{$i}]", 'pluginname', 'qformat_' . $shortname);
$separator .= $OUTPUT->help_icon('pluginname', 'qformat_' . $shortname);
}

$i++ ;
$separator .= '<br>';
$separators[] = $separator;
}
$mform->addRule("formathelp[0]", null, 'required', null, 'client');

$radioarray[] = $mform->createElement('static', 'makelasthelpiconshowup', '');
$mform->addGroup($radioarray, "formatchoices", '', $separators, false);
$mform->addRule("formatchoices", null, 'required', null, 'client');

// Import options.
$mform->addElement('header','general', get_string('general', 'form'));
Expand Down

0 comments on commit f06eacd

Please sign in to comment.