/
3dchart.php
182 lines (155 loc) · 6.9 KB
/
3dchart.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?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/>.
global $USER;
require __DIR__ . '/inc.php';
$start = optional_param('start', 0, PARAM_INT);
$end = optional_param('end', 0, PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
$topicid = required_param('topicid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourse', 'block_exacomp', $courseid);
}
// error if example does not exist or was created by somebody else
if (!$topic = $DB->get_record(BLOCK_EXACOMP_DB_TOPICS, array('id' => $topicid))) {
print_error('invalidtopic', 'block_exacomp', $topicid);
}
block_exacomp_require_login($course);
$context = context_course::instance($courseid);
if ($userid != $USER->id) {
block_exacomp_require_teacher($courseid);
}
if (!block_exacomp_use_eval_niveau($courseid)) {
print_error('invalidevalniveau', 'block_exacomp');
}
/* PAGE URL - MUST BE CHANGED */
$PAGE->set_url('/blocks/exacomp/3dchart.php', array('courseid' => $courseid));
$PAGE->set_heading(block_exacomp_get_string('blocktitle'));
$PAGE->set_pagelayout('embedded');
// build breadcrumbs navigation
block_exacomp_build_breadcrum_navigation($courseid);
$exacomp_graph = (object)[
'data' => [],
'options' => (object)[],
];
$graph_options =& $exacomp_graph->options;
$graph_data =& $exacomp_graph->data;
/*
$graph_options->xMin = 0;
$graph_options->xMax = 10;
$graph_options->yMin = 0;
$graph_options->yMax = 10;
$graph_options->zMin = 0;
$graph_options->zMax = 10;
*/
$evaluation = block_exacomp_get_descriptor_statistic_for_topic($courseid, $topicid, $userid, $start, $end)['average_descriptor_evaluations'];
$graph_options->xLabels = array_map(function($label) {
// remove LFS at the beginning
return preg_replace('!^' . preg_quote(block_exacomp_get_string('niveau_short'), '!') . '!', '', $label);
}, array_keys(['' => ''] + $evaluation));
$graph_options->xLabel = block_exacomp_get_string('niveau_short');
$xlabels_long = array_keys(['' => ''] + $evaluation);
if (block_exacomp_get_assessment_comp_diffLevel($courseid)) {
$evalniveau_titles = \block_exacomp\global_config::get_evalniveaus(true, $courseid);
} else {
$evalniveau_titles = array('' => '', '0' => block_exacomp_get_string('teacherevaluation_short'));
}
$graph_options->yLabels = array_values($evalniveau_titles) + ['2'];
$y_id_to_index = array_combine(array_keys($evalniveau_titles), array_keys($graph_options->yLabels));
$ylabels_long = $graph_options->yLabels;
// add student's evaluation
end($graph_options->yLabels);
$student_value_index = key($graph_options->yLabels) + 1;
$graph_options->yLabels[$student_value_index] = block_exacomp_get_string('selfevaluation_short');
$ylabels_long[$student_value_index] = block_exacomp_get_string('selfevaluation');
// php <5.6.0 has no filter key function
function block_exacomp_array_filter_keys($arr, $cb) {
return array_intersect_key($arr, array_flip(array_filter(array_keys($arr), $cb)));
}
$value_titles = block_exacomp_array_filter_keys(\block_exacomp\global_config::get_teacher_eval_items($courseid, true), function($k) {
return $k >= 0;
});
$value_titles_long = block_exacomp_array_filter_keys(\block_exacomp\global_config::get_teacher_eval_items($courseid, false), function($k) {
return $k >= 0;
});
$value_titles_self_assessment = \block_exacomp\global_config::get_student_eval_items(true, BLOCK_EXACOMP_TYPE_TOPIC, null, $courseid);
$graph_options->zLabels = array_fill(0, count($value_titles), '');
$graph_options->yColors = [
$student_value_index => [
'fill' => 'RGB(255,197,57)',
],
];
$x = 1;
foreach ($evaluation as $e) {
if ($e->studentvalue > 0) {
$data_value = (object)[
'x' => $x,
'y' => $student_value_index,
'z' => $e->studentvalue,
'label' => $xlabels_long[$x] . ' / ' . block_exacomp_get_string('selfevaluation') . ': <b>' . $value_titles_self_assessment[$e->studentvalue] . '</b>',
];
$graph_data["{$data_value->x}-{$data_value->y}-{$data_value->z}"] = $data_value;
}
if ($e->teachervalues) {
foreach ($e->teachervalues as $evkey => $tvalue) {
if ($tvalue >= 0 && isset($y_id_to_index[$evkey])) {
$data_value = (object)[
'x' => $x,
'y' => $y_id_to_index[$evkey],
'z' => $tvalue,
'label' => @$xlabels_long[$x] . ' / ' . @$ylabels_long[$y_id_to_index[$evkey]] . ': <b>' .
$e->teachervaluetitles[$evkey] . '</b>',
];
$graph_data["{$data_value->x}-{$data_value->y}-{$data_value->z}"] = $data_value;
}
/*if ($e->teachervalue >= 0 && isset($y_id_to_index[$e->evalniveau])) {
$data_value = (object) [
'x' => $x,
'y' => $y_id_to_index[$e->evalniveau],
'z' => $e->teachervalue,
'label' => @$xlabels_long[$x].' / '.@$ylabels_long[$y_id_to_index[$e->evalniveau]].': <b>'.
$e->teachervaluetitle.'</b>',
];
$graph_data["{$data_value->x}-{$data_value->y}-{$data_value->z}"] = $data_value;
}*/
}
}
/*
var title = evalniveau_titles_by_index[point.y] ? evalniveau_titles_by_index[point.y].title : '' || '';
var value
if (evalniveau_titles_by_index[point.y].id == student_value_id) {
value = exacomp_data.value_titles_self_assessment[point.z];
} else {
value = exacomp_data.value_titles_long[Object.keys(exacomp_data.value_titles)[point.z]];
}
return title + ' <b>' + value + '</b>';
*/
$x++;
}
$output = block_exacomp_get_renderer();
$output->requires()->js('/blocks/exacomp/javascript/vis.js', true);
// build tab navigation & print header
$PAGE->set_pagelayout('embedded');
echo $output->header_v2();
echo '<script> exacomp_graph = ' . json_encode($exacomp_graph) . '; </script>';
/* CONTENT REGION */
if (!$exacomp_graph->data) {
echo block_exacomp_get_string('topic_3dchart_empty');
} else {
echo html_writer::div(null, null, array('id' => 'mygraph'));
}
/* END CONTENT REGION */
echo $output->footer();