-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
77 lines (61 loc) · 2.77 KB
/
export.php
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
<?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/>.
require_once dirname(__FILE__) . '/../../config.php';
require_once dirname(__FILE__) . '/locallib.php';
defined('MOODLE_INTERNAL') || die();
use block_custom_course_progress\custom_course_progress_lib;
require_login();
global $CFG, $PAGE, $USER;
$personalcontext = context_user::instance($USER->id);
$PAGE->set_url(new moodle_url('/blocks/custom_course_progress/export.php'));
$PAGE->set_context($personalcontext);
$context = context_system::instance();
$config = get_config('block_custom_course_progress');
$showidlecourses = $config->showidlecourses;
$lib = new custom_course_progress_lib($context, $showidlecourses);
// The user must be allowed to download the report.
if (!$config->user_can_download_report || $config->user_can_download_report < 1) {
redirect($CFG->wwwroot .'/my/');
}
$fs = get_file_storage();
// Prepare file record object
$fileinfo = array(
'component' => 'block_custom_course_progress', // usually = table name
'filearea' => 'reportlogo', // usually = table name
'itemid' => 0, // usually = ID of row in table
'contextid' => $context->id, // ID of context
'filepath' => '/', // any path beginning and ending in /
'filename' => $config->reportlogo); // any filename
// Get file
$file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'],
$fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']);
// Read contents
if ($file) {
$path = '/' . $fileinfo['contextid'] . '/' . $fileinfo['component'] . '/' . $fileinfo['filearea'] . '/' . $fileinfo['itemid'] . $fileinfo['filename'];
$logopath = moodle_url::make_file_url('/pluginfile.php', $path);
$reportlogo = $file->get_content();
$lib->setReportlogo($reportlogo);
if (strpos($fileinfo['filename'], '.') !== false) {
$fileextension = substr($fileinfo['filename'], strrpos($fileinfo['filename'], '.') + 1);
$lib->setReportext($fileextension);
}
} else {
throw new Error('Unable to find file for block_custom_course_progress');
}
$url = $lib->make_export($USER->id, 'export_' . $USER->id . '.pdf');
if (isset($url)) {
redirect($url);
}