Explorar o código

added getCapabilities outputFormat=csv

Piotr Labudda %!s(int64=8) %!d(string=hai) anos
pai
achega
1fddf3bf80

+ 57 - 0
SE/se-lib/Api/Wfs/GetCapabilities.php

@@ -9,6 +9,63 @@ Lib::loadClass('Core_XmlWriter');
 
 
 class Api_Wfs_GetCapabilities {
 class Api_Wfs_GetCapabilities {
 
 
+	public function getCapabilitiesCsv($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList) {
+		header('Content-Type: text/csv; charset=utf-8');
+		$csvLineSepartor = "\n";
+		$csvValueSepartor = ",";
+		$csvText = function ($value) {
+			return '"' . str_replace(['"'], ['\"'], $value) . '"';
+		};
+
+		echo implode(",", [
+			"Name",
+			"Title",
+			"namespace url",
+			"Keywords",
+			"Abstract",
+			"SRS",
+			"LatLongBoundingBox - minx",
+			"LatLongBoundingBox - miny",
+			"LatLongBoundingBox - maxx",
+			"LatLongBoundingBox - maxy",
+		]);
+		echo $csvLineSepartor;
+
+		echo implode($csvLineSepartor, array_map(function ($acl) use ($csvText, $csvValueSepartor) {
+			$ns = Core_AclHelper::parseNamespaceUrl($acl->getNamespace());
+			return implode($csvValueSepartor, [
+				"p5_{$ns['prefix']}:{$ns['name']}", // Name
+				$csvText($acl->getRawLabel()), // Title
+				Api_WfsNs::getNsUri($ns['prefix']), // namespace url
+				$csvText(implode(', ', [ $acl->getID(), $acl->getName(), $acl->getRawLabel() ])), // Keywords
+				$csvText($acl->getRawOpis()), // Abstract
+				'EPSG:4326', // SRS
+				"8.12328509871721", // LatLongBoundingBox - minx
+				"38.8575126897477", // LatLongBoundingBox - miny
+				"9.838674658246807", // LatLongBoundingBox - maxx
+				"41.31378404137082", // LatLongBoundingBox - maxy
+			]);
+		}, $aclList));
+		echo $csvLineSepartor;
+
+		echo implode($csvLineSepartor, array_map(function ($typeName) use ($csvText, $csvValueSepartor) {
+			list($prefix, $name) = explode(':', $typeName);
+			return implode($csvValueSepartor, [
+				"p5_{$prefix}:{$name}", // Name
+				$csvText($name), // Title
+				Api_WfsNs::getNsUri($prefix), // namespace url
+				$csvText($name), // Keywords
+				$csvText($name), // Abstract
+				'EPSG:4326', // SRS
+				"8.12328509871721", // LatLongBoundingBox - minx
+				"38.8575126897477", // LatLongBoundingBox - miny
+				"9.838674658246807", // LatLongBoundingBox - maxx
+				"41.31378404137082", // LatLongBoundingBox - maxy
+			]);
+		}, Core_AclHelper::getCustomAclList()));
+		exit;
+	}
+
 	public function getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList) {
 	public function getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList) {
 		// if (V::get('DBG_ACL', '', $_GET)) {
 		// if (V::get('DBG_ACL', '', $_GET)) {
 		// 	{
 		// 	{

+ 10 - 3
SE/se-lib/Api/WfsDataServer.php

@@ -457,9 +457,16 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 			return ($idDefaultDB == $acl->getDB()); // hide non default_db tables
 			return ($idDefaultDB == $acl->getDB()); // hide non default_db tables
 		});
 		});
 
 
-		//header('Content-type: application/xml; charset="utf-8"');
-		header('Content-type: application/xml');
-		(new Api_Wfs_GetCapabilities)->getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+		switch (V::get('outputFormat', 'xml', $_GET)) {
+			case 'csv': {
+				(new Api_Wfs_GetCapabilities)->getCapabilitiesCsv($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+			} break;
+			case 'xml': {
+				(new Api_Wfs_GetCapabilities)->getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+			} break;
+			default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
+		}
+		exit;
 	}
 	}
 
 
 }
 }

+ 9 - 2
SE/se-lib/Api/WfsQgisServer.php

@@ -223,8 +223,15 @@ if($DBG){echo '(geomFld: '.$geomFld.'):';print_r($acl->getFieldType($geomFld));e
 			return ($idDefaultDB == $acl->getDB()); // hide non default_db tables
 			return ($idDefaultDB == $acl->getDB()); // hide non default_db tables
 		});
 		});
 
 
-		header('Content-type: application/xml');
-		(new Api_Wfs_GetCapabilities)->getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+		switch (V::get('outputFormat', 'xml', $_GET)) {
+			case 'csv': {
+				(new Api_Wfs_GetCapabilities)->getCapabilitiesCsv($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+			} break;
+			case 'xml': {
+				(new Api_Wfs_GetCapabilities)->getCapabilitiesXml($wfsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+			} break;
+			default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
+		}
 		exit;
 		exit;
 	}
 	}