-
Notifications
You must be signed in to change notification settings - Fork 0
/
curriculum-export-csv.php
executable file
·119 lines (97 loc) · 3.13 KB
/
curriculum-export-csv.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
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
<?php
# Formazione MIUR content management system
# Copyright (C) 2017 ITIS Avogadro, Ivan Bertotto, Valerio Bozzolan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 'load.php';
required_permission('see-all-curriculums');
function sanitize_csv_value(& $s) {
$s = str_replace("\n", ' ', $s);
$s = str_replace("\r", ' ', $s);
$s = str_replace(CSV_GLUE, ' ', $s);
return $s;
}
if( ! empty( $_POST ) ) {
$CSVHeadings = CurriculumFields::get();
$curriculums = Curriculum::factory()
->select(Curriculum::T . DOT . STAR)
->select(Organico ::T . DOT . STAR)
->from(Organico::T)
->equals(Curriculum::ORGANICO_, Organico::ID_)
->select(Scuola::MECCANOGRAFICO)
->from(Scuola::T)
->equals(Organico::SCUOLA_, Scuola::ID_)
->orderBy(Scuola::MECCANOGRAFICO)
->queryResults();
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=generated-export-curriculums.csv');
$headings = [
_("ruolo"),
_("meccanografico"),
_("email")
];
foreach($CSVHeadings as $heading) {
if( $heading->isLongDescription() ) {
continue;
}
$headings[] = $heading->getTitle();
if( $heading->isCountable() ) {
$headings[] = sprintf("Punteggio %s", $heading->getTitle() );
}
}
$headings[] = _("finalizzato");
$headings[] = _("PUNTEGGIO TOTALE");
echo implode(CSV_GLUE, $headings);
echo "\n";
foreach($curriculums as $curriculum) {
$user = User::factory()
->whereInt(User::ORGANICO_, $curriculum->get(Organico::ID) )
->queryRow();
$user || error_die("Unexisting user?");
$values = [
$curriculum->get(Organico::ROLE),
$curriculum->get(Scuola::MECCANOGRAFICO),
$user->getUserEmail(),
];
$points = 0;
foreach($CSVHeadings as $heading) {
if( $heading->isLongDescription() ) {
continue;
}
$values[] = $heading->getHumanValue( $curriculum );
if( $heading->isCountable() ) {
$row_points = $heading->getPoints( $curriculum );
$values[] = $row_points;
$points += $row_points;
}
}
$values[] = $curriculum->isCurriculumFinalized() ? _("si'") : _("no");
$values[] = $points;
array_walk($values, 'sanitize_csv_value');
echo implode(CSV_GLUE, $values);
echo "\n";
}
exit;
}
Header::spawn('home');
?>
<div class="card-panel">
<form method="post">
<input type="hidden" name="do" value="1" />
<p><?php _e("L'operazione potrebbe richiedere del tempo.") ?></p>
<button type="submit" class="btn waves-effect light-blue darken-1"><?php _e("Esporta tutti i curriculum"); echo m_icon('file_download') ?></button>
</form>
</div>
<?php
Footer::spawn();