* @package taoQTI */ class taoQTI_scripts_update_taoQtiUpdate extends tao_scripts_Runner { public function run() { $itemService = taoItems_models_classes_ItemsService::singleton(); $itemClass = new core_kernel_classes_Class(TaoOntology::ITEM_CLASS_URI); $items = $itemClass->getInstances(true); foreach ($items as $item) { $itemModel = $itemService->getItemModel($item); if (!is_null($itemModel) && $itemModel->getUri() == ItemModel::MODEL_URI) { $this->out('qti item found: ' . $item->getLabel()); $this->convertQtiItem($item); } // break; } } protected function convertQtiItem(core_kernel_classes_Resource $item) { $itemContentProp = new core_kernel_classes_Property(\taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT); $usedLanguages = $item->getUsedLanguages($itemContentProp); foreach ($usedLanguages as $lang) { $this->out('language:' . $lang); $xmlString = Service::singleton() ->getDataItemByRdfItem($item, $lang) ->toXML(); if (empty($xmlString)) { $this->out('no qti xml found'); } else { $qti = $this->convertQtiFromV2p0ToV2p1($xmlString); if (empty($qti)) { $this->out('fail'); } else { $this->out('done'); } } } } protected function convertQtiFromV2p0ToV2p1($xml) { $returnValue = ''; $qtiParser = new Parser($xml); $qtiv2p1xsd = ROOT_PATH . 'taoQTI/models/classes/QTI/data/qtiv2p0/imsqti_v2p0.xsd'; $qtiParser->validate($qtiv2p1xsd); if ($qtiParser->isValid()) { $this->out('is a qti 2.0 item'); $item = $qtiParser->load(); if ($item instanceof Item) { $this->out('item loaded as QTI 2.1'); $returnValue = $item->toXML(); } } else { $this->out('does not seem to be a valid qti 2.0 item, attempt to load it anyway.'); $item = $qtiParser->load(); if ($item instanceof Item) { $this->out('Done! Item loaded as QTI 2.1'); $returnValue = $item->toXML(); } } return $returnValue; } }