Merge branch 'MDL-46239-28-2' of git://github.com/xow/moodle into MOODLE_28_STABLE
[moodle.git] / mod / feedback / edit_form.php
blob708ca5ae7e17758001dc70e88da3aff28ac2e2e4
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.
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/>.
17 /**
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
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->libdir.'/formslib.php');
32 class feedback_edit_add_question_form extends moodleform {
33 public function definition() {
34 $mform = $this->_form;
36 //headline
37 $mform->addElement('header', 'general', get_string('content'));
38 // visible elements
39 $feedback_names_options = feedback_load_feedback_items_options();
41 $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
42 $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
44 // hidden elements
45 $mform->addElement('hidden', 'cmid');
46 $mform->setType('cmid', PARAM_INT);
47 $mform->addElement('hidden', 'position');
48 $mform->setType('position', PARAM_INT);
50 // buttons
51 $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'), array('class' => 'hiddenifjs'));
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 if (!isset($this->feedbackdata)) {
70 $this->feedbackdata = new stdClass();
72 foreach ($data as $key => $val) {
73 $this->feedbackdata->{$key} = $val;
78 //here the elements will be set
79 //this function have to be called manually
80 //the advantage is that the data are already set
81 public function set_form_elements() {
82 $mform =& $this->_form;
84 $elementgroup = array();
85 //headline
86 $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
87 // hidden elements
88 $mform->addElement('hidden', 'id');
89 $mform->setType('id', PARAM_INT);
91 // visible elements
92 $templates_options = array();
93 $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
94 $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
96 $options = array();
97 if ($owntemplates or $publictemplates) {
98 $options[''] = array('' => get_string('choose'));
100 if ($owntemplates) {
101 $courseoptions = array();
102 foreach ($owntemplates as $template) {
103 $courseoptions[$template->id] = $template->name;
105 $options[get_string('course')] = $courseoptions;
108 if ($publictemplates) {
109 $publicoptions = array();
110 foreach ($publictemplates as $template) {
111 $publicoptions[$template->id] = $template->name;
113 $options[get_string('public', 'feedback')] = $publicoptions;
116 $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
117 $elementgroup[] = $mform->createElement('selectgroups',
118 'templateid',
120 $options,
121 $attributes);
123 $elementgroup[] = $mform->createElement('submit',
124 'use_template',
125 get_string('use_this_template', 'feedback'));
127 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
128 } else {
129 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
134 class feedback_edit_create_template_form extends moodleform {
135 private $feedbackdata;
137 public function definition() {
140 public function data_preprocessing(&$default_values) {
141 $default_values['templatename'] = '';
144 public function set_feedbackdata($data) {
145 if (is_array($data)) {
146 if (!isset($this->feedbackdata)) {
147 $this->feedbackdata = new stdClass();
149 foreach ($data as $key => $val) {
150 $this->feedbackdata->{$key} = $val;
155 public function set_form_elements() {
156 $mform =& $this->_form;
158 // hidden elements
159 $mform->addElement('hidden', 'id');
160 $mform->setType('id', PARAM_INT);
161 $mform->addElement('hidden', 'do_show');
162 $mform->setType('do_show', PARAM_INT);
163 $mform->addElement('hidden', 'savetemplate', 1);
164 $mform->setType('savetemplate', PARAM_INT);
166 //headline
167 $mform->addElement('header', 'creating_templates', get_string('creating_templates', 'feedback'));
169 // visible elements
170 $elementgroup = array();
172 $elementgroup[] = $mform->createElement('static',
173 'templatenamelabel',
174 get_string('name', 'feedback'));
176 $elementgroup[] = $mform->createElement('text',
177 'templatename',
178 get_string('name', 'feedback'),
179 array('size'=>'40', 'maxlength'=>'200'));
181 if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
182 $elementgroup[] = $mform->createElement('checkbox',
183 'ispublic',
184 get_string('public', 'feedback'),
185 get_string('public', 'feedback'));
188 // buttons
189 $elementgroup[] = $mform->createElement('submit',
190 'create_template',
191 get_string('save_as_new_template', 'feedback'));
193 $mform->addGroup($elementgroup,
194 'elementgroup',
195 get_string('name', 'feedback'),
196 array(' '),
197 false);
199 $mform->setType('templatename', PARAM_TEXT);