-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexport.php
More file actions
98 lines (92 loc) · 3.6 KB
/
export.php
File metadata and controls
98 lines (92 loc) · 3.6 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
<?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(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/report/lp/lib.php');
require_once($CFG->libdir . '/grouplib.php');
require_once($CFG->libdir . "/excellib.class.php");
$courseid = required_param('courseid', PARAM_INT);
$course = get_course($courseid);
$coursecontext = context_course::instance($courseid);
require_login($course);
require_capability('report/lp:exportsummary', $coursecontext);
$summaryurl = report_lp\local\factories\url::get_summary_url($course);
// Build data.
$summary = new report_lp\local\summary_report($course);
$itemtypelist = new report_lp\local\item_type_list();
$summary->add_item_type_list($itemtypelist);
$learnerlist = new report_lp\local\learner_list($course);
$filteredcoursegroups = report_lp\local\course_group::get_active_filter($course->id);
if (empty($filteredcoursegroups)) {
// If no active filters, ensure people without access all groups can only see their group memberships.
if (!has_capability('moodle/site:accessallgroups', $coursecontext)) {
$groups = report_lp\local\course_group::get_available_groups($course);
$learnerlist->add_course_groups_filter(array_keys($groups));
}
}
$summary->add_learner_list($learnerlist);
$renderer = $PAGE->get_renderer('report_lp');
$data = $summary->export_for_template($renderer);
$time = strftime("%d-%m-%YT%H%M%S");
$workbook = new MoodleExcelWorkbook("-");
$filename = "{$course->shortname} LPS Report {$time}" . ".xls";
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheet = $workbook->add_worksheet('Learner progress summary');
// Format types.
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$rowindex = 0;
// Process header rows.
$theadrows = $data->thead->rows;
$theadrowcount = count($theadrows);
foreach ($theadrows as $theadrow) {
$cells = $theadrow->cells;
$columnindex = 0;
foreach ($cells as $cell) {
$text = !empty($cell->text) ? $cell->text : '';
if ($rowindex === 0) {
$sheet->write($rowindex, $columnindex, $text, $formatbc);
} else {
$sheet->write($rowindex, $columnindex, $text);
}
if ($cell->colspan > 1) {
$firstcolumn = $columnindex;
$colspan = (int) $cell->colspan;
for ($i = 1; $i < $colspan; $i++) {
$sheet->write($rowindex, ++$columnindex, '');
}
$sheet->merge_cells($rowindex, $firstcolumn, $rowindex, $columnindex);
}
$columnindex++;
}
$rowindex++;
}
// Process data rows.
$tbodyrows = $data->tbody->rows;
$tbodyrowcount = count($theadrows);
$rowindex = $theadrowcount;
foreach ($tbodyrows as $tbodyrow) {
$cells = $tbodyrow->cells;
$columnindex = 0;
foreach ($cells as $cell) {
$text = !empty($cell->plaintextcontent) ? $cell->plaintextcontent : '';
$sheet->write($rowindex, $columnindex, $text);
$columnindex++;
}
$rowindex++;
}
$workbook->close();