-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclass.ilTestOverviewExcelExporter.php
More file actions
122 lines (106 loc) · 3.51 KB
/
class.ilTestOverviewExcelExporter.php
File metadata and controls
122 lines (106 loc) · 3.51 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
114
115
116
117
118
119
120
121
122
<?php
declare(strict_types=1);
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
class ilTestOverviewExcelExporter
{
/** @var ilLanguage $lng */
protected $lng;
public function __construct()
{
global $DIC;
$this->lng = $DIC['lng'];
}
public function export($title, $columns, $row_data, $filename, $send = true): void
{
$excel = new ilExcel();
$excel->addSheet(
$title ?: $this->lng->txt("export")
);
$row = 1;
ob_start();
$pre = $row;
$this->fillHeaderExcel($excel, $columns, $row); // row should NOT be incremented in fillHeaderExcel()! (required method)
if ($pre === $row) {
$row++;
}
if(is_array($row_data)) {
foreach ($row_data as $set) {
$this->fillRowExcel($excel, $row, $set);
$row++;
}
}
ob_end_clean();
if ($send) {
$excel->sendToClient($filename);
} else {
$excel->writeToFile($filename);
}
}
/**
* Excel Version of Fill Header. Likely to
* be overwritten by derived class.
*
* @param ilExcel $a_excel Excel wrapper
* @param array $columns Header row array
* @param integer $row Row counter
*/
protected function fillHeaderExcel(ilExcel $a_excel, $columns, $row): void
{
$col = 0;
foreach ($columns as $column) {
$title = strip_tags($column);
if ($title) {
$a_excel->setCell($row, $col++, $title);
}
}
$a_excel->setBold("A" . $row . ":" . $a_excel->getColumnCoord($col - 1) . $row);
}
/**
* Fills a row
*
* @param ilExcel $a_excel excel wrapper
* @param integer $row row counter
* @param array $a_set data array
*/
protected function fillRowExcel(ilExcel $a_excel, $row, $a_set): void
{
$col = 0;
foreach ($a_set as $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
$col++;
$color = "FFFFFF";
if(str_replace("##no-result##", '', $value) !== $value) {
$color = "999999";
} elseif (str_replace('##red-result##', '', $value) !== $value) {
$color = "FF0000";
} elseif (str_replace('##green-result##', '', $value) !== $value) {
$color = "00CC00";
} elseif (str_replace('##yellow-result##', '', $value) !== $value) {
$color = "FFC100";
} elseif (str_replace('##orange-result##', '', $value) !== $value) {
$color = "FFC100";
}
$value = str_replace(['##no-result##', '##red-result##', '##green-result##', '##yellow-result##', '##orange-result##'], '', $value);
$a_excel->setCell($row, $col-1, $value);
if($color !== "FFFFFF") {
$a_excel->setColors($a_excel->getCoordByColumnAndRow($col - 1, $row), $color);
}
}
}
}