Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| taoQTI_scripts_update_taoQtiUpdate | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| convertQtiItem | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| convertQtiFromV2p0ToV2p1 | |
0.00% |
0 / 16 |
|
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 Open Assessment Technologies S.A. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\tao\model\TaoOntology; |
| 23 | use oat\taoQtiItem\model\qti\Parser; |
| 24 | use oat\taoQtiItem\model\qti\Item; |
| 25 | use oat\taoQtiItem\model\ItemModel; |
| 26 | use oat\taoQtiItem\model\qti\Service; |
| 27 | |
| 28 | /** |
| 29 | * Update script for qti |
| 30 | * @author Sam, <sam@taotesting.com> |
| 31 | * @package taoQTI |
| 32 | */ |
| 33 | class taoQTI_scripts_update_taoQtiUpdate extends tao_scripts_Runner |
| 34 | { |
| 35 | public function run() |
| 36 | { |
| 37 | $itemService = taoItems_models_classes_ItemsService::singleton(); |
| 38 | $itemClass = new core_kernel_classes_Class(TaoOntology::ITEM_CLASS_URI); |
| 39 | $items = $itemClass->getInstances(true); |
| 40 | |
| 41 | foreach ($items as $item) { |
| 42 | $itemModel = $itemService->getItemModel($item); |
| 43 | if (!is_null($itemModel) && $itemModel->getUri() == ItemModel::MODEL_URI) { |
| 44 | $this->out('qti item found: ' . $item->getLabel()); |
| 45 | $this->convertQtiItem($item); |
| 46 | } |
| 47 | // break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | protected function convertQtiItem(core_kernel_classes_Resource $item) |
| 52 | { |
| 53 | $itemContentProp = new core_kernel_classes_Property( |
| 54 | \taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT |
| 55 | ); |
| 56 | $usedLanguages = $item->getUsedLanguages($itemContentProp); |
| 57 | foreach ($usedLanguages as $lang) { |
| 58 | $this->out('language:' . $lang); |
| 59 | $xmlString = Service::singleton() |
| 60 | ->getDataItemByRdfItem($item, $lang) |
| 61 | ->toXML(); |
| 62 | if (empty($xmlString)) { |
| 63 | $this->out('no qti xml found'); |
| 64 | } else { |
| 65 | $qti = $this->convertQtiFromV2p0ToV2p1($xmlString); |
| 66 | if (empty($qti)) { |
| 67 | $this->out('fail'); |
| 68 | } else { |
| 69 | $this->out('done'); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | protected function convertQtiFromV2p0ToV2p1($xml) |
| 76 | { |
| 77 | |
| 78 | $returnValue = ''; |
| 79 | |
| 80 | $qtiParser = new Parser($xml); |
| 81 | $qtiv2p1xsd = ROOT_PATH . 'taoQTI/models/classes/QTI/data/qtiv2p0/imsqti_v2p0.xsd'; |
| 82 | $qtiParser->validate($qtiv2p1xsd); |
| 83 | if ($qtiParser->isValid()) { |
| 84 | $this->out('is a qti 2.0 item'); |
| 85 | $item = $qtiParser->load(); |
| 86 | if ($item instanceof Item) { |
| 87 | $this->out('item loaded as QTI 2.1'); |
| 88 | $returnValue = $item->toXML(); |
| 89 | } |
| 90 | } else { |
| 91 | $this->out('does not seem to be a valid qti 2.0 item, attempt to load it anyway.'); |
| 92 | $item = $qtiParser->load(); |
| 93 | if ($item instanceof Item) { |
| 94 | $this->out('Done! Item loaded as QTI 2.1'); |
| 95 | $returnValue = $item->toXML(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return $returnValue; |
| 100 | } |
| 101 | } |