Explorar el Código

updated itemsFetchRefs in AclBase

Piotr Labudda hace 9 años
padre
commit
e72d45e636

+ 1 - 1
SE/se-lib/Api/WfsDataServer.php

@@ -251,7 +251,7 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 							if (1 == count($item[$fldName])) {
 								$xlink = $item[$fldName][0]['xlink'];
 								$xlinkParts = explode(':', $xlink);
-								if (2 != count($xlinkParts)) throw new Exception("Error Processing Reques - wrong xlink format for ".$acl->getName().".{$itemKey}/{$fldName}");
+								if (2 != count($xlinkParts)) throw new Exception("Error Processing Request - wrong xlink format for ".$acl->getName().".{$itemKey}/{$fldName}");
 								$xlinkParts[0] = Api_WfsNs::getNsUri($xlinkParts[0]);
 								$xlink = implode('#', $xlinkParts);
 								$xmlWriter->startElement("{$wfsNs}:{$fldName}");

+ 37 - 0
SE/se-lib/Core/AclBase.php

@@ -4,6 +4,7 @@ Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Api_WfsException');
 Lib::loadClass('User');
 Lib::loadClass('Core_AclHelper');
+Lib::loadClass('ACL');
 
 // TODO: replace every methods using $idZasob to use $fieldName
 /* TODO: fetch ACL from acl tables:
@@ -188,6 +189,42 @@ 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, $params = []) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+
+  public function itemsFetchRefs(&$items) {
+    $DBG = V::get('DBG_DS', 0, $_GET, 'int');
+    $refs = array();// fieldName => namespace
+    foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
+      $fieldType = $this->getXsdFieldType($fieldName);
+      if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
+      else if ('alias_ref:' == substr($fieldType, 0, 10)) $refs[$fieldName] = substr($fieldType, 10);
+      // if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = str_replace(':', '/', substr($fieldType, 4));
+      // else if ('alias_ref:' == substr($fieldType, 0, 10)) $refs[$fieldName] = str_replace(':', '/', substr($fieldType, 10));
+      // else if ('ref_uri:' == substr($fieldType, 0, 8)) $refs[$fieldName] = substr($fieldType, 8);
+    }
+    if (empty($refs)) return $items;
+    $pkList = array_keys($items);
+    $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk);
+    $refRows = array();// $fieldName => [ pk, ... ]
+    foreach ($refs as $fieldName => $childNs) {
+      $acl = Core_AclHelper::getAclByTypeName($childNs);
+      // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList);
+      $refTableName = Core_AclHelper::getRefTable($this->getName(), $fieldName);
+      $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
+        select r.*
+        from `{$refTableName}` r
+        where r.PRIMARY_KEY in({$sqlPk})
+          and r.A_STATUS != 'DELETED'
+      ", $key = 'PRIMARY_KEY');
+      if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
+    }
+    foreach ($refRows as $fieldName => $refList) {
+      foreach ($refList as $pk => $ref) {
+        $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
+      }
+    }
+    return $items;
+  }
+
   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); }

+ 2 - 2
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -251,9 +251,9 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
   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 itemsFetchRefs(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: , $fieldName = ''
   public function fetchItemFieldRefs($primaryKey, $fieldName) {
-    $refTable = Core_AclHelper::getRefTable($this->getName(), $fieldName);
+    $refTable = ACL::getRefTable($this->getNamespace(), $fieldName);
     $sqlPk = DB::getPDO()->quote($primaryKey, PDO::PARAM_STR);
     return array_map(
       function ($row) {

+ 2 - 32
SE/se-lib/Schema/KorespondencjaStorageAcl.php

@@ -90,40 +90,10 @@ class Schema_KorespondencjaStorageAcl extends Core_AclBase {
     foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
     if (empty($items)) return $items;
-    $this->fetchItemRef($items);
-    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
+    $this->itemsFetchRefs($items);
+    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after itemsFetchRefs \$items:";print_r($items);echo "\n";}
     return $items;
   }
-  public function fetchItemRef(&$items) {
-    $DBG = V::get('DBG_DS', 0, $_GET, 'int');
-    $refs = array();// fieldName => xsdType
-    foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
-      $fieldType = $this->getXsdFieldType($fieldName);
-      if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
-      else if ('alias_ref:' == substr($fieldType, 0, 10)) $refs[$fieldName] = substr($fieldType, 10);
-    }
-    if (empty($refs)) return $items;
-    $fidList = array_keys($items);
-    $sqlPk = array(); foreach ($fidList as $pk) { $sqlPk[] = "'{$pk}'"; } $sqlPk = implode(", ", $sqlPk);
-    $baseRefTableName = $this->getRootTableName() . "__#REF__";
-    $refRows = array();// $fieldName => [ pk, ... ]
-    foreach ($refs as $fieldName => $type) {
-      $acl = Core_AclHelper::getAclByTypeName($type);
-      $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
-      $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
-        select r.*
-        from `{$refTableName}` r
-        where r.PRIMARY_KEY in({$sqlPk})
-        -- TODO and r.INSTANCE = '{$refInstanceName}' -- for multiple types based on the same root table
-      ", $key = 'PRIMARY_KEY');
-      if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
-    }
-    foreach ($refRows as $fieldName => $refList) {
-      foreach ($refList as $pk => $ref) {
-        $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
-      }
-    }
-  }
   public function addItem($itemTodo) {
     return $this->parentAcl->addItem($itemTodo);
   }

+ 2 - 35
SE/se-lib/Schema/TestPermsStorageAcl.php

@@ -100,43 +100,10 @@ class Schema_TestPermsStorageAcl extends Core_AclBase {
     foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
     if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
     if (empty($items)) return $items;
-    $this->fetchItemRef($items);// TODO: only fields from request
-    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
+    $this->itemsFetchRefs($items);// TODO: only fields from request
+    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after itemsFetchRefs \$items:";print_r($items);echo "\n";}
     return $items;
   }
-  public function fetchItemRef(&$items) {
-    $DBG = V::get('DBG_DS', 0, $_GET, 'int');
-    $refs = array();// fieldName => xsdType
-    foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
-      $fieldType = $this->getXsdFieldType($fieldName);
-      if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
-      else if ('alias_ref:' == substr($fieldType, 0, 10)) {
-        $refs[$fieldName] = substr($fieldType, 10);
-      }
-    }
-    if (empty($refs)) return $items;
-    $pkList = array_keys($items);
-    $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk);
-    $refRows = array();// $fieldName => [ pk, ... ]
-    foreach ($refs as $fieldName => $type) {
-      $acl = Core_AclHelper::getAclByTypeName($type);
-      // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList);
-      $refTableName = Core_AclHelper::getRefTable($this->getName(), $fieldName);
-      if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName})";echo"\n";}
-      $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
-        select r.*
-        from `{$refTableName}` r
-        where r.PRIMARY_KEY in({$sqlPk})
-          and r.A_STATUS != 'DELETED'
-      ", $key = 'PRIMARY_KEY');
-      if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
-    }
-    foreach ($refRows as $fieldName => $refList) {
-      foreach ($refList as $pk => $ref) {
-        $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
-      }
-    }
-  }
   public function addItem($itemTodo) {
     return $this->parentAcl->addItem($itemTodo);
   }