コード例 #1
0
 public function testSeparateStylesheetTwo()
 {
     // The loaded component is still a rubricBlock but this
     // time with two (YES, TWO!) stylesheets.
     $doc = new XmlDocument('2.1');
     $doc->load(self::samplesDir() . 'rendering/rubricblock_3.xml');
     $this->assertEquals(2, count($doc->getDocumentComponent()->getStylesheets()));
     $renderingEngine = new XhtmlRenderingEngine();
     $renderingEngine->setStylesheetPolicy(XhtmlRenderingEngine::STYLESHEET_SEPARATE);
     $rendering = $renderingEngine->render($doc->getDocumentComponent());
     $linkElts = $rendering->getElementsByTagName('link');
     $this->assertEquals(0, $linkElts->length);
     $linksFragment = $renderingEngine->getStylesheets();
     $this->assertInstanceOf('\\DOMDocumentFragment', $linksFragment);
     $this->assertEquals(2, $linksFragment->childNodes->length);
     // Test first <link> element.
     $linkElt = $linksFragment->childNodes->item(0);
     $this->assertEquals('link', $linkElt->localName);
     $this->assertEquals('style1.css', $linkElt->getAttribute('href'));
     $this->assertEquals('text/css', $linkElt->getAttribute('type'));
     $this->assertEquals('screen', $linkElt->getAttribute('media'));
     $this->assertEquals('\\0_ !HOURRAY! _0/', $linkElt->getAttribute('title'));
     // Test second <link> element.
     $linkElt = $linksFragment->childNodes->item(1);
     $this->assertEquals('link', $linkElt->localName);
     $this->assertEquals('style2.css', $linkElt->getAttribute('href'));
     $this->assertEquals('text/css', $linkElt->getAttribute('type'));
     $this->assertEquals('screen', $linkElt->getAttribute('media'));
     $this->assertEquals('0/*\\0 (Jedi duel)', $linkElt->getAttribute('title'));
 }
コード例 #2
0
<?php

/**
 * I don't even understand how it is correctly parsed...
 * But it's safe!
 */
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine;
require_once dirname(__FILE__) . '/../../qtism/qtism.php';
$doc = new XmlDocument();
$doc->load('../samples/rendering/php_highjacking_3.xml', true);
$renderer = new XhtmlRenderingEngine();
$rendering = $renderer->render($doc->getDocumentComponent());
$rendering->formatOutput = true;
echo $rendering->saveXML();
コード例 #3
0
 /**
  * Get the route (the way items are delivered into a test).
  * This method will compute the shuffling and other predefined conditions to take the test.
  *
  * @param string $testFilePath - the path of the QTI Test definition
  * @return array the test structure as it should be delivered.
  */
 private function getRoute($testFilePath)
 {
     $route = array();
     // Load the test definition.
     $testDefinition = new XmlDocument();
     $testDefinition->load($testFilePath);
     // Make the test definition a compact one. Compact tests combine all needed
     // information to run a test instance.
     $resolver = new taoQtiTest_helpers_ItemResolver();
     $compactTestDef = XmlCompactDocument::createFromXmlAssessmentTestDocument($testDefinition, $resolver);
     $sessionManager = new SessionManager();
     $testSession = $sessionManager->createAssessmentTestSession($compactTestDef->getDocumentComponent());
     $assessmentTest = $testSession->getAssessmentTest();
     $renderingEngine = new XhtmlRenderingEngine();
     $testPartId = null;
     $sectionId = null;
     //We are getting items with their respective test part and sections, so we need to restructure it
     foreach ($testSession->getRoute() as $routeItem) {
         $item = array('id' => $routeItem->getAssessmentItemRef()->getIdentifier(), 'href' => $routeItem->getAssessmentItemRef()->getHref());
         $routeSections = $routeItem->getAssessmentSections()->getArrayCopy();
         $lastSection = $routeSections[count($routeSections) - 1];
         if ($sectionId != $lastSection->getIdentifier() || $testPartId != $routeItem->getTestPart()->getIdentifier()) {
             $sectionId = $lastSection->getIdentifier();
             $rubricBlocks = array();
             foreach ($routeItem->getAssessmentSections() as $section) {
                 foreach ($section->getRubricBlocks() as $rubricBlock) {
                     $xmlRendering = $renderingEngine->render($rubricBlock);
                     $strRendering = $xmlRendering->saveXML($xmlRendering->documentElement);
                     $finalRendering = '';
                     // No formatting at all :) !
                     foreach (preg_split('/\\n|\\r/u', $strRendering, -1, PREG_SPLIT_NO_EMPTY) as $line) {
                         $finalRendering .= trim($line);
                     }
                     $rubricBlocks[] = $finalRendering;
                 }
             }
             $section = array('id' => $section->getIdentifier(), 'title' => $section->getTitle(), 'rubricBlock' => $rubricBlocks, 'items' => array($item));
             if ($testPartId != $routeItem->getTestPart()->getIdentifier()) {
                 $testPartId = $routeItem->getTestPart()->getIdentifier();
                 $route[] = array('id' => $testPartId, 'sections' => array($section));
             } else {
                 $route = $this->addSectionToRoute($route, $testPartId, $section);
             }
         } else {
             $route = $this->addItemToRoute($route, $testPartId, $sectionId, $item);
         }
     }
     return array('id' => $assessmentTest->getIdentifier(), 'title' => $assessmentTest->getTitle(), 'testParts' => $route);
 }
コード例 #4
0
ファイル: Render.php プロジェクト: nagyist/qti-sdk
 /**
  * Run the rendering behaviour related to the "XHTML" flavour.
  * 
  * @param \qtism\data\storage\xml\XmlDocument $doc The QTI XML document to be rendered.
  * @param \qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine $renderer
  * @return string The raw rendering data.
  */
 private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer)
 {
     $arguments = $this->getArguments();
     $profile = $arguments['flavour'];
     $xml = $renderer->render($doc->getDocumentComponent());
     $header = '';
     $footer = '';
     $indent = '';
     $nl = '';
     if ($arguments['format'] === true) {
         $xml->formatOutput = true;
         $indent .= "  ";
         $nl .= "\n";
     }
     if ($arguments['document'] === true) {
         $rootComponent = $doc->getDocumentComponent();
         $title = '';
         if ($rootComponent->getQtiClassName() === 'assessmentItem') {
             $title = XmlUtils::escapeXmlSpecialChars($rootComponent->getTitle());
         }
         $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
         $header .= "<html>{$nl}";
         $header .= "{$indent}<head>{$nl}";
         $header .= "{$indent}{$indent}<meta charset=\"utf-8\">{$nl}";
         if (empty($title) !== false) {
             $header .= "{$indent}{$indent}<title>" . $title . "</title>{$nl}";
         }
         $header .= "{$indent}{$indent}" . $renderer->getStylesheets()->ownerDocument->saveXML($renderer->getStylesheets());
         $header .= "{$indent}</head>{$nl}";
         $header .= "{$indent}<body>{$nl}";
         $footer = "{$indent}</body>{$nl}";
         $footer .= "</html>\n";
     }
     $body = $xml->saveXml($xml->documentElement) . "{$nl}";
     // Indent body...
     $indentBody = '';
     if ($arguments['document'] === null) {
         $indent = '';
     }
     foreach (preg_split('/\\n|\\r/u', $body, -1, PREG_SPLIT_NO_EMPTY) as $bodyLine) {
         // do stuff with $line
         $indentBody .= "{$indent}{$indent}{$bodyLine}{$nl}";
     }
     $body = $indentBody;
     return "{$header}{$indentBody}{$footer}";
 }