本文整理汇总了PHP中qtism\data\storage\xml\XmlDocument::save方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlDocument::save方法的具体用法?PHP XmlDocument::save怎么用?PHP XmlDocument::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtism\data\storage\xml\XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSaveSimpleItemSessionControlOnTestPart
public function testSaveSimpleItemSessionControlOnTestPart()
{
$doc = new XmlDocument('2.1');
$doc->load(self::samplesDir() . 'custom/simple_itemsessioncontrol_testpart.xml');
$file = tempnam('/tmp', 'qsm');
$doc->save($file);
$doc = new XmlDocument('2.1');
$doc->load($file);
$testParts = $doc->getDocumentComponent()->getTestParts();
$this->assertTrue($testParts['testPartId']->hasItemSessionControl());
$this->assertInternalType('integer', 0, $testParts['testPartId']->getItemSessionControl()->getMaxAttempts());
$this->assertEquals(0, $testParts['testPartId']->getItemSessionControl()->getMaxAttempts());
unlink($file);
}
示例2: 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);
}
示例3: testLoadAndSaveXIncludeNsInTag
public function testLoadAndSaveXIncludeNsInTag()
{
$doc = new XmlDocument();
$doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag.xml', true);
$includes = $doc->getDocumentComponent()->getComponentsByClassName('include');
$this->assertEquals(1, count($includes));
$this->assertEquals('xinclude_ns_in_tag_content1.xml', $includes[0]->getHref());
$file = tempnam('/tmp', 'qsm');
$doc->save($file);
// Does it validate again?
$doc = new XmlDocument();
try {
$doc->load($file, true);
$this->assertTrue(true);
} catch (XmlStorageException $e) {
$this->assertFalse(true, "The document using xinclude should validate after being saved.");
}
}
示例4: testWritePCIItem
public function testWritePCIItem()
{
$doc = new XmlDocument();
$doc->load(self::samplesDir() . 'custom/interactions/custom_interaction_pci.xml');
$file = tempnam('/tmp', 'qsm');
$doc->save($file);
$this->testLoadPCIItem($file);
unlink($file);
}
示例5: importTestDefinition
/**
* Import the Test itself by importing its QTI-XML definition into the system, after
* the QTI Items composing the test were also imported.
*
* The $itemMapping argument makes the implementation of this method able to know
* what are the items that were imported. The $itemMapping is an associative array
* where keys are the assessmentItemRef's identifiers and the values are the core_kernel_classes_Resources of
* the items that are now stored in the system.
*
* When this method returns false, it means that an error occured at the level of the content of the imported test
* itself e.g. an item referenced by the test is not present in the content package. In this case, $report might
* contain useful information to return to the client.
*
* @param core_kernel_classes_Resource $testResource A Test Resource the new content must be bind to.
* @param XmlDocument $testDefinition An XmlAssessmentTestDocument object.
* @param oat\taoQtiItem\model\qti\Resource $qtiResource The manifest resource describing the test to be imported.
* @param array $itemMapping An associative array that represents the mapping between assessmentItemRef elements and the imported items.
* @param string $extractionFolder The absolute path to the temporary folder containing the content of the imported IMS QTI Package Archive.
* @param common_report_Report $report A Report object to be filled during the import.
* @return core_kernel_file_File The newly created test content.
* @throws taoQtiTest_models_classes_QtiTestServiceException If an unexpected runtime error occurs.
*/
protected function importTestDefinition(core_kernel_classes_Resource $testResource, XmlDocument $testDefinition, Resource $qtiResource, array $itemMapping, $extractionFolder, common_report_Report $report)
{
foreach ($itemMapping as $itemRefId => $itemResource) {
$itemRef = $testDefinition->getDocumentComponent()->getComponentByIdentifier($itemRefId);
$itemRef->setHref($itemResource->getUri());
}
// Bind the newly created test content to the Test Resource in database.
$ds = DIRECTORY_SEPARATOR;
$testContent = $this->createContent($testResource);
$testPath = $testContent->getAbsolutePath();
$finalPath = taoQtiTest_helpers_Utils::storeQtiResource($testContent, $qtiResource, $extractionFolder, false, TAOQTITEST_FILENAME);
// Delete template test.xml file (created by self::createContent() method) from the root.
// (Absolutely necessary when the test.xml file is not in the root folder of the archive)
unlink($testPath . $ds . TAOQTITEST_FILENAME);
try {
$testDefinition->save($finalPath);
} catch (StorageException $e) {
throw new taoQtiTest_models_classes_QtiTestServiceException("An error occured while saving the QTI-XML test.", taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR);
}
return $testContent;
}
示例6: embedAssets
/**
* Embed external resources into the XML
*
* @param string $originalXml
* @throws \tao_models_classes_FileNotFoundException
* @return string
*/
public static function embedAssets($originalXml)
{
$basedir = dirname($originalXml) . DIRECTORY_SEPARATOR;
$xmlDocument = new XmlDocument();
$xmlDocument->load($originalXml, true);
//get images and object to base64 their src/data
$images = $xmlDocument->getDocumentComponent()->getComponentsByClassName('img');
$objects = $xmlDocument->getDocumentComponent()->getComponentsByClassName('object');
/** @var $image \qtism\data\content\xhtml\Img */
foreach ($images as $image) {
$source = $image->getSrc();
$image->setSrc(self::secureEncode($basedir, $source));
}
/** @var $object \qtism\data\content\xhtml\Object */
foreach ($objects as $object) {
$data = $object->getData();
$object->setData(self::secureEncode($basedir, $data));
}
// save the document to a tempfile
$newXml = tempnam(sys_get_temp_dir(), 'sharedStimulus_') . '.xml';
$xmlDocument->save($newXml);
return $newXml;
}
示例7: testWriteInteractionMixSachsen
public function testWriteInteractionMixSachsen()
{
$doc = new XmlDocument('2.1');
$doc->load(self::decorateUri('interaction_mix_sachsen/interaction_mix_sachsen.xml'), true);
$file = tempnam('/tmp', 'qsm');
$doc->save($file);
$this->assertTrue(file_exists($file));
$doc = new XmlDocument('2.1');
$doc->load($file);
$this->testLoadInteractionMixSachsen($doc);
// correctly namespaced ?
$dom = $doc->getDomDocument();
$assessmentTestElt = $dom->documentElement;
$this->assertEquals('assessmentTest', $assessmentTestElt->nodeName);
$this->assertEquals('http://www.imsglobal.org/xsd/imsqti_v2p1', $assessmentTestElt->namespaceURI);
// childrend in namespace ?
$outcomeDeclarationElts = $dom->documentElement->getElementsByTagName('outcomeDeclaration');
$this->assertEquals(2, $outcomeDeclarationElts->length);
$outcomeDeclarationElt = $outcomeDeclarationElts->item(0);
$this->assertEquals('http://www.imsglobal.org/xsd/imsqti_v2p1', $outcomeDeclarationElt->namespaceURI);
unlink($file);
$this->assertFalse(file_exists($file));
}
示例8: beforeSave
public function beforeSave(QtiComponent $documentComponent, $uri)
{
// Take care of rubricBlock explosion. Transform
// actual rubricBlocks in rubricBlockRefs.
if ($this->mustExplodeRubricBlocks() === true) {
// Get all rubricBlock elements...
$iterator = new QtiComponentIterator($documentComponent, array('rubricBlock'));
$sectionCount = new SplObjectStorage();
foreach ($iterator as $rubricBlock) {
// $section contains the assessmentSection the rubricBlock is related to.
$section = $iterator->parent();
// determine the occurence number of the rubricBlock relative to its section.
if (isset($sectionCount[$section]) === false) {
$sectionCount[$section] = 0;
}
$sectionCount[$section] = $sectionCount[$section] + 1;
$occurence = $sectionCount[$section];
// determine a suitable file name for the external rubricBlock definition.
$rubricBlockRefId = 'RB_' . $section->getIdentifier() . '_' . $occurence;
$href = './rubricBlock_' . $rubricBlockRefId . '.xml';
$doc = new XmlDocument();
$doc->setDocumentComponent($rubricBlock);
try {
$pathinfo = pathinfo($uri);
$doc->save($pathinfo['dirname'] . DIRECTORY_SEPARATOR . $href);
// replace the rubric block with a reference.
$sectionRubricBlocks = $section->getRubricBlocks();
$sectionRubricBlocks->remove($rubricBlock);
$sectionRubricBlockRefs = $section->getRubricBlockRefs();
$sectionRubricBlockRefs[] = new RubricBlockRef($rubricBlockRefId, $href);
} catch (XmlStorageException $e) {
$msg = "An error occured while creating external rubrickBlock definition(s).";
throw new XmlStorageException($msg, $e);
}
}
}
}
示例9: testWriteNestedLax
public function testWriteNestedLax()
{
$doc = new XmlDocument();
$doc->load(self::samplesDir() . 'custom/operators/custom_operator_nested_1.xml');
$file = tempnam('/tmp', 'qsm');
$doc->save($file);
$this->testReadNestedLax($file);
//unlink($file);
}
示例10: beforeSave
/**
* @see \qtism\data\storage\xml\XmlDocument::beforeSave()
*/
public function beforeSave(QtiComponent $documentComponent, $uri)
{
// Take care of rubricBlock explosion. Transform actual rubricBlocks in rubricBlockRefs.
if ($this->mustExplodeRubricBlocks() === true) {
// Get all rubricBlock elements...
$iterator = new QtiComponentIterator($documentComponent, array('rubricBlock'));
$sectionCount = new SplObjectStorage();
foreach ($iterator as $rubricBlock) {
// $section contains the assessmentSection the rubricBlock is related to.
$section = $iterator->parent();
// determine the occurence number of the rubricBlock relative to its section.
if (isset($sectionCount[$section]) === false) {
$sectionCount[$section] = 0;
}
$sectionCount[$section] = $sectionCount[$section] + 1;
$occurence = $sectionCount[$section];
// determine a suitable file name for the external rubricBlock definition.
$rubricBlockRefId = 'RB_' . $section->getIdentifier() . '_' . $occurence;
$href = './rubricBlock_' . $rubricBlockRefId . '.xml';
$doc = new XmlDocument();
$doc->setDocumentComponent($rubricBlock);
try {
$pathinfo = pathinfo($uri);
$doc->save($pathinfo['dirname'] . DIRECTORY_SEPARATOR . $href);
// replace the rubric block with a reference.
$sectionRubricBlocks = $section->getRubricBlocks();
$sectionRubricBlocks->remove($rubricBlock);
$sectionRubricBlockRefs = $section->getRubricBlockRefs();
$sectionRubricBlockRefs[] = new RubricBlockRef($rubricBlockRefId, $href);
} catch (XmlStorageException $e) {
$msg = "An error occured while creating external rubrickBlock definition(s).";
throw new XmlStorageException($msg, XmlStorageException::UNKNOWN, $e);
}
}
}
// Take care of testFeedback explosion. Transform actual testFeedbacks in testFeedbackRefs.
if ($this->mustExplodeTestFeedbacks() === true) {
$iterator = new QtiComponentIterator($documentComponent, array('testFeedback'));
$testPartCount = new SplObjectStorage();
$testCount = 0;
foreach ($iterator as $testFeedback) {
$parent = $iterator->parent();
if ($parent instanceof TestPart) {
if (isset($testPartCount[$parent]) === false) {
$testPartCount[$parent] = 0;
}
$testPartCount[$parent] = $testPartCount[$parent] + 1;
$occurence = $testPartCount[$parent];
} else {
// It's a testFeedback related to an assessmentTest.
$testCount += 1;
$occurence = $testCount;
}
$parentId = $parent->getIdentifier();
$href = "./testFeedback_TF_{$parentId}_{$occurence}.xml";
// Generate the document.
$doc = new XmlDocument();
$doc->setDocumentComponent($testFeedback);
try {
$pathinfo = pathinfo($uri);
$doc->save($pathinfo['dirname'] . DIRECTORY_SEPARATOR . $href);
$parent->getTestFeedbacks()->remove($testFeedback);
$testFeedbackRefs = $parent->getTestFeedbackRefs();
$testFeedbackRefs[] = new TestFeedbackRef($testFeedback->getIdentifier(), $testFeedback->getOutcomeIdentifier(), $testFeedback->getAccess(), $testFeedback->getShowHide(), $href);
} catch (XmlStorageException $e) {
$msg = "An error occured while creating external testFeedback definition(s).";
throw new XmlStorageException($msg, XmlStorageException::UNKNOWN, $e);
}
}
}
}
示例11: testSaveUnknownLocation
public function testSaveUnknownLocation()
{
$doc = new XmlDocument('2.1.1');
$doc->loadFromString('<assessmentItemRef identifier="Q01" href="./Q01.xml"/>');
$expectedMsg = "An error occured while saving QTI-XML file at '/unknown/location/qti.xml'. Maybe the save location is not reachable?";
$this->setExpectedException('\\qtism\\data\\storage\\xml\\XmlStorageException', $expectedMsg, XmlStorageException::WRITE);
$doc->save('/unknown/location/qti.xml');
}