瀏覽代碼

added ACL::getNamespaceFromId

Piotr Labudda 8 年之前
父節點
當前提交
e988221fee
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      SE/se-lib/ACL.php

+ 19 - 0
SE/se-lib/ACL.php

@@ -201,6 +201,25 @@ SQL;
 		return Core_AclHelper::getAclByNamespace(str_replace(':', '/', $typeName), $forceTblAclInit);
 	}
 
+	public static function getNamespaceFromId($idZasob) {
+		$sqlIdZasob = DB::getPDO()->quote($idZasob, PDO::PARAM_INT);
+		$zasob = DB::getPDO()->fetchFirst("
+			select z.ID, z.DESC, z.PARENT_ID
+			from CRM_LISTA_ZASOBOW z
+			where z.ID = {$sqlIdZasob}
+				and z.`TYPE` = 'TABELA'
+				and z.A_STATUS != 'DELETED'
+		");
+		if (!$zasob) throw new Exception("Object not exists '{$idZasob}'");
+		if ($zasob['PARENT_ID'] != DB::getPDO()->getZasobId()) {
+			throw new Exception("TODO: getNamespaceFromId for remote database");
+		}
+		return ('default_db/' === substr($zasob['DESC'], 0, strlen('default_db/')))
+			? $zasob['DESC']
+			: "default_db/{$zasob['DESC']}"
+		;
+	}
+
 	public static function parseNamespaceUrl($namespace) {// returns assoc array: [ 'name', 'url', 'prefix', 'sourceName' ]
 		return Core_AclHelper::parseNamespaceUrl($namespace);
 	}