Ver código fonte

added ref list to row actions

Piotr Labudda 8 anos atrás
pai
commit
645c06edeb
2 arquivos alterados com 54 adições e 11 exclusões
  1. 21 6
      SE/se-lib/ACL.php
  2. 33 5
      SE/se-lib/Core/AclHelper.php

+ 21 - 6
SE/se-lib/ACL.php

@@ -416,26 +416,41 @@ class ACL {
 	}
 	public static function getBackRefList($namespace) {
 		if (!$namespace) throw new Exception("Missing namespace");
-		$nsParts = explode('/', $namespace);
-		$typeName = array_pop($nsParts);
-		$typeName = implode("__x3A__", $nsParts) . ":{$typeName}";
 		return DB::getPDO()->fetchAll("
 			select c.ROOT_OBJECT_NS as namespace
 				, i.id as idInstance
 			from CRM_REF_CONFIG c
 				join CRM_INSTANCE_CONFIG i on ( i.namespace = c.ROOT_OBJECT_NS )
-			where ( c.CHILD_NAME = :type_name or c.CHILD_NAME = :namespace )
+			where ( c.CHILD_NS = :namespace )
+				and c.A_STATUS = 'NORMAL'
+		", [
+			':namespace' => $namespace,
+		]);
+	}
+	public static function getRefList($namespace) {
+		if (!$namespace) throw new Exception("Missing namespace");
+		return DB::getPDO()->fetchAll("
+			select c.CHILD_NS as namespace
+				, i.id as idInstance
+			from CRM_REF_CONFIG c
+				join CRM_INSTANCE_CONFIG i on ( i.namespace = c.CHILD_NS )
+			where ( c.ROOT_OBJECT_NS = :namespace )
 				and c.A_STATUS = 'NORMAL'
 		", [
-			':type_name' => $typeName,
 			':namespace' => $namespace,
 		]);
 	}
 
-	public static function fetchRefs($namespace, $childNamespace, $primaryKey, $params = []) { // TODO: $params: limit, total
+	public static function fetchRefs($namespace, $primaryKey, $childNamespace, $params = []) { // TODO: $params: limit, total
 		if (!$namespace) throw new Exception("Missing namespace");
 		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);
+		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}'");
 	}
 

+ 33 - 5
SE/se-lib/Core/AclHelper.php

@@ -270,10 +270,8 @@ class Core_AclHelper {// Helper class for Acl
 				$backRefLabel = $backRef['namespace']; // TODO: get DESC from Zasoby
 				$backRefShort = explode("/", $backRefLabel);
 				$backRefShort = array_pop($backRefShort);
-				$backRefShort = (strlen($backRefShort) > 20) ? substr($backRefShort, 0, 20) . "..." : $backRefShort;
+				$backRefShort = (strlen($backRefShort) > 28) ? substr($backRefShort, 0, 28) . "..." : $backRefShort;
 
-				// 'namespace' => 'default_db/BI_audit_KRS/BI_audit_KRS',
-				// 'idInstance' => '24'
 				try {
 					$totalBackRefs = ACL::fetchBackRefs($acl->getNamespace(), $id, $backRef['namespace'], [ 'total' => true ]);
 				} catch (Exception $e) {
@@ -289,8 +287,38 @@ class Core_AclHelper {// Helper class for Acl
 						'childRefNS' => $acl->getNamespace(),
 						'childRefPK' => $id,
 					]),
-					'title' => "Wyszukaj powiązania z '{$backRefLabel}'",
-					'label' => "Wyszukaj powiązania z '{$backRefShort}' <span class=\"badge\">{$totalBackRefs}</span>",
+					'title' => "Powiązania od '{$backRefLabel}'",
+					'label' => "Powiązania od '{$backRefShort}' <span class=\"badge\">{$totalBackRefs}</span>",
+				];
+			}
+		}
+		if (count($partsNs) > 2) { // is AntAcl
+			$refList = ACL::getRefList($ns);
+			DBG::log($refList, 'array', "\$refList");
+			foreach ($refList as $refInfo) { // [ namespace, idInstance ]
+				$refLabel = $refInfo['namespace']; // TODO: get DESC from Zasoby
+				$refShortLabel = explode("/", $refLabel);
+				$refShortLabel = array_pop($refShortLabel);
+				$refShortLabel = (strlen($refShortLabel) > 28) ? substr($refShortLabel, 0, 28) . "..." : $refShortLabel;
+
+				try {
+					$totalRefs = ACL::fetchRefs($acl->getNamespace(), $id, $refInfo['namespace'], [ 'total' => true ]);
+				} catch (Exception $e) {
+					DBG::log($e);
+					continue;
+				}
+				DBG::log($totalRefs, 'array', "\$totalRefs {$refInfo['namespace']} pk({$id})");
+
+				$rowFunList[] = [
+					'ico' => 'glyphicon glyphicon-random',
+					'href' => Router::getRoute('ViewTableAjax')->getLink('', [
+						'namespace' => $refInfo['namespace'],
+						'backRefNS' => $acl->getNamespace(),
+						'backRefPK' => $id,
+						'backRefField' => Api_WfsNs::typeName($refInfo['namespace']),
+					]),
+					'title' => "Powiązania do '{$refLabel}'",
+					'label' => "Powiązania do '{$refShortLabel}' <span class=\"badge\">{$totalRefs}</span>",
 				];
 			}
 		}