Jelajahi Sumber

added backRef info with total in WfsBiAudit

Piotr Labudda 8 tahun lalu
induk
melakukan
8d56a9b34f
3 mengubah file dengan 54 tambahan dan 3 penghapusan
  1. 0 1
      SE/se-lib/ACL.php
  2. 1 1
      SE/se-lib/Api/Wfs/GetFeature.php
  3. 53 1
      SE/se-lib/Route/WfsBiAudit.php

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

@@ -268,7 +268,6 @@ class ACL {
 			throw new Exception("Not Implemented ref SOURCE = '{$refInfo['SOURCE']}'");
 		}
 
-		DBG::log($refInfo, 'array', "DBG XXXX");
 		if ($refInfo['VERSION'] < self::$REF_TABLE_VERSION) {
 			if (1 == $refInfo['VERSION']) $refInfo = self::upgradeRefConfigFrom1to2($refInfo);
 		}

+ 1 - 1
SE/se-lib/Api/Wfs/GetFeature.php

@@ -353,7 +353,7 @@ class Api_Wfs_GetFeature {
 			return;
 		}
 		if (1 === count($item) && !empty($item['p5:links'])) {
-			DBG::log($item, 'array', "TODO: p5:links");
+			DBG::log($item, 'array', "DBG p5:links");
 			// array (
 			//   'p5:links' =>
 			//   array (

+ 53 - 1
SE/se-lib/Route/WfsBiAudit.php

@@ -265,7 +265,7 @@ public function objectStructView($item) {
 				}
 			}
 			$item = $acl->buildQuery($searchParams)->getItem($primaryKey);
-			if (!$item) throw new \Exception("Item not found {$primaryKey}");
+			if (!$item) throw new Exception("Item not found {$primaryKey}");
 			// $item = Array( [ID] => 56977, [krs] => 0000080725 , ... )
 			// $item[default_db__x3A__BI_audit_MSIG_address:BI_audit_MSIG_address] => Array( [0] => [ 'xlink' => ${url} ] )
 			// $item[default_db__x3A__BI_audit_MSIG_address:BI_audit_MSIG_address] => Array( [11] => [ 'p5:links' => ${p5Links} ] )
@@ -325,6 +325,58 @@ public function objectStructView($item) {
 					$this->addChild($dataNode, $fieldName, "<!-- TODO: " . var_export($value, true) . " -->");
 				}
 			}
+
+			// add backRef links
+			$namespace = $acl->getNamespace();
+			$backRefList = ACL::getBackRefList($namespace);
+			DBG::log($backRefList, 'array', "\$backRefList for({$namespace};{$primaryKey})");
+			$backRefStats = array_map(function ($backRef) use ($namespace, $primaryKey) { // [ namespace, idInstance ], @returns { namespace, idInstance, label, shortName, total }
+				$label = $backRef['namespace']; // TODO: get DESC from Zasoby
+				$nameShort = explode("/", $label);
+				$nameShort = array_pop($nameShort);
+				$nameShort = (strlen($nameShort) > 20) ? substr($nameShort, 0, 20) . "..." : $nameShort;
+				$total = 0;
+				try {
+					$total = ACL::fetchBackRefs($namespace, $primaryKey, $backRef['namespace'], [ 'total' => true ]);
+				} catch (Exception $e) {
+					DBG::log($e);
+				}
+				return array_merge($backRef, [
+					'primaryKey' => $primaryKey,
+					'label' => $label,
+					'shortName' => $nameShort,
+					'total' => $total,
+				]);
+			}, $backRefList);
+			DBG::log($backRefStats, 'array', "\$backRefStats for({$namespace};{$primaryKey})");
+			$foundBackRef = array_filter($backRefStats, function ($statsBackRef) {
+				return ($statsBackRef['total'] > 0);
+			});
+			DBG::log($foundBackRef, 'array', "\$foundBackRef for({$namespace};{$primaryKey})");
+			// $rowFunList[] = [
+			// 	'ico' => 'glyphicon glyphicon-random',
+			// 	'href' => Router::getRoute('ViewTableAjax')->getLink('', [
+			// 		'namespace' => $backRef['namespace'],
+			// 		'childRefNS' => $acl->getNamespace(),
+			// 		'childRefPK' => $id,
+			// 	]),
+			// 	'title' => "Wyszukaj powiązania z '{$backRefLabel}'",
+			// 	'label' => "Wyszukaj powiązania z '{$backRefShort}' <span class=\"badge\">{$totalBackRefs}</span>",
+			// ];
+			if (!empty($foundBackRef)) {
+				$p5LinkNode = $this->addChild($dataNode, 'p5:links');
+				foreach ($foundBackRef as $backRef) {
+					$linkBackRef = null; // TODO: generate back ref link
+					$p5BackRefNode = $this->addChild($p5LinkNode, 'p5:backRef', $linkBackRef);
+					$this->addAttribute($p5BackRefNode, "p5:total", $backRef['total']);
+					$this->addAttribute($p5BackRefNode, "p5:label", $backRef['label']);
+					$this->addAttribute($p5BackRefNode, "p5:shortName", $backRef['shortName']);
+					$this->addAttribute($p5BackRefNode, "p5:namespace", $backRef['namespace']);
+					$this->addAttribute($p5BackRefNode, "p5:primaryKey", $backRef['primaryKey']);
+					$this->addAttribute($p5BackRefNode, "p5:from", $namespace);
+					$this->addAttribute($p5BackRefNode, "p5:to", $backRef['namespace']);
+				}
+			}
 		} catch (Exception $e) {
 			DBG::log($e);
 		}