-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportcsv.php
94 lines (84 loc) · 3.65 KB
/
exportcsv.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
<?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/>.
/**
* Prints a particular userlist of consentform
*
* @package mod_consentform
* @copyright 2021 Thomas Niedermaier, Medical University of Vienna ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Course_module ID.
if ($id) {
$cm = get_coursemodule_from_id('consentform', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$consentform = $DB->get_record('consentform', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
die('You must specify a course_module ID');
}
$sortkey = optional_param('sortkey', 'lastname', PARAM_ALPHA); // Sorted view: lastname|firstname|email|timestamp.
$sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA); // Defines the order of the sorting (ASC or DESC).
$tab = optional_param('tab', 1, PARAM_INT); // ID of tab of listusers.php.
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
$listusers = consentform_get_listusers($sortkey, $sortorder, $tab, $context, $cm);
$csvrows = array();
foreach ($listusers as $record) {
switch ($record->state) {
case CONSENTFORM_STATUS_AGREED:
$record->state = get_string("agreed", "consentform");
break;
case CONSENTFORM_STATUS_REVOKED:
$record->state = get_string("revoked", "consentform");
break;
case CONSENTFORM_STATUS_REFUSED:
$record->state = get_string("refused", "consentform");
break;
default:
$record->state = get_string("noaction", "consentform");
}
$csvrow = array(
get_string('lastname') => $record->lastname,
get_string('firstname') => $record->firstname,
get_string('email') => $record->email,
get_string('timestamp', 'consentform') =>
$record->timestamp != CONSENTFORM_NOTIMESTAMP ? userdate($record->timestamp) : CONSENTFORM_NOTIMESTAMP,
get_string('state') => $record->state
);
$csvrows[] = $csvrow;
} // End loop records.
switch ($tab){
case CONSENTFORM_STATUS_AGREED:
$statusname = get_string("agreed", "consentform");
break;
case CONSENTFORM_STATUS_REVOKED:
$statusname = get_string("revoked", "consentform");
break;
case CONSENTFORM_STATUS_REFUSED:
$statusname = get_string("refused", "consentform");
break;
case CONSENTFORM_STATUS_NOACTION:
$statusname = get_string("noaction", "consentform");
break;
default:
$statusname = get_string("titleall", "consentform");
}
$export = new \mod_consentform\consentform_export();
$exportformat = 'csv';
$export->init($exportformat, $csvrows, $course->shortname . '_' . $consentform->name . '_' . $statusname . '_' . userdate(time(),
'%d-%m-%Y', 99, false));
$export->print_file();