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