private function map(Question $question)
 {
     $type = $question->get_type();
     if (!in_array($type, Constants::$supportedQuestionTypes)) {
         throw new MappingException("Question type `{$type}` not yet supported to be mapped to QTI");
     }
     $clazz = new \ReflectionClass(self::MAPPER_CLASS_BASE . ucfirst($type . 'Mapper'));
     $questionTypeMapper = $clazz->newInstance();
     // Try to use question `reference` as identifier
     // Otherwise, generate an alternative identifier and store the original reference as `label` to be passed in
     $questionReference = $question->get_reference();
     $interactionIdentifier = Format::isIdentifier($questionReference, false) ? $questionReference : strtoupper($type) . '_' . StringUtil::generateRandomString(12);
     if ($interactionIdentifier !== $questionReference) {
         LogService::log("The question `reference` ({$questionReference}) is not a valid identifier. " . "Replaced it with randomly generated `{$interactionIdentifier}` and stored the original `reference` as `label` attribute");
     }
     $result = $questionTypeMapper->convert($question->get_data(), $interactionIdentifier, $questionReference);
     $result[] = $questionTypeMapper->getExtraContent();
     return $result;
 }
 public function convert(Question $question)
 {
     // Make sure we clean up the log
     LogService::flush();
     // Try to build the identifier using question `reference`
     // Otherwise, generate an alternative identifier and store the original reference as `label`
     $questionReference = $question->get_reference();
     $questionIdentifier = Format::isIdentifier($questionReference, false) ? $questionReference : 'ITEM_' . StringUtil::generateRandomString(12);
     if ($questionReference !== $questionIdentifier) {
         LogService::log("The question `reference` ({$questionReference}) is not a valid identifier, thus can not be used for `assessmentItem` identifier. " . "Replaced it with randomly generated `{$questionIdentifier}`");
     }
     $builder = new AssessmentItemBuilder();
     $assessmentItem = $builder->build($questionIdentifier, '', [$question]);
     $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];
 }
 public function convert(Question $question)
 {
     return $question->to_array();
 }