Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 86 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
| ImsPortableCustomInteraction | |
0.00% |
0 / 86 |
|
0.00% |
0 / 18 |
1056 | |
0.00% |
0 / 1 |
| setTypeIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEntryPoint | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTypeIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEntryPoint | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getProperties | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setProperties | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getStylesheets | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStylesheets | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMediaFiles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setMediaFiles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLibraries | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLibraries | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| toArray | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
| getTemplateQti | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTemplateQtiVariables | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| feed | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
182 | |||
| 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) 2017 (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\ParserFactory; |
| 26 | use oat\taoQtiItem\model\qti\exception\QtiModelException; |
| 27 | use DOMElement; |
| 28 | use oat\taoQtiItem\model\qti\PortableElementTrait; |
| 29 | use oat\taoQtiItem\model\qti\QtiNamespace; |
| 30 | |
| 31 | /** |
| 32 | * The ImsPortableCustomInteraction is the class of the official IMS PCI v1 implementation |
| 33 | * |
| 34 | * @access public |
| 35 | * @author Sam, <sam@taotesting.com> |
| 36 | * @package taoQTI |
| 37 | * @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10267 |
| 38 | |
| 39 | */ |
| 40 | class ImsPortableCustomInteraction extends CustomInteraction |
| 41 | { |
| 42 | use PortableElementTrait; |
| 43 | |
| 44 | public const NS_NAME = 'imspci'; |
| 45 | public const NS_URI = 'http://www.imsglobal.org/xsd/portableCustomInteraction_v1'; |
| 46 | |
| 47 | protected $markupNs = 'http://www.w3.org/1999/xhtml'; |
| 48 | protected $properties = []; |
| 49 | protected $libraries = []; |
| 50 | protected $stylesheets = []; |
| 51 | protected $mediaFiles = []; |
| 52 | protected $typeIdentifier = ''; |
| 53 | protected $entryPoint = ''; |
| 54 | protected $version = '0.0.0'; |
| 55 | |
| 56 | public function setTypeIdentifier($typeIdentifier) |
| 57 | { |
| 58 | $this->typeIdentifier = $typeIdentifier; |
| 59 | } |
| 60 | |
| 61 | public function setEntryPoint($entryPoint) |
| 62 | { |
| 63 | $this->entryPoint = $entryPoint; |
| 64 | } |
| 65 | |
| 66 | public function getTypeIdentifier() |
| 67 | { |
| 68 | return $this->typeIdentifier; |
| 69 | } |
| 70 | |
| 71 | public function getEntryPoint() |
| 72 | { |
| 73 | return $this->entryPoint; |
| 74 | } |
| 75 | |
| 76 | public function getProperties() |
| 77 | { |
| 78 | return $this->properties; |
| 79 | } |
| 80 | |
| 81 | public function setProperties($properties) |
| 82 | { |
| 83 | if (is_array($properties)) { |
| 84 | $this->properties = $properties; |
| 85 | } else { |
| 86 | throw new InvalidArgumentException('properties should be an array'); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | public function getStylesheets() |
| 91 | { |
| 92 | return $this->stylesheets; |
| 93 | } |
| 94 | |
| 95 | public function setStylesheets($stylesheets) |
| 96 | { |
| 97 | $this->stylesheets = $stylesheets; |
| 98 | } |
| 99 | |
| 100 | public function getMediaFiles() |
| 101 | { |
| 102 | return $this->mediaFiles; |
| 103 | } |
| 104 | |
| 105 | public function setMediaFiles($mediaFiles) |
| 106 | { |
| 107 | $this->mediaFiles = $mediaFiles; |
| 108 | } |
| 109 | |
| 110 | public function getVersion() |
| 111 | { |
| 112 | return $this->version; |
| 113 | } |
| 114 | |
| 115 | public function setVersion($version) |
| 116 | { |
| 117 | return $this->version = $version; |
| 118 | } |
| 119 | |
| 120 | public function getLibraries() |
| 121 | { |
| 122 | return $this->libraries; |
| 123 | } |
| 124 | |
| 125 | public function setLibraries($libraries) |
| 126 | { |
| 127 | if (is_array($libraries)) { |
| 128 | $this->libraries = $libraries; |
| 129 | } else { |
| 130 | throw new InvalidArgumentException('libraries should be an array'); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | public function toArray($filterVariableContent = false, &$filtered = []) |
| 135 | { |
| 136 | |
| 137 | $returnValue = parent::toArray($filterVariableContent, $filtered); |
| 138 | |
| 139 | $returnValue['typeIdentifier'] = $this->typeIdentifier; |
| 140 | $returnValue['version'] = $this->version; |
| 141 | $returnValue['properties'] = $this->getArraySerializedPrimitiveCollection( |
| 142 | $this->getProperties(), |
| 143 | $filterVariableContent, |
| 144 | $filtered |
| 145 | ); |
| 146 | $returnValue['config'] = $this->config; |
| 147 | $returnValue['modules'] = $this->getArraySerializedPrimitiveCollection( |
| 148 | $this->getModules(), |
| 149 | $filterVariableContent, |
| 150 | $filtered |
| 151 | ); |
| 152 | $returnValue['xmlns'] = $this->getNamespace()->getUri(); |
| 153 | |
| 154 | return $returnValue; |
| 155 | } |
| 156 | |
| 157 | public static function getTemplateQti() |
| 158 | { |
| 159 | return static::getTemplatePath() . 'interactions/qti.imspci.tpl.php'; |
| 160 | } |
| 161 | |
| 162 | protected function getTemplateQtiVariables() |
| 163 | { |
| 164 | |
| 165 | $variables = parent::getTemplateQtiVariables(); |
| 166 | $variables['typeIdentifier'] = $this->getTypeIdentifier(); |
| 167 | $variables['modules'] = $this->getModules(); |
| 168 | $variables['serializedProperties'] = $this->serializePortableProperties($this->properties); |
| 169 | $variables['config'] = $this->getConfig(); |
| 170 | return $variables; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Feed the pci instance with data provided in the pci dom node |
| 175 | * |
| 176 | * @param ParserFactory $parser |
| 177 | * @param DOMElement $data |
| 178 | * @throws InvalidArgumentException |
| 179 | * @throws QtiModelException |
| 180 | */ |
| 181 | public function feed(ParserFactory $parser, DOMElement $data, QtiNamespace $xmlns = null) |
| 182 | { |
| 183 | |
| 184 | $this->setNamespace($xmlns); |
| 185 | $xmlnsName = $xmlns->getName(); |
| 186 | |
| 187 | $pciNodes = $parser->queryXPathChildren(['portableCustomInteraction'], $data, $xmlnsName); |
| 188 | if (!$pciNodes->length) { |
| 189 | $xmlnsName = '';//even if a namespace has been defined, it may not be used |
| 190 | $pciNodes = $parser->queryXPathChildren(['portableCustomInteraction'], $data, $xmlnsName); |
| 191 | } |
| 192 | if (!$pciNodes->length) { |
| 193 | throw new QtiModelException('no ims portableCustomInteraction node found'); |
| 194 | } |
| 195 | |
| 196 | $typeIdentifier = $pciNodes->item(0)->getAttribute('customInteractionTypeIdentifier'); |
| 197 | if (empty($typeIdentifier)) { |
| 198 | throw new QtiModelException('the type identifier of the pci is missing'); |
| 199 | } else { |
| 200 | $this->setTypeIdentifier($typeIdentifier); |
| 201 | } |
| 202 | |
| 203 | $version = $pciNodes->item(0)->getAttribute('data-version'); |
| 204 | if ($version) { |
| 205 | $this->setVersion($version); |
| 206 | } |
| 207 | |
| 208 | $rootModulesNodes = $parser->queryXPathChildren(['portableCustomInteraction', 'modules'], $data, $xmlnsName); |
| 209 | foreach ($rootModulesNodes as $rootModulesNode) { |
| 210 | $config = []; |
| 211 | if ($rootModulesNode->getAttribute('primaryConfiguration')) { |
| 212 | $config[] = $rootModulesNode->getAttribute('primaryConfiguration'); |
| 213 | } |
| 214 | if ($rootModulesNode->getAttribute('fallbackConfiguration')) { |
| 215 | $config[] = $rootModulesNode->getAttribute('fallbackConfiguration'); |
| 216 | } |
| 217 | $this->setConfig($config); |
| 218 | } |
| 219 | |
| 220 | $moduleNodes = $parser->queryXPathChildren( |
| 221 | ['portableCustomInteraction', 'modules', 'module'], |
| 222 | $data, |
| 223 | $xmlnsName |
| 224 | ); |
| 225 | |
| 226 | foreach ($moduleNodes as $libNode) { |
| 227 | $id = $libNode->getAttribute('id'); |
| 228 | $paths = []; |
| 229 | if ($libNode->getAttribute('primaryPath')) { |
| 230 | $paths[] = $libNode->getAttribute('primaryPath'); |
| 231 | } |
| 232 | if ($libNode->getAttribute('fallbackPath')) { |
| 233 | $paths[] = $libNode->getAttribute('fallbackPath'); |
| 234 | } |
| 235 | $this->addModule($id, $paths); |
| 236 | } |
| 237 | |
| 238 | $propertyNodes = $parser->queryXPathChildren(['portableCustomInteraction', 'properties'], $data, $xmlnsName); |
| 239 | if ($propertyNodes->length) { |
| 240 | $properties = $this->extractProperties($propertyNodes->item(0), $xmlnsName); |
| 241 | $this->setProperties($properties); |
| 242 | } |
| 243 | |
| 244 | $markupNodes = $parser->queryXPathChildren(['portableCustomInteraction', 'markup'], $data, $xmlnsName); |
| 245 | if ($markupNodes->length) { |
| 246 | $markup = $parser->getBodyData($markupNodes->item(0), true, true); |
| 247 | $this->setMarkup($markup); |
| 248 | } |
| 249 | } |
| 250 | } |