96 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
require_once('../../config.php');
|
|
|
5 |
|
|
|
6 |
defined('MOODLE_INTERNAL') || die();
|
|
|
7 |
|
|
|
8 |
global $CFG, $DB, $COURSE;
|
|
|
9 |
|
|
|
10 |
$id = required_param('id', PARAM_INT); // Course Module ID.
|
|
|
11 |
$rating = required_param('rating', PARAM_INT); // User selection.
|
|
|
12 |
|
1055 |
ariadna |
13 |
if (! $course = $DB->get_record('course', array('id' => $id))) {
|
96 |
efrain |
14 |
print_error('Course ID not found');
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
require_login($course, false);
|
|
|
18 |
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
|
|
|
19 |
print_error('nocontext');
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
require_capability('block/cesa_course_rating:rate', $context);
|
|
|
24 |
global $USER;
|
|
|
25 |
|
|
|
26 |
if ($form = data_submitted()) {
|
1055 |
ariadna |
27 |
if ($DB->count_records('block_cesa_course_rating', array('course' => $COURSE->id, 'user' => $USER->id))) {
|
|
|
28 |
$test = $DB->get_record('block_cesa_course_rating', array('course' => $COURSE->id, 'user' => $USER->id));
|
|
|
29 |
$DB->update_record('block_cesa_course_rating', array('id' => $test->id, 'rating' => $rating));
|
96 |
efrain |
30 |
} else {
|
|
|
31 |
|
1055 |
ariadna |
32 |
$DB->insert_record('block_cesa_course_rating', array('course' => $COURSE->id, 'user' => $USER->id, 'rating' => $rating));
|
96 |
efrain |
33 |
}
|
1056 |
ariadna |
34 |
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 |
35 |
}
|