Ejemplo n.º 1
0
 /**
  * @see \qtism\runtime\rendering\markup\xhtml\AbstractXhtmlRenderer::appendChildren()
  */
 protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendChildren($fragment, $component, $base);
     // Retrieve the two rendered simpleMatchSets and shuffle if needed.
     $currentSet = 0;
     $choiceElts = array();
     $simpleMatchSetElts = array();
     for ($i = 0; $i < $fragment->firstChild->childNodes->length; $i++) {
         $n = $fragment->firstChild->childNodes->item($i);
         if (Utils::hasClass($n, 'qti-simpleMatchSet') === true) {
             $simpleMatchSetElts[] = $n;
             $sets = $component->getSimpleMatchSets();
             if ($this->getRenderingEngine()->getShufflingPolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE && $component->mustShuffle()) {
                 Utils::shuffle($n, new ShufflableCollection($sets[$currentSet]->getSimpleAssociableChoices()->getArrayCopy()));
             }
             // Retrieve the two content of the two simpleMatchSets, separately.
             $choiceElts[] = Marshaller::getChildElementsByTagName($n, 'li');
             $currentSet++;
         }
     }
     // simpleMatchSet class cannot be rendered into a table :/
     foreach ($simpleMatchSetElts as $sms) {
         $fragment->firstChild->removeChild($sms);
     }
     $table = $fragment->ownerDocument->createElement('table');
     $fragment->firstChild->appendChild($table);
     // Build the table header.
     $tr = $fragment->ownerDocument->createElement('tr');
     $table->appendChild($tr);
     // Empty upper left cell.
     $tr->appendChild($fragment->ownerDocument->createElement('th'));
     $ifVerticalStatementsStorage = array();
     for ($i = 0; $i < count($choiceElts[1]); $i++) {
         $ifStatements = Utils::extractStatements($choiceElts[1][$i], Utils::EXTRACT_IF);
         $incStatements = Utils::extractStatements($choiceElts[1][$i], Utils::EXTRACT_INCLUDE);
         if (empty($incStatements) === false) {
             $tr->appendChild($incStatements[0]);
         }
         if (empty($ifStatements) === false) {
             $ifVerticalStatementsStorage[$i] = $ifStatements;
             $tr->appendChild($ifStatements[0]);
         }
         $th = XmlUtils::changeElementName($choiceElts[1][$i], 'th');
         $tr->appendChild($th);
         if (empty($incStatements) === false) {
             $th->parentNode->insertBefore($incStatements[1], $th->nextSibling);
         }
         if (empty($ifStatements) === false) {
             $th->parentNode->insertBefore($ifStatements[1], $th->nextSibling);
         }
     }
     // Build all remaining rows.
     for ($i = 0; $i < count($choiceElts[0]); $i++) {
         $tr = $fragment->ownerDocument->createElement('tr');
         $ifStatements = Utils::extractStatements($choiceElts[0][$i], Utils::EXTRACT_IF);
         $incStatements = Utils::extractStatements($choiceElts[0][$i], Utils::EXTRACT_INCLUDE);
         $th = XmlUtils::changeElementName($choiceElts[0][$i], 'th');
         $tr->appendChild($th);
         $table->appendChild($tr);
         if (empty($incStatements) === false) {
             $tr->parentNode->insertBefore($incStatements[0], $tr);
         }
         if (empty($ifStatements) === false) {
             $tr->parentNode->insertBefore($ifStatements[0], $tr);
         }
         for ($j = 0; $j < count($choiceElts[1]); $j++) {
             $input = $fragment->ownerDocument->createElement('input');
             $input->setAttribute('type', 'checkbox');
             $td = $fragment->ownerDocument->createElement('td');
             $td->appendChild($input);
             $tr->appendChild($td);
             if (isset($ifVerticalStatementsStorage[$j])) {
                 $td->parentNode->insertBefore($ifVerticalStatementsStorage[$j][0]->cloneNode(), $td);
                 $td->parentNode->insertBefore($ifVerticalStatementsStorage[$j][1]->cloneNode(), $td->nextSibling);
             }
         }
         if (empty($incStatements) === false && isset($td)) {
             $tr->parentNode->insertBefore($incStatements[1], $tr->nextSibling);
         }
         if (empty($ifStatements) === false && isset($td)) {
             $tr->parentNode->insertBefore($ifStatements[1], $tr->nextSibling);
         }
     }
 }
 protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendChildren($fragment, $component, $base);
     // Retrieve the two rendered simpleMatchSets and shuffle if needed.
     $currentSet = 0;
     $choiceElts = array();
     $simpleMatchSetElts = array();
     for ($i = 0; $i < $fragment->firstChild->childNodes->length; $i++) {
         $n = $fragment->firstChild->childNodes->item($i);
         if (Utils::hasClass($n, 'qti-simpleMatchSet') === true) {
             $simpleMatchSetElts[] = $n;
             $sets = $component->getSimpleMatchSets();
             if ($this->getRenderingEngine()->mustShuffle() === true) {
                 Utils::shuffle($n, new ShufflableCollection($sets[$currentSet]->getSimpleAssociableChoices()->getArrayCopy()));
             }
             // Retrieve the two content of the two simpleMatchSets, separately.
             $choiceElts[] = Marshaller::getChildElementsByTagName($n, 'div');
             $currentSet++;
         }
     }
     // simpleMatchSet class cannot be rendered into a table :/
     foreach ($simpleMatchSetElts as $sms) {
         $fragment->firstChild->removeChild($sms);
     }
     $table = $fragment->ownerDocument->createElement('table');
     $fragment->firstChild->appendChild($table);
     // Build the table header.
     $tr = $fragment->ownerDocument->createElement('tr');
     $table->appendChild($tr);
     // Empty upper left cell.
     $tr->appendChild($fragment->ownerDocument->createElement('th'));
     for ($i = 0; $i < count($choiceElts[1]); $i++) {
         $tr->appendChild(XmlUtils::changeElementName($choiceElts[1][$i], 'th'));
     }
     // Build all remaining rows.
     for ($i = 0; $i < count($choiceElts[0]); $i++) {
         $tr = $fragment->ownerDocument->createElement('tr');
         $tr->appendChild(XmlUtils::changeElementName($choiceElts[0][$i], 'th'));
         $table->appendChild($tr);
         for ($j = 0; $j < count($choiceElts[1]); $j++) {
             $input = $fragment->ownerDocument->createElement('input');
             $input->setAttribute('type', 'checkbox');
             $td = $fragment->ownerDocument->createElement('td');
             $td->appendChild($input);
             $tr->appendChild($td);
         }
     }
 }