Пример #1
0
 public function parse($xmlString, $validate = true)
 {
     // TODO: Remove this, and move it higher up
     LogService::flush();
     $xmlDocument = new XmlDocument();
     if ($validate === false) {
         LogService::log('QTI pre-validation is turned off, some invalid attributes might be stripped from XML content upon conversion');
     }
     $xmlDocument->loadFromString($xmlString, $validate);
     /** @var AssessmentItem $assessmentItem */
     $assessmentTest = $xmlDocument->getDocumentComponent();
     if (!$assessmentTest instanceof AssessmentTest) {
         throw new MappingException('XML is not a valid <assessmentItem> document');
     }
     // Ignore `testPart` and `assessmentSection`. Grab every item references and merge in array
     $itemReferences = [];
     foreach ($assessmentTest->getComponentsByClassName('assessmentItemRef', true) as $assessmentItemRef) {
         $itemReferences[] = $assessmentItemRef->getIdentifier();
     }
     LogService::log('Support for mapping is very limited. Elements such `testPart`, `assessmentSections`, `seclection`, `rubricBlock`, ' . 'etc are ignored. Please see developer docs for more details');
     $data = new activity_data();
     $data->set_items($itemReferences);
     $activity = new activity($assessmentTest->getIdentifier(), $data);
     // Flush out all the error messages stored in this static class, also ensure they are unique
     $messages = array_values(array_unique(LogService::flush()));
     return [$activity, $messages];
 }
Пример #2
0
 public static function convertQtiManifestToLearnosity($xmlString, array $rules = [])
 {
     /** @var ManifestMapper $manifestMapper */
     $manifestMapper = AppContainer::getApplicationContainer()->get('imscp_manifest_mapper');
     /** @var ManifestWriter $manifestWriter */
     $manifestWriter = AppContainer::getApplicationContainer()->get('learnosity_manifest_writer');
     try {
         LogService::flush();
         $manifest = $manifestMapper->parse($xmlString);
         list($activities, $activitiesTags, $itemsTags) = $manifestWriter->convert($manifest, $rules);
         $messages = LogService::flush();
         return [$activities, $activitiesTags, $itemsTags, $messages];
     } catch (Exception $e) {
         throw new MappingException($e->getMessage());
     }
 }
Пример #3
0
 public function convert(item $item, array $questions)
 {
     // Make sure we clean up the log
     LogService::flush();
     // Try to build the identifier using item `reference`
     // Otherwise, generate an alternative identifier and store the original reference as `label`
     $itemReference = $item->get_reference();
     $itemIdentifier = Format::isIdentifier($itemReference, false) ? $itemReference : 'ITEM_' . StringUtil::generateRandomString(12);
     if ($itemReference !== $itemIdentifier) {
         LogService::log("The item `reference` ({$itemReference}) is not a valid identifier, thus can not be used for `assessmentItem` identifier. " . "Replaced it with randomly generated `{$itemIdentifier}` and stored the original `reference` as `label` attribute");
     }
     $builder = new AssessmentItemBuilder();
     $assessmentItem = $builder->build($itemIdentifier, $itemReference, $questions, $item->get_content());
     $xml = new XmlDocument();
     $xml->setDocumentComponent($assessmentItem);
     // Flush out all the error messages stored in this static class, also ensure they are unique
     $messages = array_values(array_unique(LogService::flush()));
     return [$xml->saveToString(true), $messages];
 }
Пример #4
0
 public function parseWithAssessmentItemComponent(AssessmentItem $assessmentItem)
 {
     // TODO: Move this logging service upper to converter class level
     // Make sure we clean up the log
     // LogService::flush();
     $processings = [AppContainer::getApplicationContainer()->get('rubrics_processing'), AppContainer::getApplicationContainer()->get('maths_processing'), AppContainer::getApplicationContainer()->get('assets_processing'), AppContainer::getApplicationContainer()->get('identifiers_processing')];
     // Pre-processing works
     /** @var ProcessingInterface $processing */
     foreach ($processings as $processing) {
         $assessmentItem = $processing->processAssessmentItem($assessmentItem);
     }
     $assessmentItem = $this->validateAssessmentItem($assessmentItem);
     $responseProcessingTemplate = $this->getResponseProcessingTemplate($assessmentItem->getResponseProcessing());
     /** @var ItemBody $itemBody */
     $itemBody = $assessmentItem->getItemBody();
     // Mapping interactions
     $interactionComponents = $itemBody->getComponentsByClassName(Constants::$supportedInteractions, true);
     if (!$interactionComponents || count($interactionComponents) === 0) {
         throw new MappingException('No supported interaction mapper could be found');
     }
     $responseDeclarations = $assessmentItem->getComponentsByClassName('responseDeclaration', true);
     $itemBuilder = $this->itemBuilderFactory->getItemBuilder($interactionComponents);
     $itemBuilder->map($assessmentItem->getIdentifier(), $itemBody, $interactionComponents, $responseDeclarations, $responseProcessingTemplate);
     $item = $itemBuilder->getItem();
     if ($assessmentItem->getTitle()) {
         $item->set_description($assessmentItem->getTitle());
     }
     $questions = $itemBuilder->getQuestions();
     // Post-processing works
     /** @var ProcessingInterface $processing */
     foreach ($processings as $processing) {
         list($item, $questions) = $processing->processItemAndQuestions($item, $questions);
     }
     // Flush out all the error messages stored in this static class, also ensure they are unique
     $messages = array_values(array_unique(LogService::flush()));
     return [$item, $questions, $messages];
 }
 public function tearDown()
 {
     LogService::flush();
 }