-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_selected_outcomes.php
168 lines (147 loc) · 7.64 KB
/
export_selected_outcomes.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
// This file is part of the Checkskill plugin for 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/>.
/**
* Library of functions and constants for module checkskill
* Adapted from export.php to export Skills Repository outcomes files
*
* This script export a selected skill of Items of Checkskill module as a Skill Repository Outcome file
* exactly like 'referentiel' module
* ITEMS CSV FILE
* Separator ','
* Item text,Indent,Type (0 - normal; 1 - optional; 2 - heading),Due Time (timestamp),Colour (red; orange; green; purple; black)
* DES_rhumato,0,0,0,purple
* DES_rhumato UV1.1.1 :: Je sais définir Incidence.,1,0,0,black
* DES_rhumato UV1.1.2 :: Je sais définir Prévalence.,1,0,0,black
* DES_rhumato UV1.2.1 :: Savoir interpréter les résultats d'un essai (...),1,0,0,black
* DES_rhumato UV1.2.2 :: Savoir discuter la pertinence d'un critère d'évaluation.,1,0,0,black
* DES_rhumato UV2.1.1 :: Connaître l’incidence et la prévalence de la (...),1,0,0,black
* DES_rhumato UV2.1.2 :: Connaître les facteurs déclenchant de la PR et les (...),1,0,0,black
* DES_rhumato UV2.1.3 :: Connaître les principaux facteurs d’environnement (...),1,0,0,black
* DES_rhumato UV2.1.4 :: Connaître les principales causes de morbidité et de (...),1,0,0,black
* DES_rhumato UV2.2.1 :: Connaître de façon globale les hypothèses pathogéniques (...),1,0,0,black
*
* OUTCOMES CSV FILE
* Separator ';'
* outcome_name;outcome_shortname;outcome_description;scale_name;scale_items;scale_description
* "DES_rhumato UV1.1.1 :: Je sais définir Incidence.";UV1.1.1;"Je sais définir Incidence.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel."
* "DES_rhumato UV1.1.2 :: Je sais définir Prévalence.";UV1.1.2;"Je sais définir Prévalence.";"Item référentiel";"Non pertinent,Non validé,Validé";"Ce barème est destiné à évaluer l'acquisition des compétences du module référentiel."
*
* Skills repositoy outcome_name has to match '/(.*)::(.*)/i' regular expression
* That's mandatory
*
*
* @author jfruitet [email protected]
*
* @version $Id: import_outcome.php,v 1.0 2012/03/18 00:00:00 jfruitet Exp $
* @package checkskill 'JF-2.x (Build: 2012041100)';
**/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/importexportoutcomes.php'); // Outcomes format
require_once(dirname(__FILE__).'/locallib.php');
global $DB;
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$checkskillid = optional_param('checkskill', 0, PARAM_INT); // checkskill instance ID
if ($CFG->version < 2011120100) {
$items = optional_param('items', false, PARAM_INT);
} else {
$items = optional_param_array('items', false, PARAM_INT);
}
$referentielcode = optional_param('referentielcode', '', PARAM_ALPHANUMEXT);
$useitemid = optional_param('useitemid', '', PARAM_INT);
$quit = optional_param('quit', '', PARAM_ALPHANUM);
$url = new moodle_url('/mod/checkskill/export_selected_outcomes.php');
$urlredirect = new moodle_url('/mod/checkskill/view.php');
if ($id) {
if (!$cm = get_coursemodule_from_id('checkskill', $id)){
print_error('error_cmid', 'checkskill'); // 'Course Module ID was incorrect'
}
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$checkskill = $DB->get_record('checkskill', array('id' => $cm->instance), '*', MUST_EXIST);
$url->param('id', $id);
$urlredirect->param('id', $id);
} else if ($checkskillid) {
$checkskill = $DB->get_record('checkskill', array('id' => $checkskillid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $checkskill->course), '*', MUST_EXIST);
if (!$cm = get_coursemodule_from_instance('checkskill', $checkskill->id, $course->id)) {
print_error('error_cmid', 'checkskill'); // 'Course Module ID was incorrect'
}
$url->param('checkskill', $checkskillid);
$urlredirect->param('checkskill', $checkskillid);
} else {
print_error('error_specif_id', 'checkskill'); // 'You must specify a course_module ID or an instance ID'
}
if ($quit){
redirect($urlredirect);
}
$PAGE->set_url($url);
require_login($course, true, $cm);
if ($CFG->version < 2011120100) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
$context = context_module::instance($cm->id);
}
$userid = $USER->id;
if (!has_capability('mod/checkskill:edit', $context)) {
print_error(get_string('error_export_items', 'checkskill')); // You do not have permission to export items from this checkskill'
die();
}
if (!confirm_sesskey()) {
echo get_string('error_sesskey', 'checkskill'); // 'Error: invalid sesskey';
die();
}
if (!$items || !is_array($items)) {
print_error('error_select', 'checkskill', $urlredirect); // 'You must specify a course_module ID or an instance ID'
// redirect($urlredirect);
}
else{
// Fichier à creer
$contenu='';
$chk = new checkskill_class($cm->id, $userid, $checkskill, $cm, $course);
$selected_items=$chk->exportchecks($items);
if (!empty($selected_items)){
// Creer le fichier
$ok_referentiel=false; // flag for Skills repository outcomes
// Output the headings
$contenu = implode($separator_outcomes, array_keys($fields_outcomes))."\n";
foreach ($selected_items as $an_item) {
if (!empty($an_item->displaytext)){
$an_outcome=get_outcome_code_from_item($an_item, $referentielcode, $useitemid);
if (!empty($an_outcome) && !empty($an_outcome->outcome) && !empty($an_outcome->code_competence) && !empty($an_outcome->description)){
$ok_referentiel=true;
$contenu.=str_replace('""','"', $an_outcome->outcome.$separator_outcomes.$an_outcome->code_competence.$separator_outcomes.$an_outcome->description.$separator_outcomes.get_string('scale_name', 'checkskill').$separator_outcomes.get_string('scale_items', 'checkskill').$separator_outcomes.get_string('scale_description', 'checkskill'))."\n";
}
}
}
if ($ok_referentiel){
if (strpos($CFG->wwwroot, 'https://') === 0) { //https sites - watch out for IE! KB812935 and KB316431
@header('Cache-Control: max-age=10');
@header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
@header('Pragma: ');
} else { //normal http - prevent caching at all cost
@header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
@header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
@header('Pragma: no-cache');
}
header("Content-Type: application/download\n");
$downloadfilename = clean_filename("outcomes_{$course->shortname}_{$checkskill->name}_".date("Ymd"));
header("Content-Disposition: attachment; filename=\"$downloadfilename.csv\"");
echo $contenu;
// redirect($urlredirect);
}
}
}
exit;