Sfoglia il codice sorgente

added arg $params to getItem

Piotr Labudda 9 anni fa
parent
commit
d205ea1c1d

+ 1 - 1
SE/se-lib/ApiDataSourceTodo.php

@@ -97,7 +97,7 @@ class ApiDataSourceTodo {
 		return $items;
 	}
 
-	public function getItem($id) {
+	public function getItem($id, $params = []) {
 		$items = array();
 		$db = $this->getConnection();
 		$fields = $this->getFields();

+ 1 - 1
SE/se-lib/Core/AclBase.php

@@ -187,7 +187,7 @@ class Core_AclBase {
 
   public function getItems($params = array()) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: use ParseOgcQuery
   public function getTotal($params = array()) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: use ParseOgcQuery
-  public function getItem($primaryKey) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function getItem($primaryKey, $params = []) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   public function addItem($todoItem) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   public function updateItem($itemPatch) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   public function getGeomFieldType($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }

+ 71 - 3
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -249,10 +249,26 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function canWriteObjectField($fieldName, $record) { return false; }// TODO: perms from Procesy
 
   public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
-  public function getItem($primaryKey) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
+  public function getItem($primaryKey, $params = []) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
   public function getItems($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
   public function fetchItemRef(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: , $fieldName = ''
-  public function fetchItemFieldRefs($primaryKey, $fieldName) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
+  public function fetchItemFieldRefs($primaryKey, $fieldName) {
+    $refTable = Core_AclHelper::getRefTable($this->getName(), $fieldName);
+    $sqlPk = DB::getPDO()->quote($primaryKey, PDO::PARAM_STR);
+    return array_map(
+      function ($row) {
+        return [
+          'xlink' => "{$row['REMOTE_TYPENAME']}.{$row['REMOTE_PRIMARY_KEY']}" // TODO:
+        ];
+      }
+      , DB::getPDO()->fetchAll("
+          select r.REMOTE_PRIMARY_KEY, r.REMOTE_TYPENAME
+            from `{$refTable}` r
+          where r.PRIMARY_KEY = {$sqlPk}
+            and r.A_STATUS != 'DELETED'
+        ")
+    );
+  }
   public function addItem($itemTodo) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
   public function updateItem($itemPatch) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
 
@@ -307,7 +323,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     return $this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey];
 	}
 
-  public function addP5Types(&$item, $key) {
+  public function addP5Types(&$item) {
     DBG::_('DBG_ACL', '>1', "\$item", $item, __CLASS__, __FUNCTION__, __LINE__);
     $sqlSelect = [];
     foreach ($this->_simpleSchema['root'] as $key => $field) {
@@ -341,4 +357,56 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     }
   }
 
+  public function fixParams(&$params) {// validate and fix params for getItem, getItems, etc. @see Api_WfsServerBase::parseGetFeatureArgsFromRequest()
+    $params['cols'] = $this->parseParamCols($params['cols']);
+  }
+
+  public function parseParamCols($filterCols = []) {
+    V::get('cols', [], $params);// wfs:propertyName
+    if (empty($filterCols)) {// set default filter cols
+      foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
+        if ('@' == substr($fieldName, 0, 1)) continue;
+        if ('unbounded' == V::get('maxOccurs', '', $field)) continue;// TODO:?: default load only single value fields (skip maxOccurs="unbounded")?
+        if (!empty($field['@type'])) {
+          if ('xsd:' === substr($field['@type'], 0, 4)) $filterCols[$fieldName] = true;
+          else if ('p5:' === substr($field['@type'], 0, 3)) $filterCols[$fieldName] = true;
+        } else if (!empty($field['@ref'])) {
+          $filterCols[$fieldName] = true;
+        } else throw new Exception("Schema error for field '{$fieldName}' ns({$this->_namespace})");
+      }
+    }
+
+    {// fix xpath for ref fields
+      foreach ($filterCols as $fieldName => $bool) {
+        $field = $this->_simpleSchema['root'][$fieldName];
+        if (!empty($field['@ref'])) {
+          $filterCols[$fieldName] = [];
+        }
+      }
+    }
+    return $filterCols;
+  }
+
+  public function buildFromSqlRow($row, $params = []) {
+    $object = [];
+    $filterCols = $this->parseParamCols($params['cols']);
+    $object['_raw'] = $row;
+    foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
+      if ('@' == substr($fieldName, 0, 1)) continue;
+      if (!array_key_exists($fieldName, $filterCols)) continue;// only filter cols
+      if (!empty($field['@type'])) {
+        // UI::alert('warning', "TODO: field({$fieldName}) type({$field['@type']})");
+        if ('xsd:' === substr($field['@type'], 0, 4)) {
+          $sqlFieldName = (!empty($field['@alias'])) ? $field['@alias'] : $fieldName;
+          $object[$fieldName] = V::get($sqlFieldName, '', $row);
+        } else if ('p5:' === substr($field['@type'], 0, 3)) {
+          $object[$fieldName] = "TODO: generate value for type {$field['@type']} - field '{$fieldName}' ns({$this->_namespace})";// TODO: single field method like addP5Types
+        } else throw new Exception("Not Implemented type for field '{$fieldName}' ns({$this->_namespace})");
+      } else if (!empty($field['@ref'])) {
+        $object[$fieldName] = $this->fetchItemFieldRefs($primaryKey, $fieldName);
+      } else throw new Exception("Schema error for field '{$fieldName}' ns({$this->_namespace})");
+    }
+    return $object;
+  }
+
 }

+ 1 - 1
SE/se-lib/Data_Source.php

@@ -634,7 +634,7 @@ class Data_Source {
 	/**
 	 * @returns object
 	 */
-	public function getItem($primaryKey) {
+	public function getItem($primaryKey, $params = []) {
 		$primaryKeyField = $this->getPrimaryKeyField();
 		$ret = null;
 		$sql_cols = $this->_getSqlCols();

+ 1 - 1
SE/se-lib/Schema/AccessGroupStorageAcl.php

@@ -42,7 +42,7 @@ class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
   public function getTotal($params = array()) {
     return count($this->getItems($params));
   }
-  public function getItem($primaryKey) {
+  public function getItem($primaryKey, $params = []) {
     $items = $this->getItems(['primaryKey'=>$primaryKey]);
     return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
   }

+ 1 - 1
SE/se-lib/Schema/AccessOwnerStorageAcl.php

@@ -48,7 +48,7 @@ class Schema_AccessOwnerStorageAcl extends Core_AclBase {
   public function getTotal($params = array()) {
     return count($this->getItems($params));
   }
-  public function getItem($primaryKey) {
+  public function getItem($primaryKey, $params = []) {
     $items = $this->getItems(['primaryKey'=>$primaryKey]);
     return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
   }

+ 1 - 1
SE/se-lib/Schema/FileStorageAcl.php

@@ -141,7 +141,7 @@ class Schema_FileStorageAcl extends Core_AclBase {
     ");
   }
 
-  public function getItem($primaryKey) {
+  public function getItem($primaryKey, $params = []) {
     $items = $this->getItems(['primaryKey'=>$primaryKey]);
     return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
   }

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

@@ -88,7 +88,7 @@ class Schema_TestPermsStorageAcl extends Core_AclBase {
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";}
     return $this->parentAcl->getTotal($params);
   }
-  public function getItem($primaryKey) {
+  public function getItem($primaryKey, $params = []) {
     $items = $this->getItems(['primaryKey'=>$primaryKey]);
     return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
   }

+ 1 - 1
SE/se-lib/TableAcl.php

@@ -1376,7 +1376,7 @@ class TableAcl extends Core_AclBase {
 		return $item;
 	}
 
-	public function getItem($primaryKey) {
+	public function getItem($primaryKey, $params = []) {
 		$ds = $this->getDataSource();
 		return $ds->getItem($primaryKey);
 	}