-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnonmoodlefeedback.php
89 lines (79 loc) · 3.51 KB
/
nonmoodlefeedback.php
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
<?php
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
/**
* Add/edit users non-Moodle(turnitin) feedback turnitin grade item
*
* This file handles the addition and editing of non-Moodle (Turnitin) feedback
* for users' grade items in the My Feedback report.
*
* @package report_myfeedback
* @copyright 2022 UCL
* @author Delvon Forrester <delvon@esparanza.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_login();
require_once($CFG->dirroot . '/report/myfeedback/lib.php');
$feedname = optional_param('feedname', '', PARAM_NOTAGS);
$gradeid = optional_param('gradeid2', 0, PARAM_INT);
$userid = optional_param('userid2', 0, PARAM_INT);
$instance = optional_param('instance', 0, PARAM_INT);
$report = new \report_myfeedback\local\report();
// Check if the current user can add non-Moodle feedback for this user and
// grade item.
$gradeitem = $DB->get_record('grade_items', ['id' => $gradeid], '*', MUST_EXIST);
$coursecontext = context_course::instance($gradeitem->courseid);
require_capability('report/myfeedback:addnonfeedback', $coursecontext);
if (!is_enrolled($coursecontext, $userid)) {
throw new moodle_exception('studentnotincourse', 'report_myfeedback');
}
if (!empty($feedname) && $gradeid && $userid) {
$feednotes = strip_tags($feedname, '<br>');
$now = time();
$sql = "SELECT feedback FROM {report_myfeedback}
WHERE userid=? AND gradeitemid=? AND iteminstance=?";
$sql1 = "UPDATE {report_myfeedback}
SET modifierid=?, feedback=?, timemodified=?
WHERE userid=? AND gradeitemid=? AND iteminstance=?";
$sql2 = "INSERT INTO {report_myfeedback}
(userid, gradeitemid, modifierid, iteminstance, feedback, timemodified)
VALUES (?, ?, ?, ?, ?, ?)";
$params = [$userid, $gradeid, $instance];
$params1 = [$USER->id, $feednotes, $now, $userid, $gradeid, $instance];
$params2 = [$userid, $gradeid, $USER->id, $instance, $feednotes, $now];
$userfeedback = $DB->get_record_sql($sql, $params);
$event = \report_myfeedback\event\myfeedbackreport_addfeedback::create(
['context' => context_user::instance($userid), 'relateduserid' => $userid]
);
if ($userfeedback) {
$DB->execute($sql1, $params1);
echo get_string('updatesuccessful', 'report_myfeedback');
$event = \report_myfeedback\event\myfeedbackreport_updatefeedback::create(
['context' => context_user::instance($userid), 'relateduserid' => $userid]
);
} else {
$DB->execute($sql2, $params2);
echo get_string('insertsuccessful', 'report_myfeedback');
}
$event->trigger();
redirect(new \moodle_url('/report/myfeedback/index.php',
[
'userid' => $userid,
'currenttab' => 'feedback',
'sesskey' => sesskey(),
]
));
}