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\responsetype;
18
 
19
/**
20
 * Class for slider text response types.
21
 *
22
 * @author Hieu Vu Van
23
 * @copyright 2022 The Open University.
24
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25
 * @package mod_questionnaire
26
 */
27
class slider extends numericaltext {
28
    /**
29
     * Return an array of answer objects by question for the given response id.
30
     * THIS SHOULD REPLACE response_select.
31
     *
32
     * @param int $rid The response id.
33
     * @return array array answer
34
     * @throws \dml_exception
35
     */
36
    public static function response_answers_by_question($rid) {
37
        global $DB;
38
 
39
        $answers = [];
40
        $sql = 'SELECT qs.id, qs.response_id as responseid, qs.question_id as questionid,
41
 
42
                'FROM {' . static::response_table() . '} qs ' .
43
                'INNER JOIN {questionnaire_question} qq ON qq.id = qs.question_id ' .
44
                'WHERE response_id = ? ';
45
        $records = $DB->get_records_sql($sql, [$rid]);
46
        foreach ($records as $record) {
47
            $answers[$record->questionid][] = answer\answer::create_from_data($record);
48
            if (!empty($record->extradata)) {
49
                $answers[$record->questionid]['extradata'] = json_decode($record->extradata);
50
            }
51
        }
52
        return $answers;
53
    }
54
}