Ver código fonte

updated ACL::fetchRefs, added Api_WfsNs::toTypeName

Piotr Labudda 8 anos atrás
pai
commit
37057b5693
2 arquivos alterados com 15 adições e 3 exclusões
  1. 11 3
      SE/se-lib/ACL.php
  2. 4 0
      SE/se-lib/Api/WfsNs.php

+ 11 - 3
SE/se-lib/ACL.php

@@ -446,12 +446,20 @@ class ACL {
 		if (!$childNamespace) throw new Exception("Missing child namespace");
 		if (!$primaryKey) throw new Exception("Missing primary key");
 
-		$typeName = Api_WfsNs::typeName($childNamespace);
-		$refTable = ACL::getRefTable($namespace, $typeName);
+		$childTypeName = Api_WfsNs::toTypeName($childNamespace);
+		$refConf = ACL::getRefConfig($namespace, $childTypeName);
+		$refTable = $refConf->tableName; // ACL::getRefTable($namespace, $childTypeName);
 		if (V::get('total', false, $params)) {
 			return DB::getPDO()->fetchValue(" select count(*) as cnt from `{$refTable}` where PRIMARY_KEY = :primary_key and A_STATUS not in ('DELETED') ", [ ':primary_key' => $primaryKey ]);
 		}
-		throw new Exception("TODO: fetch refs from '{$namespace}' where primaryKey = '{$primaryKey}'");
+
+		return DB::getPDO()->fetchAll("
+			select REMOTE_PRIMARY_KEY
+			from `{$refConf->tableName}`
+			where PRIMARY_KEY = :primaryKey
+				and A_STATUS not in ('DELETED')
+		", [ ':primaryKey' => $primaryKey ]);
+		// TODO: order by SORT_PRIO
 	}
 
 	public static function fetchBackRefs($namespace, $primaryKey, $parentNamespace, $params = []) { // TODO: $params: limit, total

+ 4 - 0
SE/se-lib/Api/WfsNs.php

@@ -8,6 +8,10 @@ class Api_WfsNs {
 		return str_replace([ '__x3A__', ':' ], '/', $typeNameOrNamespace);
 	}
 
+	static function toTypeName($typeNameOrNamespace) {
+		return (false !== strpos($typeNameOrNamespace, ':')) ? $typeNameOrNamespace : self::typeName($typeNameOrNamespace);
+	}
+
 	public static function typeName($namespaceUri) {
 		$ex = explode('/', $namespaceUri);
 		$name = array_pop($ex);