-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_dataset.php
More file actions
113 lines (90 loc) · 3.08 KB
/
export_dataset.php
File metadata and controls
113 lines (90 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Export a dataset as tab-delimited spreadsheet
*
* @package local
* @subpackage dataseteditor
* @copyright 2013-2015 Daniel Seemuth
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/defines.php');
require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
$categoryid = required_param('categoryid', PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$urlargs = array(
'categoryid' => $categoryid
);
if ($cmid > 0) {
$modulecontext = context_module::instance($cmid);
$urlargs['cmid'] = $cmid;
$coursecontext = $modulecontext->get_course_context();
$courseid = $coursecontext->instanceid;
$thiscontext = $modulecontext;
} else {
$coursecontext = context_course::instance($courseid);
$thiscontext = $coursecontext;
}
$urlargs['courseid'] = $courseid;
if ($cmid > 0) {
require_login($courseid, true,
local_dataseteditor_get_cm($courseid, $cmid));
} else {
require_login($courseid);
}
$mainurl = new moodle_url(
LOCAL_DATASETEDITOR_PLUGINPREFIX.'/categories.php',
$urlargs
);
if (! local_dataseteditor_get_cat_contextid($categoryid, false)) {
/* Invalid category ID. */
$mainurl->remove_params('categoryid');
print_error(
'catnotexist',
'local_dataseteditor',
$mainurl
);
}
require_capability(LOCAL_DATASETEDITOR_EXPORT_CAPABILITY, $thiscontext);
local_dataseteditor_require_capability_cat(
LOCAL_DATASETEDITOR_EXPORT_CAPABILITY,
$categoryid
);
$PAGE->set_url(LOCAL_DATASETEDITOR_PLUGINPREFIX.'/export_dataset.php',
$urlargs);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_title(
$SITE->fullname .
': ' .
get_string('pluginname', 'local_dataseteditor') .
': ' .
get_string('editdataset', 'local_dataseteditor')
);
$PAGE->set_pagelayout('incourse');
$renderer = $PAGE->theme->get_renderer($PAGE, 'local_dataseteditor');
// Don't need any data values.
$wildcards = local_dataseteditor_get_wildcards($categoryid, 0);
$items = local_dataseteditor_get_dataset_items(array_keys($wildcards));
header(
'Content-Disposition: attachment; filename=dataset-' .
$categoryid
. '.tsv'
);
header('Content-Type: application/octet-stream');
header('Content-Description: Dataset Export');
echo $renderer->render_dataset_text($wildcards, $items);