96 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once('../../config.php');
|
|
|
4 |
|
|
|
5 |
defined('MOODLE_INTERNAL') || die();
|
|
|
6 |
|
|
|
7 |
global $CFG, $DB, $COURSE;
|
|
|
8 |
|
1101 |
ariadna |
9 |
$id = required_param('id', PARAM_INT); // Course Module ID.
|
|
|
10 |
$rating = required_param('rating', PARAM_INT); // User selection.
|
96 |
efrain |
11 |
|
1055 |
ariadna |
12 |
if (! $course = $DB->get_record('course', array('id' => $id))) {
|
96 |
efrain |
13 |
print_error('Course ID not found');
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
require_login($course, false);
|
|
|
17 |
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
|
|
|
18 |
print_error('nocontext');
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
require_capability('block/cesa_course_rating:rate', $context);
|
|
|
22 |
global $USER;
|
|
|
23 |
|
1101 |
ariadna |
24 |
// Validación: Verificar si el usuario ya ha calificado este curso
|
|
|
25 |
if ($DB->record_exists('block_cesa_course_rating', array('course' => $COURSE->id, 'user' => $USER->id))) {
|
|
|
26 |
redirect($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, get_string('already_rated', 'block_cesa_course_rating'), null, \core\output\notification::NOTIFY_WARNING);
|
|
|
27 |
}
|
|
|
28 |
|
96 |
efrain |
29 |
if ($form = data_submitted()) {
|
1101 |
ariadna |
30 |
// Si el usuario no ha calificado, se inserta el registro
|
|
|
31 |
$DB->insert_record('block_cesa_course_rating', array('course' => $COURSE->id, 'user' => $USER->id, 'rating' => $rating));
|
1056 |
ariadna |
32 |
redirect($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, get_string('rating_success', 'block_cesa_course_rating'), null, \core\output\notification::NOTIFY_SUCCESS);
|
96 |
efrain |
33 |
}
|