-
-
-
-
-
-
- | {{dimension_header}} |
- {{score_header}} |
- {{preference_header}} |
-
-
-
- {{#score_rows}}
-
- | {{label1}} - {{label2}} |
- {{value1}} - {{value2}} |
- {{dominant}} |
-
- {{/score_rows}}
-
-
+
+
+
+
+
+
+
+
{{score_header}}
+
+
+ {{#score_rows}}
+
+
+
+
{{label1}}
+
+ {{value1}}
+
+
+
+
+
vs
+
+
+
+
{{label2}}
+
+ {{value2}}
+
+
+
+ {{/score_rows}}
+
+
+
+
{{radar_chart_title}}
+
+
+
+
+ {{#can_view_reports}}
{{back_to_admin_label}}
+ {{/can_view_reports}}
{{back_to_course_label}}
diff --git a/templates/student_continue.mustache b/templates/student_continue.mustache
index 3fefe20..89de0ce 100644
--- a/templates/student_continue.mustache
+++ b/templates/student_continue.mustache
@@ -5,12 +5,14 @@
{{#str}}discover_your_personality, block_personality_test{{/str}}
+ {{#showdescriptions}}
{{#str}}test_description, block_personality_test{{/str}}
+ {{/showdescriptions}}
{{#all_answered}}
diff --git a/templates/student_invitation.mustache b/templates/student_invitation.mustache
index 10befd9..d12967a 100644
--- a/templates/student_invitation.mustache
+++ b/templates/student_invitation.mustache
@@ -5,6 +5,7 @@
{{#str}}discover_your_personality, block_personality_test{{/str}}
+ {{#showdescriptions}}
+ {{/showdescriptions}}
{{#str}}test_completed, block_personality_test{{/str}}
-
{{#str}}your_personality_type, block_personality_test{{/str}}
+
{{#str}}your_results_here, block_personality_test{{/str}}
+ {{#showdescriptions}}
{{#str}}test_description, block_personality_test{{/str}}
+ {{/showdescriptions}}
-
{{mbti_score}}
-
{{mbti_dimensions_str}}
+
+
+
+
+
+
{{mbti_score}}
+ {{mbti_dimensions_str}}
+
+
+
-
- {{{mbti_description}}}
-
-
-
+
{{#js}}
require(['jquery'], function($) {
diff --git a/templates/test_view.mustache b/templates/test_view.mustache
index 3774a69..5ec269f 100644
--- a/templates/test_view.mustache
+++ b/templates/test_view.mustache
@@ -142,8 +142,8 @@ document.querySelectorAll('.answer-btn').forEach(function(button) {
clearTimeout(autoSaveTimer);
}
- // Auto-save after 2 seconds of inactivity
- autoSaveTimer = setTimeout(autoSaveProgress, 2000);
+ // Auto-save after 400ms of inactivity
+ autoSaveTimer = setTimeout(autoSaveProgress, 400);
});
});
diff --git a/version.php b/version.php
index 6855bb5..af28399 100644
--- a/version.php
+++ b/version.php
@@ -1,7 +1,7 @@
version = 2026010800;
+$plugin->version = 2026011800; // YYYYMMDDXX (year, month, day, 2-digit version number).
$plugin->requires = 2022041900; // Moodle 4.0+
$plugin->component = 'block_personality_test';
$plugin->maturity = MATURITY_STABLE;
-$plugin->release = '2.0.2';
+$plugin->release = '2.0.3';
diff --git a/view.php b/view.php
index 73efa5b..7e748a3 100644
--- a/view.php
+++ b/view.php
@@ -44,7 +44,7 @@
// If test is completed, redirect to results
if ($existing_response && $existing_response->is_completed) {
- redirect(new moodle_url('/course/view.php', array('id' => $courseid)),
+ redirect(new moodle_url('/blocks/personality_test/view_individual.php', array('cid' => $courseid, 'userid' => $USER->id)),
get_string('test_completed_redirect', 'block_personality_test'),
null, \core\output\notification::NOTIFY_INFO);
}
diff --git a/view_individual.php b/view_individual.php
index 1dc12ed..be6efb0 100644
--- a/view_individual.php
+++ b/view_individual.php
@@ -14,59 +14,71 @@
$userid = required_param('userid', PARAM_INT);
$courseid = required_param('cid', PARAM_INT);
-
-// Verificar permisos: solo administradores y profesores
-$isadmin = is_siteadmin($USER);
-$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($courseid);
-// Check if the block is added to the course
-if (!$DB->record_exists('block_instances', array('blockname' => 'personality_test', 'parentcontextid' => $context->id))) {
- redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
-}
+$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
+$test_result = $DB->get_record('personality_test', array('user' => $userid));
+
+// Verificar permisos y manejo de privacidad
+$is_own_results = ($USER->id == $userid);
+$can_view_reports = has_capability('block/personality_test:viewreports', $context);
+$is_siteadmin = is_siteadmin($USER);
-// Silent redirect if user lacks report capability
-if (!has_capability('block/personality_test:viewreports', $context)) {
+// Acceso básico: Si no es propietario, ni profesor (con permisos), ni admin -> Redirigir
+if (!$is_own_results && !$can_view_reports && !$is_siteadmin) {
redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
}
-// Obtener datos del usuario y test
-$userfields = \core_user\fields::for_name()->with_userpic()->get_sql('', false, '', '', false)->selects;
-$user = $DB->get_record('user', array('id' => $userid), $userfields, MUST_EXIST);
-$test_result = $DB->get_record('personality_test', array('user' => $userid));
-
-// Prevent teachers from viewing students outside their groups unless they can access all groups
-if (!is_siteadmin($USER)) {
- // If the current user has accessallgroups, allow
+// Check if teacher can access this specific user info (Grouping check)
+// Si no es admin y no son sus propios resultados...
+if (!$is_siteadmin && !$is_own_results) {
+ // Si el usuario tiene la capacidad de ver todos los grupos, permitir.
if (!has_capability('moodle/site:accessallgroups', $context)) {
- // Get groups for teacher and target student
- list($teachergroups, $tg) = groups_get_user_groups($courseid, $USER->id);
- list($studentgroups, $sg) = groups_get_user_groups($courseid, $userid);
-
- // If both have groups defined and no intersection, redirect silently
- if (!empty($teachergroups) && !empty($studentgroups)) {
- $common = array_intersect($teachergroups, $studentgroups);
- if (empty($common)) {
- redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
- }
- }
- // If teacher has no groups but student does, block access (teacher not in student's group)
- if (empty($teachergroups) && !empty($studentgroups)) {
- redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
+ // Obtener grupos del profesor y del estudiante objetivo
+ $usergroups = groups_get_all_groups($courseid, $userid);
+ $teachergroups = groups_get_all_groups($courseid, $USER->id);
+
+ // Si ambos tienen grupos y no hay intersección, bloquear.
+ if (!empty($usergroups) && !empty($teachergroups)) {
+ $usergroupids = array_keys($usergroups);
+ $teachergroupids = array_keys($teachergroups);
+ $intersection = array_intersect($usergroupids, $teachergroupids);
+
+ if (empty($intersection)) {
+ redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
+ }
}
+ // Nota: Si el curso está en modo grupos separados y el profe no está en ningun grupo,
+ // o el estudiante no está en ninguno, Moodle suele manejarlo con accessallgroups.
+ // Asumimos aquí una comprobación básica de grupos.
+ }
+
+ // Cross-course privacy check: Ensure target user is enrolled in this course context
+ if (!is_enrolled($context, $user)) {
+ redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
}
}
+
if (!$test_result) {
+ if ($is_own_results) {
+ // Si es el estudiante viendo sus "resultados" inexistentes, mandar al bloque para que lo haga
+ redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
+ }
redirect(new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid)),
get_string('no_test_results', 'block_personality_test'));
}
+// Si está incompleto y es el estudiante, sacarlo antes de pintar nada
+if ($test_result->is_completed == 0 && $is_own_results) {
+ redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
+}
+
// Configurar página
$PAGE->set_url(new moodle_url('/blocks/personality_test/view_individual.php', array('userid' => $userid, 'cid' => $courseid)));
$PAGE->set_context($context);
-$PAGE->set_title(get_string('individual_results', 'block_personality_test') . ': ' . fullname($user));
-$PAGE->set_heading(get_string('individual_results', 'block_personality_test') . ': ' . fullname($user));
+$PAGE->set_title(get_string('individual_results', 'block_personality_test'));
+$PAGE->set_heading(get_string('individual_results', 'block_personality_test'));
$PAGE->requires->css(new moodle_url('/blocks/personality_test/styles.css'));
@@ -84,9 +96,12 @@
$answered++;
}
}
+ $progress_percentage = ($answered / 72) * 100;
- $progress_percentage = round(($answered / 72) * 100, 1);
-
+ // Url de retorno depende de quien ve
+ $back_url = $can_view_reports ? (new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid)))->out() : (new moodle_url('/course/view.php', array('id' => $courseid)))->out();
+ $back_label = $can_view_reports ? get_string('back_to_admin', 'block_personality_test') : get_string('back_to_course', 'block_personality_test');
+
$template_data = [
'in_progress' => true,
'is_completed' => false,
@@ -99,8 +114,8 @@
'show_submit_reminder' => ($answered == 72),
'remind_submit_test' => get_string('remind_submit_test', 'block_personality_test'),
'results_available_message' => get_string('results_available_when_complete', 'block_personality_test', fullname($user)),
- 'back_url' => (new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid)))->out(),
- 'back_to_admin_label' => get_string('back_to_admin', 'block_personality_test')
+ 'back_url' => $back_url,
+ 'back_to_admin_label' => $back_label
];
} else {
@@ -153,6 +168,38 @@
'dominant' => $dominant
];
}
+
+ // --- Radar Chart Logic Injection ---
+ $mbti_labels = [
+ get_string('introversion', 'block_personality_test'),
+ get_string('feeling', 'block_personality_test'),
+ get_string('sensing', 'block_personality_test'),
+ get_string('perceptive', 'block_personality_test'),
+ get_string('extraversion', 'block_personality_test'),
+ get_string('thinking', 'block_personality_test'),
+ get_string('intuition', 'block_personality_test'),
+ get_string('judging', 'block_personality_test')
+ ];
+
+ $chart_data = [
+ (float)$test_result->introversion,
+ (float)$test_result->feeling,
+ (float)$test_result->sensing,
+ (float)$test_result->perceptive,
+ (float)$test_result->extraversion,
+ (float)$test_result->thinking,
+ (float)$test_result->intuition,
+ (float)$test_result->judging,
+ ];
+
+ $chart_id = 'graficoRadarIndividual_' . $userid;
+ $PAGE->requires->js_call_amd('block_personality_test/results_radar', 'init', [
+ $chart_id,
+ $mbti_labels,
+ $chart_data,
+ get_string('mbti_type', 'block_personality_test') . ': ' . $mbti
+ ]);
+ // -----------------------------------
$template_data = [
'in_progress' => false,
@@ -167,12 +214,15 @@
'mbti_label' => get_string('mbti_type', 'block_personality_test'),
'mbti_type' => $mbti,
'dimensions_title' => get_string('personality_dimensions', 'block_personality_test'),
+ 'radar_chart_title' => get_string('radar_chart_title', 'block_personality_test'),
'dimension_bars' => $dimension_bars,
'summary_actions_title' => get_string('summary_actions', 'block_personality_test'),
'mbti_dimensions_str' => get_string($mbti_dimensions_key, 'block_personality_test'),
'mbti_description' => get_string($mbti_key, 'block_personality_test'),
'download_url' => (new moodle_url('/blocks/personality_test/download_pdf.php', array('userid' => $userid, 'cid' => $courseid)))->out(false),
'download_pdf_label' => get_string('download_pdf', 'block_personality_test'),
+ // Permissions for delete action
+ 'can_delete' => $can_view_reports,
'delete_url' => (new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid, 'action' => 'delete', 'userid' => $userid, 'sesskey' => sesskey())))->out(false),
'confirm_delete_msg' => get_string('confirm_delete_individual', 'block_personality_test'),
'delete_results_label' => get_string('delete_results', 'block_personality_test'),
@@ -181,6 +231,10 @@
'score_header' => get_string('score', 'block_personality_test'),
'preference_header' => get_string('preference', 'block_personality_test'),
'score_rows' => $score_rows,
+ // Chart Data
+ 'chart_id' => $chart_id,
+ // Nav
+ 'can_view_reports' => $can_view_reports,
'back_to_admin_url' => (new moodle_url('/blocks/personality_test/admin_view.php', array('cid' => $courseid)))->out(false),
'back_to_admin_label' => get_string('back_to_admin', 'block_personality_test'),
'back_to_course_url' => (new moodle_url('/course/view.php', array('id' => $courseid)))->out(false),