2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * print the form to add or edit a feedback-instance
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 //It must be included from a Moodle page
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.');
30 require_once($CFG->dirroot
.'/course/moodleform_mod.php');
32 class mod_feedback_mod_form
extends moodleform_mod
{
34 public function definition() {
37 $editoroptions = feedback_get_editor_options();
39 $mform =& $this->_form
;
41 //-------------------------------------------------------------------------------
42 $mform->addElement('header', 'general', get_string('general', 'form'));
44 $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64'));
45 $mform->setType('name', PARAM_TEXT
);
46 $mform->addRule('name', null, 'required', null, 'client');
47 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
49 $this->standard_intro_elements(get_string('description', 'feedback'));
51 //-------------------------------------------------------------------------------
52 $mform->addElement('header', 'timinghdr', get_string('availability'));
54 $mform->addElement('date_time_selector', 'timeopen', get_string('feedbackopen', 'feedback'),
55 array('optional' => true));
57 $mform->addElement('date_time_selector', 'timeclose', get_string('feedbackclose', 'feedback'),
58 array('optional' => true));
60 //-------------------------------------------------------------------------------
61 $mform->addElement('header', 'feedbackhdr', get_string('questionandsubmission', 'feedback'));
64 $options[1] = get_string('anonymous', 'feedback');
65 $options[2] = get_string('non_anonymous', 'feedback');
66 $mform->addElement('select',
68 get_string('anonymous_edit', 'feedback'),
71 // check if there is existing responses to this feedback
72 if (is_numeric($this->_instance
) AND
74 $feedback = $DB->get_record("feedback", array("id"=>$this->_instance
))) {
76 $completed_feedback_count = feedback_get_completeds_group_count($feedback);
78 $completed_feedback_count = false;
81 if ($completed_feedback_count) {
82 $multiple_submit_value = $feedback->multiple_submit ?
get_string('yes') : get_string('no');
83 $mform->addElement('text',
84 'multiple_submit_static',
85 get_string('multiplesubmit', 'feedback'),
87 'disabled'=>'disabled',
88 'value'=>$multiple_submit_value));
89 $mform->setType('multiple_submit_static', PARAM_RAW
);
91 $mform->addElement('hidden', 'multiple_submit', '');
92 $mform->setType('multiple_submit', PARAM_INT
);
93 $mform->addHelpButton('multiple_submit_static', 'multiplesubmit', 'feedback');
95 $mform->addElement('selectyesno',
97 get_string('multiplesubmit', 'feedback'));
99 $mform->addHelpButton('multiple_submit', 'multiplesubmit', 'feedback');
102 $mform->addElement('selectyesno', 'email_notification', get_string('email_notification', 'feedback'));
103 $mform->addHelpButton('email_notification', 'email_notification', 'feedback');
105 $mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback'));
106 $mform->addHelpButton('autonumbering', 'autonumbering', 'feedback');
108 //-------------------------------------------------------------------------------
109 $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
111 $mform->addElement('selectyesno', 'publish_stats', get_string('show_analysepage_after_submit', 'feedback'));
113 $mform->addElement('editor',
114 'page_after_submit_editor',
115 get_string("page_after_submit", "feedback"),
119 $mform->setType('page_after_submit_editor', PARAM_RAW
);
121 $mform->addElement('text',
123 get_string('url_for_continue', 'feedback'),
124 array('size'=>'64', 'maxlength'=>'255'));
126 $mform->setType('site_after_submit', PARAM_TEXT
);
127 $mform->addHelpButton('site_after_submit', 'url_for_continue', 'feedback');
128 //-------------------------------------------------------------------------------
129 $this->standard_coursemodule_elements();
130 //-------------------------------------------------------------------------------
132 $this->add_action_buttons();
135 public function data_preprocessing(&$default_values) {
137 $editoroptions = feedback_get_editor_options();
139 if ($this->current
->instance
) {
140 // editing an existing feedback - let us prepare the added editor elements (intro done automatically)
141 $draftitemid = file_get_submitted_draft_itemid('page_after_submit');
142 $default_values['page_after_submit_editor']['text'] =
143 file_prepare_draft_area($draftitemid, $this->context
->id
,
144 'mod_feedback', 'page_after_submit', false,
146 $default_values['page_after_submit']);
148 $default_values['page_after_submit_editor']['format'] = $default_values['page_after_submitformat'];
149 $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
151 // adding a new feedback instance
152 $draftitemid = file_get_submitted_draft_itemid('page_after_submit_editor');
154 // no context yet, itemid not used
155 file_prepare_draft_area($draftitemid, null, 'mod_feedback', 'page_after_submit', false);
156 $default_values['page_after_submit_editor']['text'] = '';
157 $default_values['page_after_submit_editor']['format'] = editors_get_preferred_format();
158 $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
163 public function get_data() {
164 $data = parent
::get_data();
166 $data->page_after_submitformat
= $data->page_after_submit_editor
['format'];
167 $data->page_after_submit
= $data->page_after_submit_editor
['text'];
169 if (!empty($data->completionunlocked
)) {
170 // Turn off completion settings if the checkboxes aren't ticked
171 $autocompletion = !empty($data->completion
) &&
172 $data->completion
== COMPLETION_TRACKING_AUTOMATIC
;
173 if (!$autocompletion ||
empty($data->completionsubmit
)) {
174 $data->completionsubmit
=0;
182 public function validation($data, $files) {
183 $errors = parent
::validation($data, $files);
187 public function add_completion_rules() {
188 $mform =& $this->_form
;
190 $mform->addElement('checkbox',
193 get_string('completionsubmit', 'feedback'));
194 return array('completionsubmit');
197 public function completion_rule_enabled($data) {
198 return !empty($data['completionsubmit']);