Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OutcomeDeclaration
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 getUsedAttributes
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getTemplateQtiVariables
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 toJSON
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3/*
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program 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 this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 *
21 */
22
23namespace oat\taoQtiItem\model\qti;
24
25/**
26 * An outcome is a data build in item output. The SCORE is one of the most
27 * outcomes.
28 *
29 * @access public
30 * @author Joel Bout, <joel.bout@tudor.lu>
31 * @package taoQTI
32 * @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10089
33 */
34class OutcomeDeclaration extends VariableDeclaration
35{
36    /**
37     * the QTI tag name as defined in QTI standard
38     *
39     * @access protected
40     * @var string
41     */
42    protected static $qtiTagName = 'outcomeDeclaration';
43
44    protected function getUsedAttributes()
45    {
46        return array_merge(
47            parent::getUsedAttributes(),
48            [
49                'oat\\taoQtiItem\\model\\qti\\attribute\\View',
50                'oat\\taoQtiItem\\model\\qti\\attribute\\Interpretation',
51                'oat\\taoQtiItem\\model\\qti\\attribute\\LongInterpretation',
52                'oat\\taoQtiItem\\model\\qti\\attribute\\ExternalScored',
53                'oat\\taoQtiItem\\model\\qti\\attribute\\NormalMaximum',
54                'oat\\taoQtiItem\\model\\qti\\attribute\\NormalMinimum',
55                'oat\\taoQtiItem\\model\\qti\\attribute\\MasteryValue'
56            ]
57        );
58    }
59
60    public function toArray($filterVariableContent = false, &$filtered = [])
61    {
62        $data = parent::toArray($filterVariableContent, $filtered);
63        $data['defaultValue'] = $this->getDefaultValue();
64        return $data;
65    }
66
67    protected function getTemplateQtiVariables()
68    {
69        $variables = parent::getTemplateQtiVariables();
70        $variables['defaultValue'] = null;
71        $defaultValue = $this->getDefaultValue();
72        if (!is_null($defaultValue) && trim($defaultValue) != '') {
73            $variables['defaultValue'] = $defaultValue;
74        }
75        return $variables;
76    }
77
78    /**
79     * get the outcome in JSON format
80     *
81     * @deprecated now use the new qtism lib for response evaluation
82     * @access public
83     * @author Joel Bout, <joel.bout@tudor.lu>
84     */
85    public function toJSON()
86    {
87        $outcomeValue = null;
88        if ($this->defaultValue != '') {
89            $outcomeValue = [$this->defaultValue];
90        } elseif (
91            $this->getAttributeValue('baseType') == 'integer'
92            || $this->getAttributeValue('baseType') == 'float'
93        ) {
94            $outcomeValue = [0];
95        } else {
96            $outcomeValue = null;
97        }
98
99        $returnValue = taoQTI_models_classes_Matching_VariableFactory::createJSONVariableFromQTIData(
100            $this->getIdentifier(),
101            $this->getAttributeValue('cardinality'),
102            $this->getAttributeValue('baseType'),
103            $outcomeValue
104        );
105
106        return $returnValue;
107    }
108}