1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* prints the form to edit the feedback items such moving, deleting and so on
|
|
|
19 |
*
|
|
|
20 |
* @author Andreas Grabs
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
22 |
* @package mod_feedback
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../../config.php');
|
|
|
26 |
require_once('lib.php');
|
|
|
27 |
|
|
|
28 |
feedback_init_feedback_session();
|
|
|
29 |
|
|
|
30 |
$id = required_param('id', PARAM_INT);
|
|
|
31 |
|
|
|
32 |
if (($formdata = data_submitted()) AND !confirm_sesskey()) {
|
|
|
33 |
throw new \moodle_exception('invalidsesskey');
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
$switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
|
|
|
37 |
$deleteitem = optional_param('deleteitem', false, PARAM_INT);
|
|
|
38 |
|
|
|
39 |
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
|
|
|
40 |
|
|
|
41 |
$context = context_module::instance($cm->id);
|
|
|
42 |
require_login($course, false, $cm);
|
|
|
43 |
require_capability('mod/feedback:edititems', $context);
|
|
|
44 |
$feedback = $PAGE->activityrecord;
|
|
|
45 |
$feedbackstructure = new mod_feedback_structure($feedback, $cm);
|
|
|
46 |
$url = new moodle_url('/mod/feedback/edit.php', ['id' => $cm->id]);
|
|
|
47 |
|
|
|
48 |
if ($switchitemrequired) {
|
|
|
49 |
require_sesskey();
|
|
|
50 |
$items = $feedbackstructure->get_items();
|
|
|
51 |
if (isset($items[$switchitemrequired])) {
|
|
|
52 |
feedback_switch_item_required($items[$switchitemrequired]);
|
|
|
53 |
}
|
|
|
54 |
redirect($url);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if ($deleteitem) {
|
|
|
58 |
require_sesskey();
|
|
|
59 |
$items = $feedbackstructure->get_items();
|
|
|
60 |
if (isset($items[$deleteitem])) {
|
|
|
61 |
feedback_delete_item($deleteitem);
|
|
|
62 |
}
|
|
|
63 |
redirect($url);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// Process the create template form.
|
|
|
67 |
$cancreatetemplates = has_capability('mod/feedback:createprivatetemplate', $context) ||
|
|
|
68 |
has_capability('mod/feedback:createpublictemplate', $context);
|
|
|
69 |
|
|
|
70 |
//Get the feedbackitems
|
|
|
71 |
$lastposition = 0;
|
|
|
72 |
$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
|
|
|
73 |
if (is_array($feedbackitems)) {
|
|
|
74 |
$feedbackitems = array_values($feedbackitems);
|
|
|
75 |
if (count($feedbackitems) > 0) {
|
|
|
76 |
$lastitem = $feedbackitems[count($feedbackitems)-1];
|
|
|
77 |
$lastposition = $lastitem->position;
|
|
|
78 |
} else {
|
|
|
79 |
$lastposition = 0;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
$lastposition++;
|
|
|
83 |
|
|
|
84 |
$PAGE->set_url($url);
|
|
|
85 |
$PAGE->set_heading($course->fullname);
|
|
|
86 |
$PAGE->set_title($feedback->name);
|
|
|
87 |
$actionbar = new \mod_feedback\output\edit_action_bar($cm->id, $url, $lastposition);
|
|
|
88 |
$PAGE->activityheader->set_attrs([
|
|
|
89 |
'hidecompletion' => true,
|
|
|
90 |
'description' => ''
|
|
|
91 |
]);
|
|
|
92 |
$PAGE->add_body_class('limitedwidth');
|
|
|
93 |
|
|
|
94 |
//Adding the javascript module for the items dragdrop.
|
|
|
95 |
if (count($feedbackitems) > 1) {
|
|
|
96 |
$PAGE->requires->strings_for_js(array(
|
|
|
97 |
'pluginname',
|
|
|
98 |
'move_item',
|
|
|
99 |
'position',
|
|
|
100 |
), 'feedback');
|
|
|
101 |
$PAGE->requires->yui_module('moodle-mod_feedback-dragdrop', 'M.mod_feedback.init_dragdrop',
|
|
|
102 |
array(array('cmid' => $cm->id)));
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
echo $OUTPUT->header();
|
|
|
106 |
/** @var \mod_feedback\output\renderer $renderer */
|
|
|
107 |
$renderer = $PAGE->get_renderer('mod_feedback');
|
|
|
108 |
echo $renderer->main_action_bar($actionbar);
|
|
|
109 |
$form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_EDIT,
|
|
|
110 |
$feedbackstructure, 'feedback_edit_form');
|
|
|
111 |
echo '<div id="feedback_dragarea">'; // The container for the dragging area.
|
|
|
112 |
$form->display();
|
|
|
113 |
echo '</div>';
|
|
|
114 |
|
|
|
115 |
if ($cancreatetemplates) {
|
|
|
116 |
echo $renderer->create_template_form($id);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
echo $OUTPUT->footer();
|