Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Script to download the export of a single question.
19
 *
20
 * @package    qbank_exporttoxml
21
 * @copyright  2015 the Open University
22
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once(__DIR__ . '/../../../config.php');
27
require_once($CFG->libdir . '/questionlib.php');
28
require_once($CFG->dirroot . '/question/format/xml/format.php');
29
 
30
// Get the parameters from the URL.
31
$questionid = required_param('id', PARAM_INT);
1441 ariadna 32
$cmid = required_param('cmid', PARAM_INT);
1 efrain 33
$urlparams = ['id' => $questionid, 'sesskey' => sesskey()];
34
 
35
\core_question\local\bank\helper::require_plugin_enabled('qbank_exporttoxml');
36
 
1441 ariadna 37
$cm = get_coursemodule_from_id(null, $cmid);
38
require_login($cm->course, false, $cm);
39
$thiscontext = context_module::instance($cmid);
40
$urlparams['cmid'] = $cmid;
41
 
1 efrain 42
require_sesskey();
43
 
44
// Load the necessary data.
45
$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
46
$questiondata = question_bank::load_question_data($questionid);
47
 
48
// Check permissions.
49
question_require_capability_on($questiondata, 'view');
50
 
51
// Initialise $PAGE. Nothing is output, so this does not really matter. Just avoids notices.
52
$nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams);
53
$PAGE->set_url('/question/bank/exporttoxml/exportone.php', $urlparams);
54
$PAGE->set_heading($COURSE->fullname);
55
$PAGE->set_pagelayout('admin');
56
 
57
// Set up the export format.
58
$qformat = new qformat_xml();
59
$filename = question_default_export_filename($COURSE, $questiondata) .
60
        $qformat->export_file_extension();
61
$qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
62
$qformat->setCourse($COURSE);
63
$qformat->setQuestions([$questiondata]);
64
$qformat->setCattofile(false);
65
$qformat->setContexttofile(false);
66
 
67
// Do the export.
68
if (!$qformat->exportpreprocess()) {
69
    send_file_not_found();
70
}
71
if (!$content = $qformat->exportprocess(true)) {
72
    send_file_not_found();
73
}
74
send_file($content, $filename, 0, 0, true, true, $qformat->mime_type());