private function buildItemBodyWithItemContent(array $interactions, $content) { // Map <itemBody> // TODO: Wrap these `content` stuff in a div // TODO: to avoid QtiComponentIterator bug ignoring 2nd element with empty content $contentCollection = QtiMarshallerUtil::unmarshallElement($content); $wrapperCollection = new FlowCollection(); foreach ($contentCollection as $component) { $wrapperCollection->attach($component); } $divWrapper = new Div(); $divWrapper->setContent($wrapperCollection); // Iterate through these elements and try to replace every single question `span` with its interaction equivalent $iterator = $divWrapper->getIterator(); foreach ($iterator as $component) { if ($component instanceof Span && StringUtil::contains($component->getClass(), 'learnosity-response')) { $currentContainer = $iterator->getCurrentContainer(); $questionReference = trim(str_replace('learnosity-response', '', $component->getClass())); $questionReference = trim(str_replace('question-', '', $questionReference)); // Build the actual interaction $interaction = $interactions[$questionReference]['interaction']; $content = new FlowCollection(); if (isset($interactions[$questionReference]['extraContent'])) { $content->attach($interactions[$questionReference]['extraContent']); } $content->attach($interaction); $replacement = ContentCollectionBuilder::buildContent($currentContainer, $content)->current(); $currentContainer->getComponents()->replace($component, $replacement); } } // Extract the actual content from the div wrapper and add that to our <itemBody> $componentsWithinDiv = $divWrapper->getComponents(); $itemBody = new ItemBody(); $itemBody->setContent(ContentCollectionBuilder::buildBlockCollectionContent($componentsWithinDiv)); return $itemBody; }