-
Notifications
You must be signed in to change notification settings - Fork 6
/
edit_instance.php
115 lines (90 loc) · 4.11 KB
/
edit_instance.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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/>.
/**
* Verbalfeedback items management page.
*
* @package mod_verbalfeedback
* @copyright 2020 Kevin Tippenhauer <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
use mod_verbalfeedback\repository\instance_repository;
require_once("../../config.php");
$cmid = required_param('id', PARAM_INT);
$itemid = optional_param('itemid', 0, PARAM_INT);
$makeavailable = optional_param('makeavailable', false, PARAM_BOOL);
$viewurl = new moodle_url('view.php');
$viewurl->param('id', $cmid);
if ($cmid == 0) {
throw new moodle_exception('errorverbalfeedbacknotfound', 'mod_verbalfeedback', $viewurl);
}
$PAGE->set_url('/mod/verbalfeedback/edit_instance.php', ['id' => $cmid]);
if (!$cm = get_coursemodule_from_id('verbalfeedback', $cmid)) {
throw new moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", ["id" => $cm->course])) {
throw new moodle_exception('coursemisconf');
}
require_login($course, true, $cm);
// Quick hack for issue #43.
ini_set('memory_limit', '256M');
$instancerepository = new instance_repository();
if (!$instance = $instancerepository->get_by_id($cm->instance)) {
throw new moodle_exception('errorverbalfeedbacknotfound', 'mod_verbalfeedback', $viewurl);
}
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
// If rescaling is required save the new maximum.
$maxgrade = unformat_float(optional_param('maxgrade', '', PARAM_RAW_TRIMMED), true);
if (is_float($maxgrade) && $maxgrade >= 0) {
\mod_verbalfeedback\utils\instance_utils::verbalfeedback_set_grade($maxgrade, $instance);
verbalfeedback_grade_item_update($instance);
verbalfeedback_update_grades($instance, 0, true);
}
redirect(new moodle_url('/mod/verbalfeedback/edit_instance.php', ['id' => $cmid]));
}
// Check capability to edit items.
$context = context_module::instance($cm->id);
if (!\mod_verbalfeedback\utils\user_utils::can_edit_items($instance->get_id(), $context)) {
throw new moodle_exception('nocaptoedititems', 'mod_verbalfeedback', $viewurl);
}
$question = '';
$questiontype = 0;
$questioncategory = 0;
$PAGE->navbar->add(get_string('titlemanageitems', 'verbalfeedback'));
$PAGE->set_heading($course->fullname);
$PAGE->set_title($instance->get_name());
echo $OUTPUT->header();
// Print the main part of the page.
echo $OUTPUT->heading(format_string($instance->get_name()));
echo $OUTPUT->heading(get_string('edititems', 'mod_verbalfeedback'), 3);
$viewurl = new moodle_url('/mod/verbalfeedback/view.php', ['id' => $cm->id]);
$previewurl = new moodle_url('/mod/verbalfeedback/questionnaire.php', ['instance' => $instance->get_id(), 'preview' => true]);
$maxgrade = $instance->get_grade();
// Check if we can make the activity available from here.
$instanceready = $instancerepository->is_ready($instance->get_id());
$makeavailableurl = null;
if (!$instanceready) {
// Check if we can make the instance available to the respondents.
if ($instancerepository->has_items($instance->get_id())) {
$makeavailableurl = clone $viewurl;
$makeavailableurl->param('makeavailable', true);
}
}
// Verbalfeedback item list.
$itemslist = new mod_verbalfeedback\output\list_verbalfeedback_items($cmid, $course->id, $instance->get_id(), $viewurl, $previewurl,
$makeavailableurl, $maxgrade);
$itemslistoutput = $PAGE->get_renderer('mod_verbalfeedback');
echo $itemslistoutput->render($itemslist);
echo $OUTPUT->footer();