فهرست منبع

updated TestPerms refs to default_objects; added support for more comparison signs in SqlQueryWhereBuilder

Piotr Labudda 9 سال پیش
والد
کامیت
b2cce1f291

+ 9 - 0
SE/se-lib/Schema/AccessGroupReadStorageAcl.php

@@ -0,0 +1,9 @@
+<?php
+
+Lib::loadClass('Schema_AccessGroupStorageAcl');
+
+class Schema_AccessGroupReadStorageAcl extends Schema_AccessGroupStorageAcl {
+
+  public function getName() { return 'AccessGroupRead'; }
+
+}

+ 38 - 0
SE/se-lib/Schema/AccessGroupStorageAcl.php

@@ -4,6 +4,7 @@ Lib::loadClass('Core_AclBase');
 Lib::loadClass('User');
 Lib::loadClass('UsersHelper');
 Lib::loadClass('ParseOgcFilter');
+Lib::loadClass('SqlQueryWhereBuilder');
 
 class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
 
@@ -41,6 +42,7 @@ class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
   }
   public function getItems($params = array()) {
     $DBG = V::get('DBG_DS', 0, $_GET, 'int');
+    if($DBG>2){echo'<pre>';}
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
     $items = array();
     // TODO: fetch groups connectes with current user
@@ -77,6 +79,42 @@ class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
       if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
       $items = array_filter($items, array($queryWhereBuilder, 'filterRawArray'));
     }
+    $filterId = trim(V::get('f_id', '', $params));
+    if (strlen($filterId)) {// allow '0'
+      $queryWhereBuilder = new SqlQueryWhereBuilder();
+      if (is_numeric($filterId)) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', '=', $filterId);
+      } else if (false !== strpos($filterId, '%') && is_numeric(trim($filterId, '%'))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', 'like', $filterId);
+      } else if ('>=' == substr($filterId, 0, 2) && is_numeric(substr($filterId, 2))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', 'GreaterThenOrEqualTo', substr($filterId, 2));
+      } else if ('<=' == substr($filterId, 0, 2) && is_numeric(substr($filterId, 2))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', 'LessThenOrEqualTo', substr($filterId, 2));
+      } else if ('>' == substr($filterId, 0, 1) && is_numeric(substr($filterId, 1))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', 'GreaterThen', substr($filterId, 1));
+      } else if ('<' == substr($filterId, 0, 1) && is_numeric(substr($filterId, 1))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', 'LessThen', substr($filterId, 1));
+      } else {
+        $filterId = null;// TODO: BUG uniimplemented comparison sign
+      }
+      if ($filterId) $items = array_filter($items, array($queryWhereBuilder, 'filterRawArray'));
+    }
+
+    foreach (['name', 'uid'] as $fieldName) {
+      $filterValue = trim(V::get("f_{$fieldName}", '', $params));
+      if (strlen($filterValue)) {// allow '0'
+        $queryWhereBuilder = new SqlQueryWhereBuilder();
+        if (!is_scalar($filterValue)) {
+        } else if ('=' == substr($filterValue, 0, 1)) {
+          $queryWhereBuilder->addComparisonFieldToValue($fieldName, '=', substr($filterValue, 1));
+        } else {
+          if ('%' != substr($filterValue, 0, 1)) $filterValue = "%{$filterValue}";
+          if ('%' != substr($filterValue, -1)) $filterValue = "{$filterValue}%";
+          $queryWhereBuilder->addComparisonFieldToValue($fieldName, 'like', $filterValue);
+        }
+        $items = array_filter($items, array($queryWhereBuilder, 'filterRawArray'));
+      }
+    }
 
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
     return $items;

+ 9 - 0
SE/se-lib/Schema/AccessGroupWriteStorageAcl.php

@@ -0,0 +1,9 @@
+<?php
+
+Lib::loadClass('Schema_AccessGroupStorageAcl');
+
+class Schema_AccessGroupWriteStorageAcl extends Schema_AccessGroupStorageAcl {
+
+  public function getName() { return 'AccessGroupWrite'; }
+
+}

+ 3 - 3
SE/se-lib/Schema/TestPermsStorageAcl.php

@@ -159,9 +159,9 @@ class Schema_TestPermsStorageAcl extends Core_AclBase {
     // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File';
     // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File';
     // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
-    if ('AccessGroupRead' == $fieldName) return 'alias_ref:p5_objects:AccessGroup';
-    if ('AccessGroupWrite' == $fieldName) return 'alias_ref:p5_objects:AccessGroup';
-    if ('AccessOwner' == $fieldName) return 'ref:p5_objects:AccessOwner';
+    if ('AccessGroupRead' == $fieldName) return 'ref:default_objects:AccessGroupRead';
+    if ('AccessGroupWrite' == $fieldName) return 'ref:default_objects:AccessGroupWrite';
+    if ('AccessOwner' == $fieldName) return 'ref:default_objects:AccessOwner';
     return $this->parentAcl->getXsdFieldType($fieldName);
   }
   public function isGeomField($fldName) {

+ 31 - 9
SE/se-lib/SqlQueryWhereBuilder.php

@@ -145,24 +145,46 @@ class SqlQueryWhereBuilder {
 					break;
 				default: {
 					if (is_array($log) && 4 == count($log) && 'comparisonFieldToValue' == $log[0]) {
-						$fieldName = strtolower($log[1]);
+						list($logType, $fieldName, $compSign, $compValue) = $log;
+						$fieldName = strtolower($fieldName);
 						if (!array_key_exists($fieldName, $lowerItem)) throw new Exception("field '{$fieldName}' not defined");
-						switch ($log[2]) {
+						$fieldValue = $lowerItem[$fieldName];
+						switch ($compSign) {
 							case '=': {
-								$sqlFromStack = ($lowerItem[$fieldName] == $log[3]);
-								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$log[0]}' comparison({$lowerItem[$fieldName]} == {$log[3]}) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								$sqlFromStack = ($fieldValue == $compValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison({$fieldValue} == {$compValue}) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
 								break;
 							}
 							case 'like': {
-								$pattern = str_replace('%', '(.*)', $log[3]);
-								$sqlFromStack = (bool)preg_match("/^{$pattern}\$/i", $lowerItem[$fieldName]);
-								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$log[0]}' comparison(preg_match('/^{$pattern}\$/i', '{$lowerItem[$fieldName]}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								$pattern = str_replace('%', '(.*)', $compValue);
+								$sqlFromStack = (bool)preg_match("/^{$pattern}\$/i", $fieldValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison(preg_match('/^{$pattern}\$/i', '{$fieldValue}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
 								break;
 							}
-							default: throw new Exception("compaison sign '{$log[2]}' not defined");
+							case '>=': {
+								$sqlFromStack = (bool)($fieldValue >= $compValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison({$compValue} {$compSign} '{$fieldValue}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								break;
+							}
+							case '<=': {
+								$sqlFromStack = (bool)($fieldValue <= $compValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison({$compValue} {$compSign} '{$fieldValue}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								break;
+							}
+							case '>': {
+								$sqlFromStack = (bool)($fieldValue > $compValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison({$compValue} {$compSign} '{$fieldValue}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								break;
+							}
+							case '<': {
+								$sqlFromStack = (bool)($fieldValue < $compValue);
+								DBG::_('DBG_DS_OGC', '>2', "\nlog loop({$idxLog}) '{$logType}' comparison({$compValue} {$compSign} '{$fieldValue}')) \$sqlFromStack(".($sqlFromStack ? 'true' : 'false').")", null, __CLASS__, __FUNCTION__, __LINE__);
+								break;
+							}
+							default: throw new Exception("compaison sign '{$compSign}' not defined");
 						}
 						// $this->_usedFields[$sqlFieldName] = true;
-						// $sqlFromStack = "{tablePrefix}`{$sqlFieldName}` {$log[2]} '{$log[3]}'";
+						// $sqlFromStack = "{tablePrefix}`{$sqlFieldName}` {$compSign} '{$compValue}'";
 						$stackValue = array_pop($sqlValuesStack);
 						if (!is_array($stackValue)) throw new Exception("parse sql query failed - stack value is not array");
 						array_push($stackValue, $sqlFromStack);