PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/question/export_form.php

http://github.com/moodle/moodle
PHP | 93 lines | 43 code | 18 blank | 32 comment | 2 complexity | 624f3b1cecbb6608450598abe57b9939 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Defines the export questions form.
  18. *
  19. * @package moodlecore
  20. * @subpackage questionbank
  21. * @copyright 2007 Jamie Pratt me@jamiep.org
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->libdir . '/formslib.php');
  26. /**
  27. * Form to export questions from the question bank.
  28. *
  29. * @copyright 2007 Jamie Pratt me@jamiep.org
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class question_export_form extends moodleform {
  33. protected function definition() {
  34. global $OUTPUT;
  35. $mform = $this->_form;
  36. $defaultcategory = $this->_customdata['defaultcategory'];
  37. $contexts = $this->_customdata['contexts'];
  38. // Choice of format, with help.
  39. $mform->addElement('header', 'fileformat', get_string('fileformat', 'question'));
  40. $fileformatnames = get_import_export_formats('export');
  41. $radioarray = array();
  42. $separators = array();
  43. foreach ($fileformatnames as $shortname => $fileformatname) {
  44. $radioarray[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
  45. $separator = '';
  46. if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
  47. $separator .= $OUTPUT->help_icon('pluginname', 'qformat_' . $shortname);
  48. }
  49. $separator .= '<br>';
  50. $separators[] = $separator;
  51. }
  52. $radioarray[] = $mform->createElement('static', 'makelasthelpiconshowup', '');
  53. $mform->addGroup($radioarray, "formatchoices", '', $separators, false);
  54. $mform->addRule("formatchoices", null, 'required', null, 'client');
  55. // Export options.
  56. $mform->addElement('header', 'general', get_string('general', 'form'));
  57. $mform->addElement('questioncategory', 'category', get_string('exportcategory', 'question'),
  58. array('contexts' => $contexts, 'top' => true));
  59. $mform->setDefault('category', $defaultcategory);
  60. $mform->addHelpButton('category', 'exportcategory', 'question');
  61. $categorygroup = array();
  62. $categorygroup[] = $mform->createElement('checkbox', 'cattofile', '', get_string('tofilecategory', 'question'));
  63. $categorygroup[] = $mform->createElement('checkbox', 'contexttofile', '', get_string('tofilecontext', 'question'));
  64. $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
  65. $mform->disabledIf('categorygroup', 'cattofile', 'notchecked');
  66. $mform->setDefault('cattofile', 1);
  67. $mform->setDefault('contexttofile', 1);
  68. // Set a template for the format select elements
  69. $renderer = $mform->defaultRenderer();
  70. $template = "{help} {element}\n";
  71. $renderer->setGroupElementTemplate($template, 'format');
  72. // Submit buttons.
  73. $this->add_action_buttons(false, get_string('exportquestions', 'question'));
  74. }
  75. }