Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
GapMatchInteraction
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 8
156
0.00% covered (danger)
0.00%
0 / 1
 getUsedAttributes
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getGaps
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addGap
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createGap
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 removeGap
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getIdentifiedElements
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getChoiceBySerial
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 removeChoice
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
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\interaction;
24
25use oat\taoQtiItem\model\qti\interaction\GapMatchInteraction;
26use oat\taoQtiItem\model\qti\interaction\ContainerInteraction;
27use oat\taoQtiItem\model\qti\choice\Gap;
28use oat\taoQtiItem\model\qti\choice\Choice;
29
30/**
31 * QTI GapMatch Interaction
32 *
33 * @access public
34 * @author Sam, <sam@taotesting.com>
35 * @package taoQTI
36
37 */
38class GapMatchInteraction extends ContainerInteraction
39{
40    /**
41     * the QTI tag name as defined in QTI standard
42     *
43     * @access protected
44     * @var string
45     */
46    protected static $qtiTagName = 'gapMatchInteraction';
47    protected static $choiceClass = 'oat\\taoQtiItem\\model\\qti\\choice\\GapText';
48    protected static $baseType = 'directedPair';
49    protected static $containerType = 'oat\\taoQtiItem\\model\\qti\\container\\ContainerGap';
50
51    protected function getUsedAttributes()
52    {
53        return array_merge(
54            parent::getUsedAttributes(),
55            [
56            'oat\\taoQtiItem\\model\\qti\\attribute\\Shuffle'
57                ]
58        );
59    }
60
61    public function getGaps()
62    {
63        return $this->getBody()->getElements('oat\\taoQtiItem\\model\\qti\\choice\\Gap');
64    }
65
66    public function addGap($body, Gap $gap)
67    {
68        return $this->setElements([$gap], $body);
69    }
70
71    public function createGap($body, $gapAttributes = [], $gapValue = null)
72    {
73        $returnValue = null;
74        $gap = new Gap($gapAttributes, $gapValue);
75        if ($this->addGap($body, $gap)) {
76            $returnValue = $gap;
77        }
78        return $returnValue;
79    }
80
81    public function removeGap(Gap $gap)
82    {
83        return $this->body->removeElement($gap);
84    }
85
86    public function getIdentifiedElements()
87    {
88        $returnValue = parent::getIdentifiedElements();
89        $returnValue->addMultiple($this->getGaps());
90        return $returnValue;
91    }
92
93    public function getChoiceBySerial($serial)
94    {
95
96        $returnValue = parent::getChoiceBySerial($serial);
97        if (is_null($returnValue)) {
98            $gaps = $this->getGaps();
99            if (isset($gaps[$serial])) {
100                $returnValue = $gaps[$serial];
101            }
102        }
103        return $returnValue;
104    }
105
106    public function removeChoice(Choice $choice, $setNumber = null)
107    {
108        if ($choice instanceof Gap) {
109            return $this->body->removeElement($choice);
110        } else {
111            parent::removeChoice($choice);
112        }
113    }
114}