public function buildItemBody(array $interactions, $content = '') { // Try to build the <itemBody> according to items` content if exists if (empty($content)) { return $this->buildItemBodySimple($interactions); } try { return $this->buildItemBodyWithItemContent($interactions, $content); // If anything fails, <itemBody> can't be mapped due to whatever reasons // Probably simply due to its being wrapped in a tag which only accept inline content // Simply build it without considering items` content and put the content on the top } catch (\Exception $e) { $itemBody = $this->buildItemBodySimple($interactions); $itemBodyContent = new BlockCollection(); // Build the div bundle that contains all the item`s content // minus those questions and features `span` $html = new SimpleHtmlDom(); $html->load($content); foreach ($html->find('span.learnosity-response') as &$span) { $span->outertext = ''; } $div = new Div(); $contentCollection = QtiMarshallerUtil::unmarshallElement($html->save()); $div->setContent(ContentCollectionBuilder::buildFlowCollectionContent($contentCollection)); $itemBodyContent->attach($div); $itemBodyContent->merge($itemBody->getComponents()); $itemBody->setContent($itemBodyContent); LogService::log('Interactions are failed to be mapped with `item` content: ' . $e->getMessage() . '. Thus, interactions are separated from its actual `item` content and appended in the bottom'); return $itemBody; } }