Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace mod_questionnaire;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
require_once($CFG->libdir . '/formslib.php');
22
require_once($CFG->dirroot.'/mod/questionnaire/lib.php');
23
 
24
/**
25
 * Print the form to manage feedback settings.
26
 *
27
 * @package mod_questionnaire
28
 * @copyright  2016 onward Mike Churchward (mike.churchward@poetgroup.org)
29
 * @author Joseph Rezeau
30
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31
 */
32
class feedback_form extends \moodleform {
33
 
34
    /**
35
     * Defition of the form.
36
     */
37
    public function definition() {
38
        global $questionnaire;
39
 
40
        $mform =& $this->_form;
41
 
42
        // Questionnaire Feedback Sections and Messages.
43
        $mform->addElement('header', 'submithdr', get_string('feedbackoptions', 'questionnaire'));
44
        $feedbackoptions = [];
45
        $feedbackoptions[0] = get_string('feedbacknone', 'questionnaire');
46
        $feedbackoptions[1] = get_string('feedbackglobal', 'questionnaire');
47
        $feedbackoptions[2] = get_string('feedbacksections', 'questionnaire');
48
 
49
        $mform->addElement('select', 'feedbacksections', get_string('feedbackoptions', 'questionnaire'), $feedbackoptions);
50
        $mform->setDefault('feedbacksections', $questionnaire->survey->feedbacksections);
51
        $mform->addHelpButton('feedbacksections', 'feedbackoptions', 'questionnaire');
52
 
53
        $options = ['0' => get_string('no'), '1' => get_string('yes')];
54
        $mform->addElement('select', 'feedbackscores', get_string('feedbackscores', 'questionnaire'), $options);
55
        $mform->addHelpButton('feedbackscores', 'feedbackscores', 'questionnaire');
56
 
57
        // Is the RGraph library enabled at level site?
58
        if (get_config('questionnaire', 'usergraph')) {
59
            $chartgroup = [];
60
            $charttypes = [null => get_string('none'),
61
                'bipolar' => get_string('chart:bipolar', 'questionnaire'),
62
                'vprogress' => get_string('chart:vprogress', 'questionnaire')];
63
            $chartgroup[] = $mform->createElement('select', 'chart_type_global',
64
                get_string('chart:type', 'questionnaire') . ' (' .
65
                get_string('feedbackglobal', 'questionnaire') . ')', $charttypes);
66
            if ($questionnaire->survey->feedbacksections == 1) {
67
                $mform->setDefault('chart_type_global', $questionnaire->survey->chart_type);
68
            }
69
            $mform->disabledIf('chart_type_global', 'feedbacksections', 'eq', 0);
70
            $mform->disabledIf('chart_type_global', 'feedbacksections', 'neq', 1);
71
 
72
            $charttypes = [null => get_string('none'),
73
                'bipolar' => get_string('chart:bipolar', 'questionnaire'),
74
                'hbar' => get_string('chart:hbar', 'questionnaire'),
75
                'rose' => get_string('chart:rose', 'questionnaire')];
76
            $chartgroup[] = $mform->createElement('select', 'chart_type_two_sections',
77
                get_string('chart:type', 'questionnaire') . ' (' .
78
                get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
79
            if ($questionnaire->survey->feedbacksections > 1) {
80
                $mform->setDefault('chart_type_two_sections', $questionnaire->survey->chart_type);
81
            }
82
            $mform->disabledIf('chart_type_two_sections', 'feedbacksections', 'neq', 2);
83
 
84
            $charttypes = [null => get_string('none'),
85
                'bipolar' => get_string('chart:bipolar', 'questionnaire'),
86
                'hbar' => get_string('chart:hbar', 'questionnaire'),
87
                'radar' => get_string('chart:radar', 'questionnaire'),
88
                'rose' => get_string('chart:rose', 'questionnaire')];
89
            $chartgroup[] = $mform->createElement('select', 'chart_type_sections',
90
                get_string('chart:type', 'questionnaire') . ' (' .
91
                get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
92
            if ($questionnaire->survey->feedbacksections > 1) {
93
                $mform->setDefault('chart_type_sections', $questionnaire->survey->chart_type);
94
            }
95
            $mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 0);
96
            $mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 1);
97
            $mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 2);
98
 
99
            $mform->addGroup($chartgroup, 'chartgroup',
100
                get_string('chart:type', 'questionnaire'), null, false);
101
            $mform->addHelpButton('chartgroup', 'chart:type', 'questionnaire');
102
        }
103
        $editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true];
104
        $mform->addElement('editor', 'feedbacknotes', get_string('feedbacknotes', 'questionnaire'), null, $editoroptions);
105
        $mform->setType('feedbacknotes', PARAM_RAW);
106
        $mform->setDefault('feedbacknotes', $questionnaire->survey->feedbacknotes);
107
        $mform->addHelpButton('feedbacknotes', 'feedbacknotes', 'questionnaire');
108
 
109
        $mform->addElement('hidden', 'id', 0);
110
        $mform->setType('id', PARAM_INT);
111
        $mform->addElement('hidden', 'sid', 0);
112
        $mform->setType('sid', PARAM_INT);
113
        $mform->addElement('hidden', 'courseid', '');
114
        $mform->setType('courseid', PARAM_RAW);
115
 
116
        // Can't seem to disable or hide one button in the group, so create two different button sets and hide one.
117
        $buttongroup = [];
118
        $buttongroup[] = $mform->createElement('submit', 'feedbacksettingsbutton1', get_string('savesettings', 'questionnaire'));
119
        $buttongroup[] = $mform->createElement('submit', 'feedbackeditbutton', get_string('feedbackeditsections', 'questionnaire'));
120
        $mform->addGroup($buttongroup, 'buttongroup');
121
        if (moodle_major_version() == '3.3') {
122
            $mform->disabledIf('buttongroup', 'feedbacksections', 'eq', 0);
123
        } else {
124
            $mform->hideIf('buttongroup', 'feedbacksections', 'eq', 0);
125
        }
126
 
127
        $mform->addElement('submit', 'feedbacksettingsbutton2', get_string('savesettings', 'questionnaire'));
128
        if (moodle_major_version() == '3.3') {
129
            $mform->disabledIf('feedbacksettingsbutton2', 'feedbacksections', 'neq', 0);
130
        } else {
131
            $mform->hideIf('feedbacksettingsbutton2', 'feedbacksections', 'neq', 0);
132
        }
133
    }
134
 
135
    /**
136
     * Validate the data submitted.
137
     * @param array $data
138
     * @param array $files
139
     * @return array
140
     */
141
    public function validation($data, $files) {
142
        $errors = parent::validation($data, $files);
143
        return $errors;
144
    }
145
}