当前位置: 首页>>代码示例>>PHP>>正文


PHP XmlDocument::getDocumentComponent方法代码示例

本文整理汇总了PHP中qtism\data\storage\xml\XmlDocument::getDocumentComponent方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlDocument::getDocumentComponent方法的具体用法?PHP XmlDocument::getDocumentComponent怎么用?PHP XmlDocument::getDocumentComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qtism\data\storage\xml\XmlDocument的用法示例。


在下文中一共展示了XmlDocument::getDocumentComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSeparateStylesheetTwo

 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'));
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:30,代码来源:XhtmlRenderingEngineTest.php

示例2: toArray

 /**
  * Converts the test from the document to an array
  * @return array the test data as array
  * @throws taoQtiTest_models_classes_QtiTestConverterException
  */
 public function toArray()
 {
     try {
         return $this->componentToArray($this->doc->getDocumentComponent());
     } catch (ReflectionException $re) {
         common_Logger::e($re->getMessage());
         common_Logger::d($re->getTraceAsString());
         throw new taoQtiTest_models_classes_QtiTestConverterException('Unable to convert the QTI Test to json: ' . $re->getMessage());
     }
 }
开发者ID:nagyist,项目名称:extension-tao-testqti,代码行数:15,代码来源:class.QtiTestConverter.php

示例3: testItemSessionControls

 public function testItemSessionControls()
 {
     $doc = new XmlDocument('2.1');
     $doc->load(self::samplesDir() . 'custom/runtime/routeitem_itemsessioncontrols.xml');
     // Q01.
     $q01 = $doc->getDocumentComponent()->getComponentByIdentifier('Q01');
     $this->assertInstanceOf('qtism\\data\\AssessmentItemRef', $q01);
     $this->assertEquals(2, $q01->getItemSessionControl()->getMaxAttempts());
     // P02.
     $p02 = $doc->getDocumentComponent()->getComponentByIdentifier('P02');
     $this->assertInstanceOf('qtism\\data\\TestPart', $p02);
     $this->assertEquals(4, $p02->getItemSessionControl()->getMaxAttempts());
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:13,代码来源:XmlAssessmentTestDocumentTest.php

示例4: testLoadAndResolveXIncludeDifferentBase

 /**
  * @depends testLoadAndResolveXIncludeSameBase
  */
 public function testLoadAndResolveXIncludeDifferentBase()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag_subfolder.xml', true);
     $doc->xInclude();
     $includes = $doc->getDocumentComponent()->getComponentsByClassName('include');
     $this->assertEquals(0, count($includes));
     // And we should find an img component then!
     $imgs = $doc->getDocumentComponent()->getComponentsByClassName('img');
     $this->assertEquals(1, count($imgs));
     // Check that xml:base was appropriately resolved. In this case,
     // no content for xml:base because 'xinclude_ns_in_tag_content1.xml' is in the
     // same directory as the main xml file.
     $this->assertEquals('subfolder/', $imgs[0]->getXmlBase());
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:18,代码来源:XmlDocumentXIncludeTest.php

示例5: parse

 public function parse($xmlString, $validate = true)
 {
     // TODO: Remove this, and move it higher up
     LogService::flush();
     $xmlDocument = new XmlDocument();
     if ($validate === false) {
         LogService::log('QTI pre-validation is turned off, some invalid attributes might be stripped from XML content upon conversion');
     }
     $xmlDocument->loadFromString($xmlString, $validate);
     /** @var AssessmentItem $assessmentItem */
     $assessmentTest = $xmlDocument->getDocumentComponent();
     if (!$assessmentTest instanceof AssessmentTest) {
         throw new MappingException('XML is not a valid <assessmentItem> document');
     }
     // Ignore `testPart` and `assessmentSection`. Grab every item references and merge in array
     $itemReferences = [];
     foreach ($assessmentTest->getComponentsByClassName('assessmentItemRef', true) as $assessmentItemRef) {
         $itemReferences[] = $assessmentItemRef->getIdentifier();
     }
     LogService::log('Support for mapping is very limited. Elements such `testPart`, `assessmentSections`, `seclection`, `rubricBlock`, ' . 'etc are ignored. Please see developer docs for more details');
     $data = new activity_data();
     $data->set_items($itemReferences);
     $activity = new activity($assessmentTest->getIdentifier(), $data);
     // Flush out all the error messages stored in this static class, also ensure they are unique
     $messages = array_values(array_unique(LogService::flush()));
     return [$activity, $messages];
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:27,代码来源:TestMapper.php

示例6: testAssigningScoresAndCorrectResponses

 public function testAssigningScoresAndCorrectResponses()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/items/template_processing.xml');
     $session = new AssessmentItemSession($doc->getDocumentComponent());
     $itemSessionControl = new ItemSessionControl();
     $itemSessionControl->setMaxAttempts(0);
     $session->setItemSessionControl($itemSessionControl);
     $session->beginItemSession();
     // Check that the templateProcessing was correctly processed.
     $this->assertEquals('ChoiceA', $session->getVariable('RESPONSE')->getCorrectResponse()->getValue());
     $this->assertEquals(1.0, $session['GOODSCORE']->getValue());
     $this->assertEquals(0.0, $session['WRONGSCORE']->getValue());
     // Check that it really works...
     // With a correct response.
     $session->beginAttempt();
     $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceA'))));
     $session->endAttempt($responses);
     $this->assertEquals(1.0, $session['SCORE']->getValue());
     // With an incorrect response.
     $session->beginAttempt();
     $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceB'))));
     $session->endAttempt($responses);
     $this->assertEquals(0.0, $session['SCORE']->getValue());
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:25,代码来源:AssessmentItemSessionTemplateTest.php

示例7: testWrite

 public function testWrite()
 {
     $uri = self::samplesDir() . 'custom/standalone_assessmentsection.xml';
     $doc = new XmlDocument();
     $doc->load($uri);
     $assessmentSection = $doc->getDocumentComponent();
     // Write the file.
     $uri = tempnam('/tmp', 'qsm');
     $doc->save($uri);
     $this->assertTrue(file_exists($uri));
     // Reload it.
     $doc->load($uri);
     $this->assertInstanceOf('qtism\\data\\AssessmentSection', $doc->getDocumentComponent());
     // Retest.
     $this->testLoad($doc->getDocumentComponent());
     unlink($uri);
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:17,代码来源:XmlAssessmentSectionDocumentTest.php

示例8: testGetShuffledChoiceIdentifierAtInvalidShuffledChoiceIndex

 public function testGetShuffledChoiceIdentifierAtInvalidShuffledChoiceIndex()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'ims/items/2_1/choice_fixed.xml');
     $session = new AssessmentItemSession($doc->getDocumentComponent());
     $session->beginItemSession();
     $this->setExpectedException('\\OutOfBoundsException', 'No identifier at index 1337.');
     $session->getShuffledChoiceIdentifierAt(0, 1337);
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:9,代码来源:AssessmentItemSessionShufflingTest.php

示例9: testTimeLimits

 public function testTimeLimits()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/timelimits.xml');
     $testPart = $doc->getDocumentComponent()->getComponentByIdentifier('testPartId');
     $this->assertTrue($testPart->hasTimeLimits());
     $timeLimits = $testPart->getTimeLimits();
     $this->assertTrue($timeLimits->getMinTime()->equals(new Duration('PT60S')));
     $this->assertTrue($timeLimits->getMaxTime()->equals(new Duration('PT120S')));
     $this->assertTrue($timeLimits->doesAllowLateSubmission());
 }
开发者ID:hutnikau,项目名称:qti-sdk,代码行数:11,代码来源:AssessmentTestTest.php

示例10: testBasicSelection

 public function testBasicSelection()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/selection_and_ordering.xml');
     $testPart = $doc->getDocumentComponent()->getComponentByIdentifier('testPart');
     $this->assertEquals('testPart', $testPart->getIdentifier());
     $s01 = $doc->getDocumentComponent()->getComponentByIdentifier('S01', true);
     $this->assertEquals('S01', $s01->getIdentifier());
     // Prepare route selection of S01A.
     $s01a = $doc->getDocumentComponent()->getComponentByIdentifier('S01A', true);
     $this->assertEquals('S01A', $s01a->getIdentifier());
     $s01aRoute = new SelectableRoute();
     foreach ($s01a->getSectionParts() as $sectionPart) {
         $s01aRoute->addRouteItem($sectionPart, $s01a, $testPart, $doc->getDocumentComponent());
     }
     // Prepare route selection of S01B.
     $s01b = $doc->getDocumentComponent()->getComponentByIdentifier('S01B', true);
     $this->assertEquals('S01B', $s01b->getIdentifier());
     $s01bRoute = new SelectableRoute();
     foreach ($s01b->getSectionParts() as $sectionPart) {
         $s01bRoute->addRouteItem($sectionPart, $s01b, $testPart, $doc->getDocumentComponent());
     }
     $selection = new BasicSelection($s01, new SelectableRouteCollection(array($s01aRoute, $s01bRoute)));
     $selectedRoutes = $selection->select();
     $selectedRoute = new SelectableRoute();
     foreach ($selectedRoutes as $r) {
         $selectedRoute->appendRoute($r);
     }
     $routeCheck1 = self::isRouteCorrect($selectedRoute, array('Q1', 'Q2', 'Q3'));
     $routeCheck2 = self::isRouteCorrect($selectedRoute, array('Q4', 'Q5', 'Q6'));
     $this->assertFalse($routeCheck1 === true && $routeCheck2 === true);
     $this->assertTrue($routeCheck1 === true || $routeCheck2 === true);
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:33,代码来源:BasicSelectionTest.php

示例11: testAssessmentTests

function testAssessmentTests(array $files, $validate = false)
{
    $loaded = 0;
    $totalSpent = 0;
    foreach ($files as $f) {
        $start = microtime();
        $testDoc = new XmlDocument();
        $testDoc->load($f, $validate);
        $end = microtime();
        $spent = spentTime($start, $end);
        $totalSpent += $spent;
        output("Test '" . pathinfo($f, PATHINFO_BASENAME) . "' loaded in " . sprintf("%.8f", $spent) . " seconds.");
        $partCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('testPart'));
        $sectionCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('assessmentSection'));
        $itemCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('assessmentItemRef'));
        outputDescription("{$partCount} testPart(s), {$sectionCount} assessmentSection(s), {$itemCount} assessmentItemRef(s)");
        outputDescription("Memory usage is " . memory_get_usage() / pow(1024, 2) . " MB");
        output('');
        $loaded++;
    }
    outputAverage($totalSpent / $loaded);
}
开发者ID:nagyist,项目名称:qti-sdk,代码行数:22,代码来源:XmlLoadSpeed.php

示例12: processResponses

 /**
  * Item's ResponseProcessing.
  *
  * @param core_kernel_classes_Resource $item The Item you want to apply ResponseProcessing.
  * @throws \RuntimeException If an error occurs while processing responses or transmitting results
  */
 protected function processResponses(core_kernel_classes_Resource $item)
 {
     $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload();
     try {
         $qtiXmlFilePath = QtiFile::getQtiFilePath($item);
         $qtiXmlDoc = new XmlDocument();
         $qtiXmlDoc->load($qtiXmlFilePath);
     } catch (StorageException $e) {
         $msg = "An error occurred while loading QTI-XML file at expected location '{$qtiXmlFilePath}'.";
         common_Logger::e($e->getPrevious()->getMessage());
         throw new \RuntimeException($msg, 0, $e);
     }
     $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager());
     $itemSession->beginItemSession();
     $variables = array();
     $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent());
     // Convert client-side data as QtiSm Runtime Variables.
     foreach ($jsonPayload as $id => $response) {
         try {
             $var = $filler->fill($id, $response);
             // Do not take into account QTI Files at preview time.
             // Simply delete the created file.
             if (taoQtiCommon_helpers_Utils::isQtiFile($var, false) === true) {
                 $fileManager = taoQtiCommon_helpers_Utils::getFileDatatypeManager();
                 $fileManager->delete($var->getValue());
             } else {
                 $variables[] = $var;
             }
         } catch (OutOfRangeException $e) {
             // A variable value could not be converted, ignore it.
             // Developer's note: QTI Pairs with a single identifier (missing second identifier of the pair) are transmitted as an array of length 1,
             // this might cause problem. Such "broken" pairs are simply ignored.
             common_Logger::d("Client-side value for variable '{$id}' is ignored due to data malformation.");
         } catch (OutOfBoundsException $e) {
             // No such identifier found in item.
             common_Logger::d("The variable with identifier '{$id}' is not declared in the item definition.");
         }
     }
     try {
         $itemSession->beginAttempt();
         $itemSession->endAttempt(new State($variables));
         // Return the item session state to the client-side.
         echo json_encode(array('success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession)));
     } catch (AssessmentItemSessionException $e) {
         $msg = "An error occurred while processing the responses.";
         throw new \RuntimeException($msg, 0, $e);
     } catch (taoQtiCommon_helpers_ResultTransmissionException $e) {
         $msg = "An error occurred while transmitting a result to the target Result Server.";
         throw new \RuntimeException($msg, 0, $e);
     }
 }
开发者ID:nagyist,项目名称:extension-tao-itemqti,代码行数:57,代码来源:QtiPreview.php

示例13: testLoadMatchCorrect

 public function testLoadMatchCorrect()
 {
     $xml = new XmlDocument('2.1');
     $xml->load(self::getTemplatesPath() . '2_1/match_correct.xml');
     $this->assertInstanceOf('qtism\\data\\processing\\ResponseProcessing', $xml->getDocumentComponent());
     $this->assertFalse($xml->getDocumentComponent()->hasTemplateLocation());
     $this->assertFalse($xml->getDocumentComponent()->hasTemplate());
     $responseRules = $xml->getDocumentComponent()->getResponseRules();
     $this->assertEquals(1, count($responseRules));
     $responseCondition = $responseRules[0];
     $this->assertInstanceOf('qtism\\data\\rules\\ResponseCondition', $responseCondition);
     $responseIf = $responseCondition->getResponseIf();
     $match = $responseIf->getExpression();
     $this->assertInstanceOf('qtism\\data\\expressions\\operators\\Match', $match);
     $matchExpressions = $match->getExpressions();
     $this->assertEquals(2, count($matchExpressions));
     $variable = $matchExpressions[0];
     $this->assertInstanceOf('qtism\\data\\expressions\\Variable', $variable);
     $this->assertEquals('RESPONSE', $variable->getIdentifier());
     $correct = $matchExpressions[1];
     $this->assertInstanceOf('qtism\\data\\expressions\\Correct', $correct);
     $this->assertEquals('RESPONSE', $correct->getIdentifier());
     // To be continued...
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:24,代码来源:XmlResponseProcessingDocumentTest.php

示例14: testModerateXmlBase

 public function testModerateXmlBase()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'rendering/xmlbase_2.xml');
     $div = $doc->getDocumentComponent();
     $this->assertInstanceOf('qtism\\data\\content\\xhtml\\text\\Div', $div);
     $this->assertFalse($div->hasXmlBase());
     $this->assertEquals('', $div->getXmlBase());
     $subDivs = $div->getComponentsByClassName('div');
     $this->assertEquals(2, count($subDivs));
     $this->assertTrue($subDivs[0]->hasXmlBase());
     $this->assertEquals('http://www.qtism-project.org/farm/', $subDivs[0]->getXmlBase());
     $this->assertTrue($subDivs[1]->hasXmlBase());
     $this->assertEquals('http://www.qtism-project.org/birds/', $subDivs[1]->getXmlBase());
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:15,代码来源:XmlAssessmentContentDocumentTest.php

示例15: parse

 public function parse($xmlString, $validate = true)
 {
     // TODO: Remove this, and move it higher up
     LogService::flush();
     $xmlDocument = new XmlDocument();
     if ($validate === false) {
         LogService::log('QTI pre-validation is turned off, some invalid attributes might be stripped from XML content upon conversion');
     }
     $xmlDocument->loadFromString($xmlString, $validate);
     /** @var AssessmentItem $assessmentItem */
     $assessmentItem = $xmlDocument->getDocumentComponent();
     if (!$assessmentItem instanceof AssessmentItem) {
         throw new MappingException('XML is not a valid <assessmentItem> document');
     }
     return $this->parseWithAssessmentItemComponent($assessmentItem);
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:16,代码来源:ItemMapper.php


注:本文中的qtism\data\storage\xml\XmlDocument::getDocumentComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。