1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
// This file is part of Moodle - http://moodle.org/
|
|
|
4 |
//
|
|
|
5 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
6 |
// it under the terms of the GNU General Public License as published by
|
|
|
7 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
8 |
// (at your option) any later version.
|
|
|
9 |
//
|
|
|
10 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
// GNU General Public License for more details.
|
|
|
14 |
//
|
|
|
15 |
// You should have received a copy of the GNU General Public License
|
|
|
16 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17 |
|
|
|
18 |
require_once '../../../config.php';
|
|
|
19 |
require_once $CFG->dirroot.'/grade/export/lib.php';
|
|
|
20 |
require_once 'grade_export_txt.php';
|
|
|
21 |
|
|
|
22 |
$id = required_param('id', PARAM_INT); // course id
|
|
|
23 |
$PAGE->set_url('/grade/export/txt/export.php', array('id'=>$id));
|
|
|
24 |
|
|
|
25 |
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
|
|
26 |
throw new \moodle_exception('invalidcourseid');
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
require_login($course);
|
|
|
30 |
$context = context_course::instance($id);
|
|
|
31 |
$groupid = groups_get_course_group($course, true);
|
|
|
32 |
|
|
|
33 |
require_capability('moodle/grade:export', $context);
|
|
|
34 |
require_capability('gradeexport/txt:view', $context);
|
|
|
35 |
|
|
|
36 |
// We need to call this method here before any print otherwise the menu won't display.
|
|
|
37 |
// If you use this method without this check, will break the direct grade exporting (without publishing).
|
|
|
38 |
$key = optional_param('key', '', PARAM_RAW);
|
|
|
39 |
if (!empty($CFG->gradepublishing) && !empty($key)) {
|
|
|
40 |
$actionbar = new \core_grades\output\export_publish_action_bar($context, 'txt');
|
|
|
41 |
print_grade_page_head($COURSE->id, 'export', 'txt',
|
|
|
42 |
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'),
|
|
|
43 |
false, false, true, null, null, null, $actionbar);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
|
|
|
47 |
if (!groups_is_member($groupid, $USER->id)) {
|
|
|
48 |
throw new \moodle_exception('cannotaccessgroup', 'grades');
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
$params = array(
|
|
|
53 |
'includeseparator'=>true,
|
|
|
54 |
'publishing' => true,
|
|
|
55 |
'simpleui' => true,
|
|
|
56 |
'multipledisplaytypes' => true
|
|
|
57 |
);
|
|
|
58 |
$mform = new grade_export_form(null, $params);
|
|
|
59 |
$data = $mform->get_data();
|
|
|
60 |
$export = new grade_export_txt($course, $groupid, $data);
|
|
|
61 |
|
|
|
62 |
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
|
|
|
63 |
if (!empty($CFG->gradepublishing) && !empty($key)) {
|
|
|
64 |
groups_print_course_menu($course, 'index.php?id='.$id);
|
|
|
65 |
echo $export->get_grade_publishing_url();
|
|
|
66 |
echo $OUTPUT->footer();
|
|
|
67 |
} else {
|
|
|
68 |
$event = \gradeexport_txt\event\grade_exported::create(array('context' => $context));
|
|
|
69 |
$event->trigger();
|
|
|
70 |
$export->print_grades();
|
|
|
71 |
}
|