MDL-19488 - allow the creation of a "Public" feedback
[moodle.git] / mod / feedback / edit_form.php
CommitLineData
1adbd2c3 1<?php
c70ad9f7 2/**
3* prints the forms to choose an item-typ to create items and to choose a template to use
4*
c70ad9f7 5* @author Andreas Grabs
6* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7* @package feedback
8*/
9
bfebaf64
MD
10if (!defined('MOODLE_INTERNAL')) {
11 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
12}
13
c70ad9f7 14require_once $CFG->libdir.'/formslib.php';
15
16class feedback_edit_add_question_form extends moodleform {
17 function definition() {
18 $mform =& $this->_form;
19
20 //headline
21 $mform->addElement('header', 'general', get_string('add_items', 'feedback'));
22 // visible elements
23 // $feedback_names = feedback_load_feedback_items('mod/feedback/item');
24 // $feedback_names_options = array();
25 // $feedback_names_options[' '] = get_string('select');
26 // foreach($feedback_names as $fn) {
27 // $feedback_names_options[$fn] = get_string($fn,'feedback');
28 // }
29 $feedback_names_options = feedback_load_feedback_items_options();
1adbd2c3 30
c70ad9f7 31 $attributes = 'onChange="this.form.submit()"';
32 $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
33
34 // hidden elements
7e55c2ef
AG
35 $mform->addElement('hidden', 'cmid');
36 $mform->setType('cmid', PARAM_INT);
c70ad9f7 37 $mform->addElement('hidden', 'position');
d18e0fe6 38 $mform->setType('position', PARAM_INT);
c70ad9f7 39//-------------------------------------------------------------------------------
40 // buttons
41 $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
42 }
43}
44
45class feedback_edit_use_template_form extends moodleform {
46 var $feedbackdata;
1adbd2c3 47
c70ad9f7 48 function definition() {
39790bd8 49 $this->feedbackdata = new stdClass();
c70ad9f7 50 //this function can not be called, because not all data are available at this time
51 //I use set_form_elements instead
52 }
1adbd2c3 53
c70ad9f7 54 //this function set the data used in set_form_elements()
55 //in this form the only value have to set is course
56 //eg: array('course' => $course)
57 function set_feedbackdata($data) {
58 if(is_array($data)) {
59 foreach($data as $key => $val) {
60 $this->feedbackdata->{$key} = $val;
61 }
62 }
63 }
1adbd2c3 64
c70ad9f7 65 //here the elements will be set
66 //this function have to be called manually
67 //the advantage is that the data are already set
68 function set_form_elements(){
69 $mform =& $this->_form;
1adbd2c3 70
c70ad9f7 71 $elementgroup = array();
72 //headline
73 $mform->addElement('header', '', get_string('using_templates', 'feedback'));
74 // hidden elements
75 $mform->addElement('hidden', 'id');
d18e0fe6 76 $mform->setType('id', PARAM_INT);
1adbd2c3 77
c70ad9f7 78 // visible elements
79 $templates_options = array();
485ec594
AG
80 $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
81 $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
7b1126fd
AG
82
83 $options = array();
84 if($owntemplates or $publictemplates) {
85 $options[''] = array('' => get_string('choose'));
86
87 if($owntemplates) {
88 $courseoptions = array();
89 foreach($owntemplates as $template) {
90 $courseoptions[$template->id] = $template->name;
485ec594 91 }
7b1126fd 92 $options[get_string('course')] = $courseoptions;
c70ad9f7 93 }
7b1126fd
AG
94
95 if($publictemplates) {
96 $publicoptions = array();
97 foreach($publictemplates as $template) {
98 $publicoptions[$template->id] = $template->name;
99 }
100 $options[get_string('public', 'feedback')] = $publicoptions;
485ec594 101 }
7b1126fd 102
c70ad9f7 103 $attributes = 'onChange="this.form.submit()"';
7b1126fd 104 $elementgroup[] =& $mform->createElement('selectgroups', 'templateid', '', $options, $attributes);
c70ad9f7 105 $elementgroup[] =& $mform->createElement('submit', 'use_template', get_string('use_this_template', 'feedback'));
106 }else {
107 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
108 }
109 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
1adbd2c3 110
c70ad9f7 111 //-------------------------------------------------------------------------------
112 }
113}
114
115class feedback_edit_create_template_form extends moodleform {
116 var $feedbackdata;
1adbd2c3 117
c70ad9f7 118 function definition() {
119 }
1adbd2c3 120
c70ad9f7 121 function data_preprocessing(&$default_values){
122 $default_values['templatename'] = '';
123 }
1adbd2c3 124
c70ad9f7 125 function set_feedbackdata($data) {
126 if(is_array($data)) {
127 foreach($data as $key => $val) {
128 $this->feedbackdata->{$key} = $val;
129 }
130 }
131 }
1adbd2c3 132
c70ad9f7 133 function set_form_elements(){
485ec594
AG
134 global $CFG;
135
c70ad9f7 136 $mform =& $this->_form;
c987dbad 137 // $capabilities = $this->feedbackdata->capabilities;
c70ad9f7 138
139 // hidden elements
140 $mform->addElement('hidden', 'id');
d18e0fe6 141 $mform->setType('id', PARAM_INT);
c70ad9f7 142 $mform->addElement('hidden', 'do_show');
d18e0fe6 143 $mform->setType('do_show', PARAM_INT);
c70ad9f7 144 $mform->addElement('hidden', 'savetemplate', 1);
d18e0fe6 145 $mform->setType('savetemplate', PARAM_INT);
c70ad9f7 146
147 //headline
148 $mform->addElement('header', '', get_string('creating_templates', 'feedback'));
1adbd2c3 149
c70ad9f7 150 // visible elements
151 $elementgroup = array();
1adbd2c3 152
c70ad9f7 153 $elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
154 $elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
39790bd8 155
7b1126fd
AG
156 if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
157 $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
485ec594 158 }
1adbd2c3 159
c70ad9f7 160 // buttons
161 $elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
162 $mform->addGroup($elementgroup, 'elementgroup', get_string('name', 'feedback'), array(' '), false);
1adbd2c3 163
c70ad9f7 164 $mform->setType('templatename', PARAM_TEXT);
1adbd2c3 165
c70ad9f7 166//-------------------------------------------------------------------------------
167 }
168}
1adbd2c3 169