Merge branch 'MDL-70072-310' of git://github.com/rezaies/moodle into MOODLE_310_STABLE
[moodle.git] / question / export_form.php
CommitLineData
aeb15530 1<?php
f7c1dfaf
TH
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/**
18 * Defines the export questions form.
19 *
20 * @package moodlecore
21 * @subpackage questionbank
22 * @copyright 2007 Jamie Pratt me@jamiep.org
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
a17b297d 27defined('MOODLE_INTERNAL') || die();
bfebaf64 28
f7c1dfaf
TH
29require_once($CFG->libdir . '/formslib.php');
30
515ed4c3 31
f7c1dfaf
TH
32/**
33 * Form to export questions from the question bank.
34 *
35 * @copyright 2007 Jamie Pratt me@jamiep.org
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
515ed4c3 38class question_export_form extends moodleform {
39
c7df5006 40 protected function definition() {
f06eacd9
TH
41 global $OUTPUT;
42
f7c1dfaf 43 $mform = $this->_form;
515ed4c3 44
f7c1dfaf
TH
45 $defaultcategory = $this->_customdata['defaultcategory'];
46 $contexts = $this->_customdata['contexts'];
47
48 // Choice of format, with help.
49 $mform->addElement('header', 'fileformat', get_string('fileformat', 'question'));
f06eacd9 50
45b68eef 51 $fileformatnames = get_import_export_formats('export');
52 $radioarray = array();
f06eacd9 53 $separators = array();
f94902db 54 foreach ($fileformatnames as $shortname => $fileformatname) {
f06eacd9 55 $radioarray[] = $mform->createElement('radio', 'format', '', $fileformatname, $shortname);
64679179 56
f06eacd9 57 $separator = '';
64679179 58 if (get_string_manager()->string_exists('pluginname_help', 'qformat_' . $shortname)) {
f06eacd9 59 $separator .= $OUTPUT->help_icon('pluginname', 'qformat_' . $shortname);
64679179 60 }
8dfa3027 61 $separator .= '<div class="w-100"></div>';
f06eacd9 62 $separators[] = $separator;
45b68eef 63 }
f06eacd9
TH
64
65 $radioarray[] = $mform->createElement('static', 'makelasthelpiconshowup', '');
66 $mform->addGroup($radioarray, "formatchoices", '', $separators, false);
67 $mform->addRule("formatchoices", null, 'required', null, 'client');
f7c1dfaf
TH
68
69 // Export options.
70 $mform->addElement('header', 'general', get_string('general', 'form'));
515ed4c3 71
f86f8c85
SR
72 $mform->addElement('questioncategory', 'category', get_string('exportcategory', 'question'),
73 array('contexts' => $contexts, 'top' => true));
515ed4c3 74 $mform->setDefault('category', $defaultcategory);
5fcefc97 75 $mform->addHelpButton('category', 'exportcategory', 'question');
515ed4c3 76
77 $categorygroup = array();
f7c1dfaf
TH
78 $categorygroup[] = $mform->createElement('checkbox', 'cattofile', '', get_string('tofilecategory', 'question'));
79 $categorygroup[] = $mform->createElement('checkbox', 'contexttofile', '', get_string('tofilecontext', 'question'));
515ed4c3 80 $mform->addGroup($categorygroup, 'categorygroup', '', '', false);
81 $mform->disabledIf('categorygroup', 'cattofile', 'notchecked');
82 $mform->setDefault('cattofile', 1);
83 $mform->setDefault('contexttofile', 1);
aeb15530 84
f7c1dfaf
TH
85 // Set a template for the format select elements
86 $renderer = $mform->defaultRenderer();
79e3dd8e 87 $template = "{help} {element}\n";
88 $renderer->setGroupElementTemplate($template, 'format');
515ed4c3 89
f7c1dfaf
TH
90 // Submit buttons.
91 $this->add_action_buttons(false, get_string('exportquestions', 'question'));
515ed4c3 92 }
93}