Piotr Labudda 8 лет назад
Родитель
Сommit
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);
 	}