-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchoose.php
More file actions
70 lines (56 loc) · 2.56 KB
/
choose.php
File metadata and controls
70 lines (56 loc) · 2.56 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
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Display information about all the mod_choicepath modules in the requested course.
*
* @package mod_choicepath
* @copyright 2024 Willian Mano <willianmanoaraujo@gmail.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
$cmid = required_param('cmid', PARAM_INT);
$id = required_param('id', PARAM_INT);
$cm = get_coursemodule_from_id('choicepath', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$moduleinstance = $DB->get_record('choicepath', ['id' => $cm->instance], '*', MUST_EXIST);
$option = $DB->get_record('choicepath_options', ['id' => $id, 'choicepathid' => $moduleinstance->id], '*', MUST_EXIST);
require_login($course, true, $cm);
$redirecturl = new moodle_url('/mod/choicepath/view.php', ['id' => $cmid]);
if (!confirm_sesskey()) {
redirect($redirecturl, get_string('invaliddata', 'error'), null, \core\output\notification::NOTIFY_ERROR);
}
try {
$hasanswer = $DB->get_record('choicepath_answers', [
'choicepathid' => $moduleinstance->id,
'userid' => $USER->id
]);
if ($hasanswer) {
redirect($redirecturl, get_string('choosepath:hasanswer', 'mod_choicepath'), null, \core\output\notification::NOTIFY_ERROR);
}
$answer = new stdClass();
$answer->choicepathid = $moduleinstance->id;
$answer->optionid = $option->id;
$answer->userid = $USER->id;
$answer->timecreated = time();
$answer->timemodified = time();
$DB->insert_record('choicepath_answers', $answer);
redirect($redirecturl, get_string('choosepath:success', 'mod_choicepath'), null, \core\output\notification::NOTIFY_SUCCESS);
} catch (Exception $ex) {
if ($CFG->debug) {
throw $ex;
}
redirect($redirecturl, get_string('something_went_wrong', 'mod_choicepath'), null, \core\output\notification::NOTIFY_ERROR);
}