ソースを参照

added support to ogc:Not in ogc:Filter

Piotr Labudda 10 年 前
コミット
e3c890b0c1

+ 10 - 0
SE/schema/wfs/convertOgcFilterToXmlTaskList.xsl

@@ -43,6 +43,16 @@
 		</xsl:element>
 	</xsl:template>
 
+	<xsl:template match="ogc:Not">
+		<xsl:element name="sql_filter_openBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'not'" /></xsl:attribute>
+		</xsl:element>
+		<xsl:apply-templates/>
+		<xsl:element name="sql_filter_closeBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'not'" /></xsl:attribute>
+		</xsl:element>
+	</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>

+ 22 - 2
SE/se-lib/SqlQueryWhereBuilder.php

@@ -45,7 +45,8 @@ class SqlQueryWhereBuilder {
 		foreach ($this->_log as $log) {
 			switch ($log) {
 				case 'open_block_and':
-				case 'open_block_or': {
+				case 'open_block_or':
+				case 'open_block_not': {
 					$blockType = substr($log, 11);
 					array_push($sqlBlocksStack, $blockType);
 					$arr = array(); array_push($sqlValuesStack, $arr);
@@ -71,6 +72,25 @@ class SqlQueryWhereBuilder {
 					array_push($sqlValuesStack, $parentStackValue);
 				}
 					break;
+				case 'close_block_not': {
+					$blockType = substr($log, 12);
+					if (empty($sqlBlocksStack)) throw new Exception("parse sql query failed - blocks stack is empty");
+					$stackBlockType = array_pop($sqlBlocksStack);
+					if ($blockType != $stackBlockType) throw new Exception("parse sql query failed - expected stop '{$blockType}', given '{$stackBlockType}'");
+
+					// parse to string and add to parent value stack
+					$stackValue = array_pop($sqlValuesStack);
+					if (!is_array($stackValue)) throw new Exception("parse sql query failed - stack value is not array");
+					if (empty($stackValue)) throw new Exception("parse sql query failed - stack value is empty");
+					if (1 != count($stackValue)) throw new Exception("parse sql query failed - stack value count is not equal to 1");
+					$stackValue = reset($stackValue);
+					$sqlFromStack = " ! ({$stackValue}) ";
+					$parentStackValue = array_pop($sqlValuesStack);
+					if (!is_array($parentStackValue)) throw new Exception("parse sql query failed - parent stack value is not array");
+					array_push($parentStackValue, $sqlFromStack);
+					array_push($sqlValuesStack, $parentStackValue);
+				}
+					break;
 				default: {
 					if (is_array($log) && 4 == count($log) && 'comparisonFieldToValue' == $log[0]) {
 						$sqlFieldName = $log[1];
@@ -105,7 +125,7 @@ class SqlQueryWhereBuilder {
 		if ('and' == $blockType || 'or' == $blockType) {
 			return true;
 		} else if ('not' == $blockType) {
-			return false;// TODO: allow not operator: expect only one children, if more -> use only last
+			return true;
 		}
 		return false;
 	}