Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| GraphicGapMatchInteraction | |
0.00% |
0 / 39 |
|
0.00% |
0 / 9 |
306 | |
0.00% |
0 / 1 |
| createGapImg | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| addGapImg | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getGapImgs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIdentifiedElements | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getTemplateQti | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTemplateQtiVariables | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getChoiceBySerial | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| removeChoice | |
0.00% |
0 / 3 |
|
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 | |
| 23 | namespace oat\taoQtiItem\model\qti\interaction; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\choice\GapImg; |
| 26 | use oat\taoQtiItem\model\qti\QtiObject; |
| 27 | use oat\taoQtiItem\model\qti\choice\Choice; |
| 28 | |
| 29 | /** |
| 30 | * QTI Graphic Associate Interaction |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Sam, <sam@taotesting.com> |
| 34 | * @package taoQTI |
| 35 | * @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10373 |
| 36 | |
| 37 | */ |
| 38 | class GraphicGapMatchInteraction extends GraphicInteraction |
| 39 | { |
| 40 | /** |
| 41 | * the QTI tag name as defined in QTI standard |
| 42 | * |
| 43 | * @access protected |
| 44 | * @var string |
| 45 | */ |
| 46 | protected static $qtiTagName = 'graphicGapMatchInteraction'; |
| 47 | protected static $choiceClass = 'oat\\taoQtiItem\\model\\qti\\choice\\AssociableHotspot'; |
| 48 | protected static $baseType = 'directedPair'; |
| 49 | protected $gapImgs = []; |
| 50 | |
| 51 | /** |
| 52 | * |
| 53 | * @return oat\taoQtiItem\model\qti\choice\Choice |
| 54 | */ |
| 55 | public function createGapImg($objectLabel = '', $objectAttributes = []) |
| 56 | { |
| 57 | |
| 58 | $returnValue = null; |
| 59 | |
| 60 | if ( |
| 61 | !empty(static::$choiceClass) |
| 62 | && is_subclass_of(static::$choiceClass, 'oat\\taoQtiItem\\model\\qti\\choice\\Choice') |
| 63 | ) { |
| 64 | $returnValue = new GapImg(empty($objectLabel) ? [] : ['objectLabel' => (string) $objectLabel]); |
| 65 | $returnValue->setContent(new QtiObject($objectAttributes)); |
| 66 | $this->addGapImg($returnValue); |
| 67 | } |
| 68 | |
| 69 | return $returnValue; |
| 70 | } |
| 71 | |
| 72 | public function addGapImg(GapImg $gapImg) |
| 73 | { |
| 74 | $this->gapImgs[$gapImg->getSerial()] = $gapImg; |
| 75 | $relatedItem = $this->getRelatedItem(); |
| 76 | if (!is_null($relatedItem)) { |
| 77 | $gapImg->setRelatedItem($relatedItem); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public function getGapImgs() |
| 82 | { |
| 83 | return $this->gapImgs; |
| 84 | } |
| 85 | |
| 86 | public function getIdentifiedElements() |
| 87 | { |
| 88 | $returnValue = parent::getIdentifiedElements(); |
| 89 | $returnValue->addMultiple($this->getGapImgs()); |
| 90 | return $returnValue; |
| 91 | } |
| 92 | |
| 93 | public function toArray($filterVariableContent = false, &$filtered = []) |
| 94 | { |
| 95 | $data = parent::toArray($filterVariableContent, $filtered); |
| 96 | $data['gapImgs'] = $this->getArraySerializedElementCollection( |
| 97 | $this->getGapImgs(), |
| 98 | $filterVariableContent, |
| 99 | $filtered |
| 100 | ); |
| 101 | |
| 102 | return $data; |
| 103 | } |
| 104 | |
| 105 | public static function getTemplateQti() |
| 106 | { |
| 107 | return static::getTemplatePath() . 'interactions/qti.graphicGapMatchInteraction.tpl.php'; |
| 108 | } |
| 109 | |
| 110 | protected function getTemplateQtiVariables() |
| 111 | { |
| 112 | $variables = parent::getTemplateQtiVariables(); |
| 113 | $variables['gapImgs'] = ''; |
| 114 | foreach ($this->getGapImgs() as $gapImg) { |
| 115 | $variables['gapImgs'] .= $gapImg->toQTI(); |
| 116 | } |
| 117 | return $variables; |
| 118 | } |
| 119 | |
| 120 | public function getChoiceBySerial($serial) |
| 121 | { |
| 122 | |
| 123 | $returnValue = parent::getChoiceBySerial($serial); |
| 124 | if (is_null($returnValue)) { |
| 125 | $gapImgs = $this->getGapImgs(); |
| 126 | if (isset($gapImgs[$serial])) { |
| 127 | $returnValue = $gapImgs[$serial]; |
| 128 | } |
| 129 | } |
| 130 | return $returnValue; |
| 131 | } |
| 132 | |
| 133 | public function removeChoice(Choice $choice, $setNumber = null) |
| 134 | { |
| 135 | if ($choice instanceof GapImg) { |
| 136 | unset($this->gapImgs[$choice->getSerial()]); |
| 137 | } else { |
| 138 | parent::removeChoice($choice); |
| 139 | } |
| 140 | } |
| 141 | } |