Repository navigation
Expand file tree
/
Copy pathblock_learning_style.php
More file actions
344 lines (296 loc) · 12.4 KB
/
Copy pathblock_learning_style.php
File metadata and controls
344 lines (296 loc) · 12.4 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
/**
* Learning Style Block
*
* @package block_learning_style
* @copyright 2026 SAVIO - Sistema de Aprendizaje Virtual Interactivo (UTB)
* @author SAVIO Development Team
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_learning_style extends block_base
{
public function init()
{
$this->title = get_string('pluginname', 'block_learning_style');
}
public function instance_allow_multiple()
{
return false;
}
public function my_slider($value, $izq_val, $der_val, $izq_title, $der_title) {
$rawp = (($value + 11) / 22) * 100;
$p = $rawp;
$edgeclass = '';
$markertransform = '';
if ($p <= 0) {
$p = 0;
$edgeclass = ' ls-edge-left';
$markertransform = ' transform: translateX(0);';
} else if ($p >= 100) {
$p = 100;
$edgeclass = ' ls-edge-right';
$markertransform = ' transform: translateX(-100%);';
}
// Determinar si predomina la derecha o izquierda.
$predomina_izq = $p < 50;
// Armar etiquetas con botón si es dominante (escapando atributos/texto).
$buttonattrs = [
'data-placement' => 'top',
'role' => 'button',
'tabindex' => '0',
'style' => 'background: none; color: #000; font-weight: 700; border: none;text-transform: none;font-size: 16px;padding: 0;cursor: pointer;text-decoration: none;',
'data-toggle' => 'popover',
'data-trigger' => 'focus',
];
if ($predomina_izq) {
$izq_label = html_writer::tag('a', s($izq_val), $buttonattrs + [
'title' => s($izq_val),
'data-content' => s($izq_title),
]);
} else {
$izq_label = html_writer::tag('span', s($izq_val), ['title' => s($izq_title)]);
}
if (!$predomina_izq) {
$der_label = html_writer::tag('a', s($der_val), $buttonattrs + [
'title' => s($der_val),
'data-content' => s($der_title),
]);
} else {
$der_label = html_writer::tag('span', s($der_val), ['title' => s($der_title)]);
}
$slider = html_writer::start_div('slider-container', ['style' => 'text-align:center; margin: 10px 0px;']);
$slider .= $izq_label . ' ⇄ ' . $der_label . html_writer::empty_tag('br');
// Barra de progreso con marca.
$slider .= html_writer::start_tag('div', [
'class' => 'progress learning-style-progress' . $edgeclass,
'style' => 'position: relative; height: 20px;'
]);
$slider .= html_writer::tag('div', '', [
'class' => 'center_mark',
'style' => 'left: 50%; width: 1px; background: #a8a8a8;',
]);
$slider .= html_writer::tag('div', '', [
'class' => 'center_mark',
'style' => 'left: ' . (float)$p . '%;' . $markertransform,
]);
$slider .= html_writer::end_tag('div');
$slider .= html_writer::end_div();
return $slider;
}
/**
* Main content generator
*/
public function get_content() {
global $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
if ($COURSE->id == SITEID) {
return $this->content;
}
if (empty($this->instance)) {
return $this->content;
}
if (!isloggedin()) {
return $this->content;
}
$context = context_course::instance($COURSE->id);
$this->page->requires->css('/blocks/learning_style/styles.css');
if ($this->can_view_dashboard($context)) {
$this->content->text = $this->get_teacher_content($context);
} else if ($this->is_student($context)) {
$this->content->text = $this->get_student_content();
}
return $this->content;
}
/**
* Check if user can view dashboard
*/
private function can_view_dashboard($context, $userid = null) {
return has_capability('block/learning_style:viewstudentdata', $context, $userid);
}
/**
* Check if user is a student
*/
private function is_student($context) {
return has_capability('block/learning_style:take_test', $context);
}
/**
* Generate content for students
*/
private function get_student_content() {
global $DB, $USER;
$entry = $DB->get_record('learning_style', array('user' => $USER->id));
if (!$entry) {
return $this->get_test_invitation();
}
if (isset($entry->is_completed) && $entry->is_completed == 0) {
$answered = 0;
for ($i = 1; $i <= 44; $i++) {
$field = "q{$i}";
if (isset($entry->$field) && $entry->$field !== null) {
$answered++;
}
}
return $this->get_continue_test_card($answered);
}
return $this->render_results($entry);
}
/**
* Render results and chart
*/
private function render_results($entry) {
global $COURSE, $OUTPUT;
$results_cards = [];
// Definition of dimensions and icons
// Processing: Active vs Reflexive
if ($entry->ap_active >= $entry->ap_reflexivo) {
$results_cards[] = [
'dimension' => get_string('processing_dimension', 'block_learning_style'),
'style' => get_string('active', 'block_learning_style'),
'icon' => 'fa-bolt'
];
} else {
$results_cards[] = [
'dimension' => get_string('processing_dimension', 'block_learning_style'),
'style' => get_string('reflexive', 'block_learning_style'),
'icon' => 'fa-lightbulb-o'
];
}
// Perception: Sensorial vs Intuitive
if ($entry->ap_sensorial >= $entry->ap_intuitivo) {
$results_cards[] = [
'dimension' => get_string('perception_dimension', 'block_learning_style'),
'style' => get_string('sensorial', 'block_learning_style'),
'icon' => 'fa-wrench'
];
} else {
$results_cards[] = [
'dimension' => get_string('perception_dimension', 'block_learning_style'),
'style' => get_string('intuitive', 'block_learning_style'),
'icon' => 'fa-puzzle-piece'
];
}
// Input: Visual vs Verbal
if ($entry->ap_visual >= $entry->ap_verbal) {
$results_cards[] = [
'dimension' => get_string('input_dimension', 'block_learning_style'),
'style' => get_string('visual', 'block_learning_style'),
'icon' => 'fa-eye'
];
} else {
$results_cards[] = [
'dimension' => get_string('input_dimension', 'block_learning_style'),
'style' => get_string('verbal', 'block_learning_style'),
'icon' => 'fa-comments-o'
];
}
// Understanding: Sequential vs Global
if ($entry->ap_secuencial >= $entry->ap_global) {
$results_cards[] = [
'dimension' => get_string('understanding_dimension', 'block_learning_style'),
'style' => get_string('sequential', 'block_learning_style'),
'icon' => 'fa-list-ol'
];
} else {
$results_cards[] = [
'dimension' => get_string('understanding_dimension', 'block_learning_style'),
'style' => get_string('global', 'block_learning_style'),
'icon' => 'fa-globe'
];
}
$template_data = [
'icon' => $this->get_learning_style_icon('4em', 'display: block;', false),
'results_cards' => $results_cards,
'summary_url' => (new moodle_url('/blocks/learning_style/view_individual.php', ['courseid' => $COURSE->id, 'userid' => $entry->user]))->out(false),
'instanceid' => $this->instance->id,
'showdescriptions' => !empty($this->config->showdescriptions)
];
return $OUTPUT->render_from_template('block_learning_style/results', $template_data);
}
/**
* Generate content for teachers/admins
*/
private function get_teacher_content($context) {
global $COURSE, $OUTPUT;
return $OUTPUT->render_from_template('block_learning_style/admin_launcher', [
'icon_html' => $this->get_learning_style_icon('4em', '', true),
'security_label' => get_string('sensitive_data', 'block_learning_style'),
'title' => get_string('management_title', 'block_learning_style'),
'admin_url' => (new moodle_url('/blocks/learning_style/admin_view.php', ['courseid' => $COURSE->id]))->out(false),
'button_label' => get_string('open_admin_panel', 'block_learning_style'),
]);
}
/**
* Get the learning style icon HTML (SVG)
*/
private function get_learning_style_icon($size = '1.8em', $additional_style = '', $centered = false) {
global $CFG;
$iconurl = new moodle_url('/blocks/learning_style/pix/icon.svg');
// NOTE: styles.css has a legacy rule that floats all images in the block.
// This icon must never float, otherwise it cannot be centered.
$style = 'width: ' . $size . '; height: ' . $size . '; vertical-align: middle; float: none !important;';
if ($centered) {
$style .= ' display: block; margin: 0 auto;';
}
if ($additional_style) {
$style .= ' ' . $additional_style;
}
return '<img class="learning-style-icon" src="' . $iconurl . '" alt="Learning Style Icon" style="' . $style . '" />';
}
/**
* Método para mostrar la invitación al test de estilos de aprendizaje
*/
private function get_test_invitation() {
global $COURSE, $OUTPUT;
$template_data = [
'icon' => $this->get_learning_style_icon('4em', '', true),
'url' => (new moodle_url('/blocks/learning_style/view.php', array('cid' => $COURSE->id)))->out(),
'showdescriptions' => !empty($this->config->showdescriptions)
];
return $OUTPUT->render_from_template('block_learning_style/test_invitation', $template_data);
}
/**
* Display continue test card for students with test in progress
*/
private function get_continue_test_card($answered_count) {
global $COURSE, $OUTPUT;
$progress_percentage = ($answered_count / 44) * 100;
$all_answered = ($answered_count == 44);
// Change button text, icon and URL based on completion status
if ($all_answered) {
$button_text = get_string('finish_test', 'block_learning_style');
$button_icon = 'fa-flag-checkered';
$button_class = 'btn-success';
$questions_per_page = 11;
$total_questions = 44;
$last_page = (int)ceil($total_questions / $questions_per_page);
$url = new moodle_url('/blocks/learning_style/view.php', array(
'cid' => $COURSE->id,
'page' => $last_page,
'scroll_to_finish' => 1
));
} else {
$button_text = get_string('continue_test', 'block_learning_style');
$button_icon = 'fa-play';
$button_class = 'btn-warning';
$url = new moodle_url('/blocks/learning_style/view.php', array('cid' => $COURSE->id));
}
$template_data = [
'icon' => $this->get_learning_style_icon('4em', 'filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));', true),
'answered_count' => $answered_count,
'progress_percentage' => $progress_percentage,
'formatted_percentage' => number_format($progress_percentage, 1),
'all_answered' => $all_answered,
'url' => $url->out(false),
'button_text' => $button_text,
'button_icon' => $button_icon,
'button_class' => $button_class,
'showdescriptions' => !empty($this->config->showdescriptions)
];
return $OUTPUT->render_from_template('block_learning_style/continue_test', $template_data);
}
}