瀏覽代碼

Włączenie BiAuditGenerate w cronie

Mariusz Muszyński 8 年之前
父節點
當前提交
b8aa2c86cd
共有 1 個文件被更改,包括 18 次插入5 次删除
  1. 18 5
      SE/se-lib/Route/WfsBiAudit.php

+ 18 - 5
SE/se-lib/Route/WfsBiAudit.php

@@ -5,7 +5,7 @@ Lib::loadClass('RouteBase');
 class Route_WfsBiAudit extends RouteBase {
 
 	const maxResolveDepth = 3;
-	private $dom, $path = [], $tablesUsed = [];
+	private $dom, $path = [], $relations = [], $tablesUsed = [];
 
 	private static function output($output) {
 		header("Content-Type: application/xml");
@@ -38,7 +38,17 @@ EOT;
 		$node->appendChild($attr);
 	}
 
-	private function findRelations($node, $ID, $resolveDepth) {
+	private function relationName($ID) {
+		if (!isset($this->relations[$ID])) {
+			$query = "select `RELATION` from `BI_audit_ALL_ref_RELATIONS` where `ID` & {$ID} order by `ID`";
+			$result = DB::getPDO()->fetchAll($query);
+			$rels = array_map('reset', $result);
+			$this->relations[$ID] = implode(", ", $rels);
+		}
+		return $this->relations[$ID];
+        }
+
+	private function findRelations($node, $ID, $resolveDepth, $relation = null) {
 		if (in_array($ID, $this->path)) return;
 		$this->path[] = $ID;
 		$query = "select `REMOTE_TABLE`, `REMOTE_ID` from `BI_audit_ALL` where `ID` = {$ID}";
@@ -48,12 +58,15 @@ EOT;
 			$feature = $this->addChild($node, "default_db__x3A__{$row['REMOTE_TABLE']}:{$row['REMOTE_TABLE']}");
 			$this->addAttribute($feature, 'fid', "{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}");
 			$this->addChild($feature, "default_db__x3A__{$row['REMOTE_TABLE']}:ID", $row['REMOTE_ID']);
-			$query = "select `ID2` from `BI_audit_ALL_ref` where `ID1` = {$ID}";
+			if ($relation) $this->addChild($feature, "relation_from", $this->relationName($relation));
+			//$query = "select `ID2` from `BI_audit_ALL_ref` where `ID1` = {$ID}";
+			$where = $relation ? "and ({$relation} & `RELATION_ID`) != {$relation}" : "";
+			$query = "select `ID2`, `RELATION_ID` from `BI_audit_ALL_ref` where `ID1` = {$ID} {$where}";
 			$result = DB::getPDO()->fetchAll($query);
-			foreach ($result as $row) $this->findRelations($feature, $row['ID2'], $resolveDepth - 1);
+			foreach ($result as $row) $this->findRelations($feature, $row['ID2'], $resolveDepth - 1, $row['RELATION_ID']);
 		} else {
 			$xlink = $this->addChild($node, "default_db__x3A__{$row['REMOTE_TABLE']}:{$row['REMOTE_TABLE']}");
-			$this->addAttribute($xlink, 'xlink:href', "https://biuro.biall-net.pl/wfs/default_db/{$row['REMOTE_TABLE']}#{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}");
+			$this->addAttribute($xlink, 'xlink:href', "https://biuro.biall-net.pl/wfs/default_db/{$row['REMOTE_TABLE']}?BI_audit_ALL_ref_RELATIONS={$relation}#{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}");
 		}
 		array_pop($this->path);
 	}