Преглед на файлове

updated example for fetchWfs inside xsl

Piotr Labudda преди 8 години
родител
ревизия
b5c4c4d48c
променени са 2 файла, в които са добавени 19 реда и са изтрити 4 реда
  1. 7 3
      SE/se-lib/Route/Test/XslRecurse.php
  2. 12 1
      SE/se-lib/xsl-functions/testFetchWfs.php

+ 7 - 3
SE/se-lib/Route/Test/XslRecurse.php

@@ -15,8 +15,11 @@ class Route_Test_XslRecurse extends RouteBase {
 			 <item typeName=\"default_db:TEST_PERMS\">
 			  <featureId>TEST_PERMS.1</featureId>
 			 </item>
-			 <item typeName=\"default_db__x3A__TEST_PERMS:TestPermAnt\">
-			  <featureId>TestPermAnt.1</featureId>
+			 <item typeName=\"default_db:TEST_PERMS\">
+			  <featureId>TEST_PERMS.99999</featureId>
+			 </item>
+			 <item typeName=\"default_db__x3A__TEST_PERMS:TestPermsAnt\">
+			  <featureId>TestPermsAnt.1</featureId>
 			 </item>
 			</root>
 		";
@@ -40,7 +43,7 @@ class Route_Test_XslRecurse extends RouteBase {
 			      <tr>
 							<td><xsl:value-of select="featureId"/></td>
 							<td><pre>
-				        <xsl:copy-of select="php:function(\'testFetchWfs\',@typeName, string(featureId))/node()"/>
+				        <xsl:copy-of select="php:function(\'testFetchWfs\', string(@typeName), string(featureId))/node()"/>
 				      </pre></td>
 						</tr>
 			    </xsl:for-each>
@@ -63,6 +66,7 @@ class Route_Test_XslRecurse extends RouteBase {
 		$proc->importStyleSheet($xsldoc);
 		$transformed = $proc->transformToXML($xmldoc);
 		DBG::nicePrint(htmlspecialchars($xml), 'xml');
+		DBG::nicePrint(htmlspecialchars($xsl), 'xsl');
 		DBG::nicePrint(htmlspecialchars($transformed), 'xml transformed');
 		echo "\n".'<hr>';
 		echo $transformed;

+ 12 - 1
SE/se-lib/xsl-functions/testFetchWfs.php

@@ -4,7 +4,18 @@ function testFetchWfs($typeName, $featureId) {
 	DBG::log([$typeName, $featureId], 'array', "TODO: testFetchWfs");
 	$dom = new DOMDocument();
 	$tmp = $dom->createDocumentFragment();
-	$tmp->appendXML(' <b> foo <i val="123"> bar</i> </b> TEST');
+
+	try {
+		$acl = ACL::getAclByTypeName($typeName);
+		$pk = substr($featureId, strpos($featureId, '.') + 1);
+		$item = $acl->buildQuery([])->getItem($pk);
+		if (!$item) throw new Exception("Object with primary key = '{$pk}' not found");
+		foreach ($item as $fieldName => $value) {
+			$tmp->appendXML('<p>' . $fieldName .': "' . $value . '"</p>');
+		}
+	} catch (Exception $e) {
+		$tmp->appendXML('<div class="alert alert-danger">' . $e->getMessage() . '</div>');
+	}
 
 	return $tmp; // TODO: require <xsl:copy-of select="php:function(...)/node() - @see https://en.wikibooks.org/wiki/PHP_Programming/XSL/registerPHPFunctions#XSL_receiving_external_fragments
 	// return $dom->saveXML($tmp);