Piotr Labudda пре 11 година
родитељ
комит
a83136016d
1 измењених фајлова са 130 додато и 74 уклоњено
  1. 130 74
      SE/superedit-OPEN_LAYERS_WPS.php

+ 130 - 74
SE/superedit-OPEN_LAYERS_WPS.php

@@ -625,31 +625,85 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 }
 
 
+class WpsActionBase {
+
+	public $title = '';
+	public $description = '';
+	public $dataInputs = array();
+
+	public function execute($args) {
+		var_dump($args);
+	}
+
+}
+
+class WpsActionPrzypiszDoRekordu extends WpsActionBase {
+
+	public function __construct() {
+		$this->title = 'Przypisz';
+		$this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
+
+		$this->dataInputs['geom'] = new stdClass();
+		$this->dataInputs['geom']->title = 'geom';
+		$this->dataInputs['geom']->description = 'Input geometry';
+		$this->dataInputs['geom']->type = 'geom';// CoomplexData
+
+		$this->dataInputs['idTable'] = new stdClass();
+		$this->dataInputs['idTable']->title = 'geom';
+		$this->dataInputs['idTable']->description = 'Table ID';
+		$this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
+
+		$this->dataInputs['idRecord'] = new stdClass();
+		$this->dataInputs['idRecord']->title = 'idRecord';
+		$this->dataInputs['idRecord']->description = 'Record ID';
+		$this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
+	}
+
+}
+
 class WpsServer {
-	
+
+	private $_fun;// config for identifiers
+
+	public function __construct() {
+		$this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
+	}
+
 	public function parseXMLRequest() {
-		$entityBody = file_get_contents('php://input');
-		$table = array();
-		$content = $entityBody;
-		$identifier = new SimpleXMLElement($content);
-		if(isset($identifier->children('ows', TRUE)->Identifier)) {
-			$funcName = ($identifier->children('ows', TRUE)->Identifier);
-			print_r($funcName);
-	
-			if ($content != FALSE) {
-				$xml = new SimpleXmlElement($content);
-				foreach($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
-					if(isset($input->children('wps', TRUE)->Data->ComplexData)) {
-						$table[] = $input->children('wps', TRUE)->Data->ComplexData;
-					} else if(isset($input->children('wps', TRUE)->Data->LiteralData)) {
-						$table[] = $input->children('wps', TRUE)->Data->LiteralData;
+		$data = array();
+		$reqContent = file_get_contents('php://input');
+		$xml = new SimpleXMLElement($reqContent);
+		if (isset($xml->children('ows', TRUE)->Identifier)) {
+			$identifier = (string)$xml->children('ows', TRUE)->Identifier;
+			if (array_key_exists($identifier, $this->_fun)) {
+
+				foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
+					$inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
+					if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
+						$inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
+						switch ($inputType) {
+							case 'integer':
+								$data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
+								break;
+							case 'geom':
+								$data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
+								break;
+							default:
+								
+						}
+					} else {
+						// brak zdefiniowanego inputa
 					}
 				}
-				foreach($table as $value) {
-					echo($value);
-				}
-				}
+
+				$this->_fun['przypiszDoRekordu']->execute($data);
+
+			} else {
+				echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
+				var_dump($identifier);
+				return;
 			}
+		}
 	}
 
 	public function getCapabilitiesAction() {
@@ -700,11 +754,13 @@ class WpsServer {
         </ows:Operation>
     </ows:OperationsMetadata>
     <wps:ProcessOfferings>
+			<?php foreach($this->_fun as $kFun => $vFun) : ?>
         <wps:Process wps:processVersion="1.0.0">
-            <ows:Identifier>przypiszDoRekordu</ows:Identifier>
-            <ows:Title>Przypisz</ows:Title>
-            <ows:Abstract>Przypisuje położenie do wybranego rekordu w tabeli.</ows:Abstract>
+            <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
+            <ows:Title><?php echo $vFun->title; ?></ows:Title>
+            <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
         </wps:Process>
+			<?php endforeach; ?>
     </wps:ProcessOfferings>
     <wps:Languages>
         <wps:Default>
@@ -727,60 +783,56 @@ class WpsServer {
 		 * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
 		 */
 		echo '<?xml version="1.0" encoding="UTF-8"?>';
+
+		if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
+			$identifier = $this->_fun[$args['IDENTIFIER']];
 		?>
 <wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
   <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
-    <ows:Identifier>przypiszDoRekordu</ows:Identifier>
-    <ows:Title>Przypisz</ows:Title>
-    <ows:Abstract>Przypisuje położenie do wybranego rekordu w tabeli.</ows:Abstract>
+    <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
+    <ows:Title><?php echo $identifier->title; ?></ows:Title>
+    <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
     <DataInputs>
-      <Input maxOccurs="1" minOccurs="1">
-        <ows:Identifier>geom</ows:Identifier>
-        <ows:Title>geom</ows:Title>
-        <ows:Abstract>Input geometry</ows:Abstract>
-        <ComplexData>
-          <Default>
-            <Format>
-              <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
-            </Format>
-          </Default>
-          <Supported>
-            <Format>
-              <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
-            </Format>
-            <Format>
-              <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
-            </Format>
-            <Format>
-              <MimeType>application/wkt</MimeType>
-            </Format>
-            <Format>
-              <MimeType>application/gml-3.1.1</MimeType>
-            </Format>
-            <Format>
-              <MimeType>application/gml-2.1.2</MimeType>
-            </Format>
-          </Supported>
-        </ComplexData>
-      </Input>
-      <Input maxOccurs="1" minOccurs="1">
-        <ows:Identifier>idTable</ows:Identifier>
-        <ows:Title>idTabele</ows:Title>
-        <ows:Abstract>The maximum segment length in the result, in the units of the geometry</ows:Abstract>
-        <LiteralData>
-          <ows:DataType>xs:integer</ows:DataType>
-          <ows:AnyValue />
-        </LiteralData>
-      </Input>
-        <Input maxOccurs="1" minOccurs="1">
-        <ows:Identifier>idObject</ows:Identifier>
-        <ows:Title>idObject</ows:Title>
-        <ows:Abstract>The maximum segment length in the result, in the units of the geometry</ows:Abstract>
-        <LiteralData>
-          <ows:DataType>xs:integer</ows:DataType>
-          <ows:AnyValue />
-        </LiteralData>
-      </Input>
+			<?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
+				<Input maxOccurs="1" minOccurs="1">
+					<ows:Identifier><?php echo $kInput; ?></ows:Identifier>
+					<ows:Title><?php echo $vInput->title; ?></ows:Title>
+					<ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
+					<?php if ($vInput->type == 'geom') : ?>
+						<ComplexData>
+							<Default>
+								<Format>
+									<MimeType>text/xml; subtype=gml/3.1.1</MimeType>
+								</Format>
+							</Default>
+							<Supported>
+								<Format>
+									<MimeType>text/xml; subtype=gml/3.1.1</MimeType>
+								</Format>
+								<Format>
+									<MimeType>text/xml; subtype=gml/2.1.2</MimeType>
+								</Format>
+								<Format>
+									<MimeType>application/wkt</MimeType>
+								</Format>
+								<Format>
+									<MimeType>application/gml-3.1.1</MimeType>
+								</Format>
+								<Format>
+									<MimeType>application/gml-2.1.2</MimeType>
+								</Format>
+							</Supported>
+						</ComplexData>
+					<?php elseif ($vInput->type == 'integer') : ?>
+						<LiteralData>
+							<ows:DataType>xs:integer</ows:DataType>
+							<ows:AnyValue />
+						</LiteralData>
+					<?php else : ?>
+
+					<?php endif; ?>
+				</Input>
+			<?php endforeach; ?>
     </DataInputs>
     <ProcessOutputs>
       <Output>
@@ -814,6 +866,10 @@ class WpsServer {
     </ProcessOutputs>
   </ProcessDescription>
 </wps:ProcessDescriptions>
-		<?php
+			<?php
+		} else {
+			echo 'TODO: brak funkcji';
+		}
 	}
+
 }