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\answer;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* This defines a structured class to hold question answers.
|
|
|
21 |
*
|
|
|
22 |
* @author Mike Churchward
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
24 |
* @package mod_questionnaire
|
|
|
25 |
* @copyright 2019, onwards Poet
|
|
|
26 |
*/
|
|
|
27 |
class answer {
|
|
|
28 |
|
|
|
29 |
// Class properties.
|
|
|
30 |
|
|
|
31 |
/** @var int $id The id of the question response data record this applies to. */
|
|
|
32 |
public $id;
|
|
|
33 |
|
|
|
34 |
/** @var int $responseid This id of the response record this applies to. */
|
|
|
35 |
public $responseid;
|
|
|
36 |
|
|
|
37 |
/** @var int $questionid The id of the question this response applies to. */
|
|
|
38 |
public $questionid;
|
|
|
39 |
|
|
|
40 |
/** @var string $content The choiceid of this response (if applicable). */
|
|
|
41 |
public $choiceid;
|
|
|
42 |
|
|
|
43 |
/** @var string $value The value of this response (if applicable). */
|
|
|
44 |
public $value;
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Answer constructor.
|
|
|
48 |
* @param null $id
|
|
|
49 |
* @param null $responseid
|
|
|
50 |
* @param null $questionid
|
|
|
51 |
* @param null $choiceid
|
|
|
52 |
* @param null $value
|
|
|
53 |
*/
|
|
|
54 |
public function __construct($id = null, $responseid = null, $questionid = null, $choiceid = null, $value = null) {
|
|
|
55 |
$this->id = $id;
|
|
|
56 |
$this->responseid = $responseid;
|
|
|
57 |
$this->questionid = $questionid;
|
|
|
58 |
$this->choiceid = $choiceid;
|
|
|
59 |
$this->value = $value;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Create and return an answer object from data.
|
|
|
64 |
*
|
|
|
65 |
* @param \stdClass|array $answerdata The data to load.
|
|
|
66 |
* @return answer
|
|
|
67 |
*/
|
|
|
68 |
public static function create_from_data($answerdata) {
|
|
|
69 |
if (!is_array($answerdata)) {
|
|
|
70 |
$answerdata = (array)$answerdata;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
$properties = array_keys(get_class_vars(__CLASS__));
|
|
|
74 |
foreach ($properties as $property) {
|
|
|
75 |
if (!isset($answerdata[$property])) {
|
|
|
76 |
$answerdata[$property] = null;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
return new answer($answerdata['id'], $answerdata['responseid'], $answerdata['questionid'], $answerdata['choiceid'],
|
|
|
81 |
$answerdata['value']);
|
|
|
82 |
}
|
|
|
83 |
}
|