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 * prints the forms to choose an item-typ to create items and to choose a template to use
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
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->libdir
.'/formslib.php');
32 class feedback_edit_add_question_form
extends moodleform
{
33 public function definition() {
34 $mform =& $this->_form
;
37 $mform->addElement('header', 'general', get_string('add_items', 'feedback'));
39 $feedback_names_options = feedback_load_feedback_items_options();
41 $attributes = 'onChange="this.form.submit()"';
42 $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
45 $mform->addElement('hidden', 'cmid');
46 $mform->setType('cmid', PARAM_INT
);
47 $mform->addElement('hidden', 'position');
48 $mform->setType('position', PARAM_INT
);
51 $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
55 class feedback_edit_use_template_form
extends moodleform
{
56 private $feedbackdata;
58 public function definition() {
59 $this->feedbackdata
= new stdClass();
60 //this function can not be called, because not all data are available at this time
61 //I use set_form_elements instead
64 //this function set the data used in set_form_elements()
65 //in this form the only value have to set is course
66 //eg: array('course' => $course)
67 public function set_feedbackdata($data) {
68 if (is_array($data)) {
69 foreach ($data as $key => $val) {
70 $this->feedbackdata
->{$key} = $val;
75 //here the elements will be set
76 //this function have to be called manually
77 //the advantage is that the data are already set
78 public function set_form_elements() {
79 $mform =& $this->_form
;
81 $elementgroup = array();
83 $mform->addElement('header', '', get_string('using_templates', 'feedback'));
85 $mform->addElement('hidden', 'id');
86 $mform->setType('id', PARAM_INT
);
89 $templates_options = array();
90 $owntemplates = feedback_get_template_list($this->feedbackdata
->course
, 'own');
91 $publictemplates = feedback_get_template_list($this->feedbackdata
->course
, 'public');
94 if ($owntemplates or $publictemplates) {
95 $options[''] = array('' => get_string('choose'));
98 $courseoptions = array();
99 foreach ($owntemplates as $template) {
100 $courseoptions[$template->id
] = $template->name
;
102 $options[get_string('course')] = $courseoptions;
105 if ($publictemplates) {
106 $publicoptions = array();
107 foreach ($publictemplates as $template) {
108 $publicoptions[$template->id
] = $template->name
;
110 $options[get_string('public', 'feedback')] = $publicoptions;
113 $attributes = 'onChange="this.form.submit()"';
114 $elementgroup[] =& $mform->createElement('selectgroups',
120 $elementgroup[] =& $mform->createElement('submit',
122 get_string('use_this_template', 'feedback'));
124 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
126 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
131 class feedback_edit_create_template_form
extends moodleform
{
132 private $feedbackdata;
134 public function definition() {
137 public function data_preprocessing(&$default_values) {
138 $default_values['templatename'] = '';
141 public function set_feedbackdata($data) {
142 if (is_array($data)) {
143 foreach ($data as $key => $val) {
144 $this->feedbackdata
->{$key} = $val;
149 public function set_form_elements() {
150 $mform =& $this->_form
;
153 $mform->addElement('hidden', 'id');
154 $mform->setType('id', PARAM_INT
);
155 $mform->addElement('hidden', 'do_show');
156 $mform->setType('do_show', PARAM_INT
);
157 $mform->addElement('hidden', 'savetemplate', 1);
158 $mform->setType('savetemplate', PARAM_INT
);
161 $mform->addElement('header', '', get_string('creating_templates', 'feedback'));
164 $elementgroup = array();
166 $elementgroup[] =& $mform->createElement('static',
168 get_string('name', 'feedback'));
170 $elementgroup[] =& $mform->createElement('text',
172 get_string('name', 'feedback'),
173 array('size'=>'40', 'maxlength'=>'200'));
175 if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
176 $elementgroup[] =& $mform->createElement('checkbox',
178 get_string('public', 'feedback'),
179 get_string('public', 'feedback'));
183 $elementgroup[] =& $mform->createElement('submit',
185 get_string('save_as_new_template', 'feedback'));
187 $mform->addGroup($elementgroup,
189 get_string('name', 'feedback'),
193 $mform->setType('templatename', PARAM_TEXT
);