1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Gradebook results class |
6
|
|
|
* @author Yannick Warnier |
7
|
|
|
* @package chamilo.gradebook |
8
|
|
|
*/ |
9
|
|
|
class GradeBookResult |
10
|
|
|
{ |
11
|
|
|
private $gradebook_list = array(); //stores the list of exercises |
|
|
|
|
12
|
|
|
private $results = array(); //stores the results |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* constructor of the class |
16
|
|
|
*/ |
17
|
|
|
public function __construct($get_questions=false,$get_answers=false) |
18
|
|
|
{ |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Exports the complete report as a CSV file |
23
|
|
|
* @param string Document path inside the document tool |
24
|
|
|
* @param integer Optional user ID |
25
|
|
|
* @param boolean Whether to include user fields or not |
26
|
|
|
* @return boolean False on error |
27
|
|
|
*/ |
28
|
|
|
public function exportCompleteReportCSV($dato) |
29
|
|
|
{ |
30
|
|
|
$filename = 'gradebook_results_'.gmdate('YmdGis').'.csv'; |
31
|
|
|
if (!empty($user_id)) { |
|
|
|
|
32
|
|
|
$filename = 'gradebook_results_user_'.$user_id.'_'.gmdate('YmdGis').'.csv'; |
33
|
|
|
} |
34
|
|
|
$data = ''; |
35
|
|
|
//build the results |
36
|
|
|
//titles |
37
|
|
|
|
38
|
|
|
foreach ($dato[0] as $header_col) { |
39
|
|
|
if(!empty($header_col)) { |
40
|
|
|
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($header_col))).';'; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$data .="\r\n"; |
45
|
|
|
$cant_students = count($dato[1]); |
46
|
|
|
//print_r($data); exit(); |
47
|
|
|
|
48
|
|
|
for($i=0;$i<$cant_students;$i++) { |
49
|
|
|
$column = 0; |
50
|
|
|
foreach($dato[1][$i] as $col_name) { |
51
|
|
|
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($col_name))).';'; |
52
|
|
|
} |
53
|
|
|
$data .="\r\n"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
//output the results |
57
|
|
|
$len = strlen($data); |
58
|
|
|
header('Content-type: application/octet-stream'); |
59
|
|
|
header('Content-Type: application/force-download'); |
60
|
|
|
header('Content-length: '.$len); |
61
|
|
View Code Duplication |
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) { |
62
|
|
|
header('Content-Disposition: filename= '.$filename); |
63
|
|
|
} else { |
64
|
|
|
header('Content-Disposition: attachment; filename= '.$filename); |
65
|
|
|
} if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { |
66
|
|
|
header('Pragma: '); |
67
|
|
|
header('Cache-Control: '); |
68
|
|
|
header('Cache-Control: public'); // IE cannot download from sessions without a cache |
69
|
|
|
} |
70
|
|
|
header('Content-Description: '.$filename); |
71
|
|
|
header('Content-transfer-encoding: binary'); |
72
|
|
|
echo $data; |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Exports the complete report as an XLS file |
79
|
|
|
* @return boolean False on error |
80
|
|
|
*/ |
81
|
|
|
public function exportCompleteReportXLS($data) |
82
|
|
|
{ |
83
|
|
|
$filename = 'gradebook-results-'.api_get_local_time().'.xls'; |
84
|
|
|
|
85
|
|
|
$spreadsheet = new PHPExcel(); |
86
|
|
|
$spreadsheet->setActiveSheetIndex(0); |
87
|
|
|
$worksheet = $spreadsheet->getActiveSheet(); |
88
|
|
|
|
89
|
|
|
$line = 0; |
90
|
|
|
$column = 0; //skip the first column (row titles) |
91
|
|
|
|
92
|
|
|
//headers |
93
|
|
|
foreach ($data[0] as $header_col) { |
94
|
|
|
$worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($header_col))); |
95
|
|
|
$column++; |
96
|
|
|
} |
97
|
|
|
$line++; |
98
|
|
|
|
99
|
|
|
$cant_students = count($data[1]); |
100
|
|
|
|
101
|
|
|
for ($i = 0; $i < $cant_students; $i++) { |
102
|
|
|
$column = 0; |
103
|
|
|
foreach ($data[1][$i] as $col_name) { |
104
|
|
|
$worksheet->SetCellValueByColumnAndRow($line,$column, html_entity_decode(strip_tags($col_name))); |
105
|
|
|
$column++; |
106
|
|
|
} |
107
|
|
|
$line++; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename); |
111
|
|
|
$writer = new PHPExcel_Writer_Excel2007($spreadsheet); |
112
|
|
|
$writer->save($file); |
113
|
|
|
DocumentManager::file_send_for_download($file, true, $filename); |
114
|
|
|
exit; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Exports the complete report as a DOCX file |
119
|
|
|
* @param $data The table data |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
public function exportCompleteReportDOC($data) |
123
|
|
|
{ |
124
|
|
|
$filename = 'gradebook_results_'.api_get_local_time() . '.docx'; |
125
|
|
|
|
126
|
|
|
$doc = new \PhpOffice\PhpWord\PhpWord(); |
127
|
|
|
$section = $doc->addSection(['orientation' => 'landscape']); |
128
|
|
|
$table = $section->addTable(); |
129
|
|
|
$table->addRow(); |
130
|
|
|
|
131
|
|
View Code Duplication |
for ($i = 0; $i < count($data[0]); $i++) { |
132
|
|
|
$table->addCell(1750)->addText(strip_tags($data[0][$i])); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
foreach ($data[1] as $dataLine) { |
136
|
|
|
$table->addRow(); |
137
|
|
|
|
138
|
|
View Code Duplication |
for ($i = 0; $i < count($dataLine); $i++) { |
139
|
|
|
$table->addCell(1750)->addText(strip_tags($dataLine[$i])); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$file = api_get_path(SYS_ARCHIVE_PATH) . api_replace_dangerous_char($filename); |
144
|
|
|
$doc->save($file, 'Word2007'); |
145
|
|
|
|
146
|
|
|
DocumentManager::file_send_for_download($file, true, $filename); |
147
|
|
|
return true; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.