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\question;
18
 
19
use mod_questionnaire\feedback\section;
20
 
21
/**
22
 * This file contains the parent class for sectiontext question types.
23
 *
24
 * @author Mike Churchward
25
 * @copyright  2016 onward Mike Churchward (mike.churchward@poetopensource.org)
26
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
27
 * @package mod_questionnaire
28
 */
29
class sectiontext extends question {
30
 
31
    /**
32
     * Each question type must define its response class.
33
     * @return object The response object based off of questionnaire_response_base.
34
     */
35
    protected function responseclass() {
36
        return '';
37
    }
38
 
39
    /**
40
     * Short name for this question type - no spaces, etc..
41
     * @return string
42
     */
43
    public function helpname() {
44
        return 'sectiontext';
45
    }
46
 
47
    /**
48
     * Return true if this question has been marked as required.
49
     * @return boolean
50
     */
51
    public function required() {
52
        return true;
53
    }
54
 
55
    /**
56
     * True if question type supports feedback options. False by default.
57
     */
58
    public function supports_feedback() {
59
        return true;
60
    }
61
 
62
    /**
63
     * True if question type supports feedback scores and weights. Same as supports_feedback() by default.
64
     */
65
    public function supports_feedback_scores() {
66
        return false;
67
    }
68
 
69
    /**
70
     * True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough.
71
     */
72
    public function valid_feedback() {
73
        return true;
74
    }
75
 
76
    /**
77
     * Override and return a form template if provided. Output of question_survey_display is iterpreted based on this.
78
     * @return boolean | string
79
     */
80
    public function question_template() {
81
        return 'mod_questionnaire/question_sectionfb';
82
    }
83
 
84
    /**
85
     * Return the context tags for the check question template.
86
     * @param \mod_questionnaire\responsetype\response\response $response
87
     * @param array $descendantsdata Array of all questions/choices depending on this question.
88
     * @param boolean $blankquestionnaire
89
     * @return object The check question context tags.
90
     *
91
     */
92
    protected function question_survey_display($response, $descendantsdata, $blankquestionnaire=false) {
93
        global $DB, $CFG, $PAGE;
94
        require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
95
 
96
        // If !isset then normal behavior as sectiontext question.
97
        if (!isset($response->questionnaireid)) {
98
            return '';
99
        }
100
 
101
        $filteredsections = [];
102
 
103
        // In which section(s) is this question?
104
        if ($fbsections = $DB->get_records('questionnaire_fb_sections', ['surveyid' => $this->surveyid])) {
105
            foreach ($fbsections as $key => $fbsection) {
106
                if ($scorecalculation = section::decode_scorecalculation($fbsection->scorecalculation)) {
107
                    if (array_key_exists($this->id, $scorecalculation)) {
108
                        array_push($filteredsections, $fbsection->section);
109
                    }
110
                }
111
            }
112
        }
113
 
114
        // If empty then normal behavior as sectiontext question.
115
        if (empty($filteredsections)) {
116
            return '';
117
        }
118
 
119
        list($cm, $course, $questionnaire) = questionnaire_get_standard_page_items(null, $response->questionnaireid);
120
        $questionnaire = new \questionnaire($course, $cm, 0, $questionnaire);
121
        $questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
122
        $questionnaire->add_page(new \mod_questionnaire\output\reportpage());
123
 
124
        $compare = false;
125
        $allresponses = false;
126
        $currentgroupid = 0;
127
        $isgroupmember = false;
128
        $rid = (isset($response->id) && !empty($response->id)) ? $response->id : 0;
129
        $resps = [$rid => null];
130
        // For $filteredsections -> get the feedback messages only for this sections!
131
        $feedbackmessages = $questionnaire->response_analysis($rid, $resps, $compare, $isgroupmember, $allresponses,
132
            $currentgroupid, $filteredsections);
133
 
134
        // Output.
135
        $questiontags = new \stdClass();
136
        $questiontags->qelements = new \stdClass();
137
        $choice = new \stdClass();
138
 
139
        $choice->fb = implode($feedbackmessages);
140
 
141
        $questiontags->qelements->choice = $choice;
142
        return $questiontags;
143
    }
144
 
145
    /**
146
     * Question specific response display method.
147
     * @param \stdClass $data
148
     *
149
     */
150
    protected function response_survey_display($data) {
151
        return '';
152
    }
153
 
154
    /**
155
     * Check question's form data for complete response.
156
     *
157
     * @param object $responsedata The data entered into the response.
158
     * @return boolean
159
     */
160
    public function response_complete($responsedata) {
161
        return true;
162
    }
163
 
164
    /**
165
     * Add the form required field.
166
     * @param \MoodleQuickForm $mform
167
     * @return \MoodleQuickForm
168
     */
169
    protected function form_required(\MoodleQuickForm $mform) {
170
        return $mform;
171
    }
172
 
173
    /**
174
     * Return the length form element.
175
     * @param \MoodleQuickForm $mform
176
     * @param string $helpname
177
     */
178
    protected function form_length(\MoodleQuickForm $mform, $helpname = '') {
179
        return question::form_length_hidden($mform);
180
    }
181
 
182
    /**
183
     * Return the precision form element.
184
     * @param \MoodleQuickForm $mform
185
     * @param string $helpname
186
     */
187
    protected function form_precise(\MoodleQuickForm $mform, $helpname = '') {
188
        return question::form_precise_hidden($mform);
189
    }
190
}