Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
taoResultServer_models_classes_ResponseVariable
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
9 / 9
9
100.00% covered (success)
100.00%
1 / 1
 setCorrectResponse
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCorrectResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCandidateResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEncodedCandidateResponse
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCandidateResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setValue
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; under version 2
9 * of the License (non-upgradable).
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 *
20 * Copyright (c) 2013 (original work) Open Assessment Technologies S.A.
21 *
22 * @author "Patrick Plichart, <patrick@taotesting.com>"
23 *
24 * An Assessment Result is used to report the results of a candidate's interaction
25 * with a test and/or one or more items attempted. Information about the test is optional,
26 * in some systems it may be possible to interact with items that are not organized into
27 * a test at all. For example, items that are organized with learning resources and
28 * presented individually in a formative context.
29 */
30class taoResultServer_models_classes_ResponseVariable extends taoResultServer_models_classes_Variable
31{
32    public const TYPE = 'responseVariable';
33
34    /**
35     * The correct response may be output as part of the report if desired.
36     * Systems are not limited to reporting correct responses declared in responseDeclarations. For example, a correct
37     * response may be set by a templateRule or may simply have been suppressed from the declaration passed to the
38     * delivery engine (e.g., for security).
39     *
40     * @var mixed|null
41     */
42    protected $correctResponse;
43
44    /**
45     * @var string|null Base64 encoded candidate response
46     */
47    protected $candidateResponse;
48
49    public function setCorrectResponse($correctResponse): self
50    {
51        $this->correctResponse = $correctResponse;
52
53        return $this;
54    }
55
56    public function getCorrectResponse()
57    {
58        return $this->correctResponse;
59    }
60
61    public function setCandidateResponse($candidateResponse): self
62    {
63        return $this->setEncodedCandidateResponse(base64_encode((string)$candidateResponse));
64    }
65
66    public function setEncodedCandidateResponse($encodedCandidateResponse): self
67    {
68        $this->candidateResponse = $encodedCandidateResponse;
69
70        return $this;
71    }
72
73    /**
74     * @return string|false
75     */
76    public function getCandidateResponse()
77    {
78        return base64_decode((string)$this->candidateResponse);
79    }
80
81    /**
82     * {@inheritdoc}
83     */
84    public function getValue()
85    {
86        return $this->getCandidateResponse();
87    }
88
89    /**
90     * {@inheritdoc}
91     */
92    public function setValue($value): self
93    {
94        $this->setCandidateResponse($value);
95
96        return $this;
97    }
98
99    /**
100     * {@inheritdoc}
101     */
102    public function jsonSerialize()
103    {
104        return parent::jsonSerialize() +
105            [
106                'correctResponse' => $this->correctResponse,
107                'candidateResponse' => $this->candidateResponse,
108            ];
109    }
110
111    protected function getType(): string
112    {
113        return self::TYPE;
114    }
115}