[Mapbender-commits] r6774 - trunk/mapbender/lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Aug 20 06:28:00 EDT 2010
Author: christoph
Date: 2010-08-20 10:28:00 +0000 (Fri, 20 Aug 2010)
New Revision: 6774
Modified:
trunk/mapbender/lib/class_Filter.php
Log:
empty filters
multiple filters with a single filter as argument
Modified: trunk/mapbender/lib/class_Filter.php
===================================================================
--- trunk/mapbender/lib/class_Filter.php 2010-08-20 07:20:45 UTC (rev 6773)
+++ trunk/mapbender/lib/class_Filter.php 2010-08-20 10:28:00 UTC (rev 6774)
@@ -32,7 +32,7 @@
$this->value = func_get_arg(2);
}
- if (func_num_args() === 2) {
+ else if (func_num_args() === 2) {
if (!in_array(func_get_arg(0), explode(",", Filter::BOOLEAN_OPERATORS))) {
throw new Exception ("Filter: Invalid boolean operator " . func_get_arg(0));
}
@@ -47,30 +47,11 @@
$this->filterArray = func_get_arg(1);
}
}
- }
-
- protected function isComplex () {
- if (in_array($this->booleanOperator, explode(",", Filter::BOOLEAN_OPERATORS)) &&
- is_array($this->filterArray)
- ) {
- foreach ($this->filterArray as $filter) {
- if (!is_a($filter, "Filter")) {
- throw new Exception("Filter: Not a valid filter.");
- return false;
- }
- }
- return true;
+ else {
+
}
- return false;
}
- private function getType ($v) {
- if (is_float($v) || is_integer($v)) {
- return "i";
- }
- return "s";
- }
-
public function toSql ($parameterCount = 1) {
$sqlObject = new stdClass();
$sqlObject->sql = "";
@@ -81,6 +62,10 @@
$i = $parameterCount;
foreach ($this->filterArray as $filter) {
$currentSqlObject = $filter->toSql($i);
+
+ if ($currentSqlObject->sql === "") {
+ continue;
+ }
$currentBooleanOperator = ($i === $parameterCount) ?
"" : " " . $this->booleanOperator . " ";
$sqlObject->sql .= $currentBooleanOperator .
@@ -109,12 +94,55 @@
}
}
else {
- $sqlObject->sql = $this->key . $this->operator . "$" . $parameterCount;
- $sqlObject->v = array($this->value);
- $sqlObject->t = array($this->getType($this->value));
+ $sqlObject->sql = !is_null($this->key) && !is_null($this->operator) ?
+ $this->key . $this->operator . "$" . $parameterCount : "";
+ $sqlObject->v = !is_null($this->value) ? array($this->value) : array();
+ $sqlObject->t = !is_null($this->value) ? array($this->getType($this->value)) : array();
}
return $sqlObject;
}
}
+
+ public static function merge ($booleanOperator, $filterArray) {
+ if (!in_array($booleanOperator, explode(",", Filter::BOOLEAN_OPERATORS))) {
+ throw new Exception ("Filter: Invalid boolean operator " . $booleanOperator);
+ }
+
+ $validFilterArray = array();
+ if (is_array($filterArray)) {
+ foreach ($filterArray as $filter) {
+ if (!is_a($filter, "Filter")) {
+ continue;
+ }
+ $validFilterArray[]= $filter;
+ }
+ }
+ return count($validFilterArray) > 0 ?
+ count($validFilterArray) === 1 ? $validFilterArray[0] : new Filter($booleanOperator, $validFilterArray)
+ : null;
+ }
+
+ protected function isComplex () {
+ if (in_array($this->booleanOperator, explode(",", Filter::BOOLEAN_OPERATORS)) &&
+ is_array($this->filterArray)
+ ) {
+ foreach ($this->filterArray as $filter) {
+ if (!is_a($filter, "Filter")) {
+ throw new Exception("Filter: Not a valid filter.");
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private function getType ($v) {
+ if (is_float($v) || is_integer($v)) {
+ return "i";
+ }
+ return "s";
+ }
+
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list