Bläddra i källkod

added support for ogc:Function in ogc:Filter

Piotr Labudda 10 år sedan
förälder
incheckning
bd14a8d0ee

+ 25 - 5
SE/schema/wfs/convertOgcFilterToXmlTaskList.xsl

@@ -54,11 +54,31 @@
 	</xsl:template>
 
 	<xsl:template match="ogc:PropertyIsEqualTo">
-		<xsl:element name="sql_filter_comparisonFieldToValue">
-			<xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
-			<xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
-			<xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
-		</xsl:element>
+<!--
+		<ogc:PropertyIsEqualTo>
+			<ogc:Function name="GeometryType">
+				 <ogc:PropertyName>{$geomFld}</ogc:PropertyName>
+			</ogc:Function>
+			<ogc:Literal>{$geomType}</ogc:Literal>
+		</ogc:PropertyIsEqualTo>
+-->
+		<xsl:choose>
+			<xsl:when test="./ogc:Function/ogc:PropertyName">
+				<xsl:element name="sql_filter_comparisonFieldToValue">
+					<xsl:attribute name="fieldFunction"><xsl:value-of select="ogc:Function/@name" /></xsl:attribute>
+					<xsl:attribute name="fieldName"><xsl:value-of select="ogc:Function/ogc:PropertyName" /></xsl:attribute>
+					<xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
+					<xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
+				</xsl:element>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:element name="sql_filter_comparisonFieldToValue">
+					<xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
+					<xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
+					<xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
+				</xsl:element>
+			</xsl:otherwise>
+		</xsl:choose>
 	</xsl:template>
 
 	<xsl:template match="ogc:PropertyIsLike">

+ 6 - 1
SE/se-lib/ParseOgcFilter.php

@@ -55,6 +55,7 @@ OGC_FILTER_XML_FILE;
 					break;
 				case 'sql_filter_comparisonFieldToValue': {
 					$fieldName = V::get('fieldName', '', $tag['attributes']);
+					$fieldFunction = V::get('fieldFunction', null, $tag['attributes']);
 					$comparisonSign = V::get('comparisonSign', '', $tag['attributes']);
 					$value = V::get('value', '', $tag['attributes']);
 					DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue comparisonSign", $comparisonSign, __CLASS__, __FUNCTION__, __LINE__);
@@ -101,7 +102,11 @@ OGC_FILTER_XML_FILE;
 						}
 					}
 					DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue value({$value})", null, __CLASS__, __FUNCTION__, __LINE__);
-					$queryWhereBuilder->addComparisonFieldToValue($fieldName, $comparisonSign, $value);
+					if ($fieldFunction) {
+						$queryWhereBuilder->addComparisonFieldFunToValue($fieldFunction, $fieldName, $comparisonSign, $value);
+					} else {
+						$queryWhereBuilder->addComparisonFieldToValue($fieldName, $comparisonSign, $value);
+					}
 				}
 					break;
 				case 'sql_filter_comparisonFieldIsNull': {

+ 20 - 0
SE/se-lib/SqlQueryWhereBuilder.php

@@ -29,6 +29,16 @@ class SqlQueryWhereBuilder {
 		$this->_log[] = array('comparisonFieldToValue', $fieldName, $sqlCompSign, $value);
 	}
 
+	public function addComparisonFieldFunToValue($fieldFun, $fieldName, $comparisonSign, $value) {
+		$sqlCompSign = "";
+		switch ($comparisonSign) {
+			case '=': $sqlCompSign = '='; break;
+			case 'like': $sqlCompSign = 'like'; break;
+			default: throw new Exception("Unsupported comparison sign");
+		}
+		$this->_log[] = array('comparisonFieldFunToValue', $fieldFun, $fieldName, $sqlCompSign, $value);
+	}
+
 	public function sql_filter_comparisonFieldIsNull($fieldName) {
 		$this->_log[] = array('comparisonFieldIsNull', $fieldName);
 	}
@@ -106,6 +116,16 @@ class SqlQueryWhereBuilder {
 						array_push($sqlValuesStack, $stackValue);
 //echo "L.".__LINE__.":sqlBlocksStack:" . json_encode($sqlBlocksStack) . "\n";
 //echo "L.".__LINE__.":sqlValuesStack:" . json_encode($sqlValuesStack) . "\n\n";
+					} else if (is_array($log) && 5 == count($log) && 'comparisonFieldFunToValue' == $log[0]) {
+						$sqlFieldFunName = $log[1];
+						if (strtolower($sqlFieldFunName) != 'geometrytype') throw new Exception("Unsupported db function {$sqlFieldName}");
+						$sqlFieldName = $log[2];
+						$this->_usedFields[$sqlFieldName] = true;
+						$sqlFromStack = "{$sqlFieldFunName}({tablePrefix}`{$sqlFieldName}`) {$log[3]} '{$log[4]}'";
+						$stackValue = array_pop($sqlValuesStack);
+						if (!is_array($stackValue)) throw new Exception("parse sql query failed - stack value is not array");
+						array_push($stackValue, $sqlFromStack);
+						array_push($sqlValuesStack, $stackValue);
 					} else if (is_array($log) && 2 == count($log) && 'comparisonFieldIsNull' == $log[0]) {
 						$sqlFieldName = $log[1];
 						$sqlFromStack = "{tablePrefix}`{$sqlFieldName}` is null";