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