a.binder 8 лет назад
Родитель
Сommit
84f9687aff
1 измененных файлов с 105 добавлено и 26 удалено
  1. 105 26
      SE/se-lib/Route/WfsBiAudit.php

+ 105 - 26
SE/se-lib/Route/WfsBiAudit.php

@@ -49,21 +49,66 @@ public function objectStructView($item) {
 		
 		$getBackRefList=ACL::getBackRefList($item['namespace']);
 		
-		echo "item";
-		error_log('getBackRefList, item:');
-		error_log($item);
+		/*
+		//echo "item";
+		//error_log('getBackRefList, item:');
+		//error_log($item);
 		
-		print_r($item);
-		echo "thisGetLink";
-		print_r($thisGetLink);
-		echo "getBackRefList";
+		//print_r($item);
+		//echo "thisGetLink";
+		//print_r($thisGetLink);
+		//echo "getBackRefList";
 
-		print_r($getBackRefList);
+		//print_r($getBackRefList);
+		*/
+		
+		foreach($getBackRefList as $backref) {
+			$exploded_ns= explode('/', $backref['namespace']);
+			$return['backrefs'][]=$exploded_ns[1].'__x3A__'.$exploded_ns[2],':',$exploded_ns[3];
+		}
+		foreach($item['field'] as $refs) {
+			
+			$return['refs'][]=$refs['fieldNamespace'];
+		}
+		
+		$return['table']=$item['name'];
+		$return['primaryKey']=$item['primaryKey'];
 
+		/*
+			
+			getBackRefList=Array(
+ 			   [0] => Array
+		        (
+		            [namespace] => default_db/BI_audit_CEIDG/BI_audit_CEIDG
+		            [idInstance] => 28
+		        )
 
-		//$refTable = ACL::getRefTable($field['objectNamespace'], $field['fieldNamespace']);
-						
 
+		/*
+		
+		/*
+		item=Array (
+			[field] => Array (
+				[0] => Array
+                (
+                    [namespace] => default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy/default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI
+                    [fieldNamespace] => default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI
+					[_rootTableName] => BI_audit_CEIDG_pelnomocnicy
+                    [objectNamespace] => default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy
+                    [xsdType] => ref:default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI
+                    
+                    [isActive] => 1
+                    [isLocal] => 0
+                    [sortPrio] => 0
+                )
+			)
+			
+			
+		)
+		*/
+		
+		return $return;
+	
 	}
 
 
@@ -89,6 +134,34 @@ public function objectStructView($item) {
 		}
 		return $this->relations[$ID];
         }
+        
+    private function findRelations_base($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}";
+		if (!($row = DB::getPDO()->fetchFirst($query)))
+		{
+			$this->objectStructureAction('default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy');
+			// self::throwServiceException("Błąd danych");
+		}
+		if (!in_array($row['REMOTE_TABLE'], $this->tablesUsed)) $this->tablesUsed[] = $row['REMOTE_TABLE'];
+		if ($resolveDepth) {
+			$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']);
+			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, $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']}?BI_audit_ALL_ref_RELATIONS={$relation}#{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}");
+		}
+		array_pop($this->path);
+
+	}
 
 	private function findRelations($node, $ID, $resolveDepth, $relation = null) {
 		if (in_array($ID, $this->path)) return;
@@ -143,28 +216,34 @@ public function objectStructView($item) {
 			$gml = $this->addChild($wfs, 'gml:featureMember');
 
 			$query = "select `ID` from `BI_audit_ALL` where `REMOTE_TABLE` = " . DB::getPDO()->quote($table) . " and `REMOTE_ID` = {$primaryKey}";
-			if (!($ID = DB::getPDO()->fetchValue($query))) 
+			if (!($ID = DB::getPDO()->fetchValue($query))) {
 				
-				$this->objectStructureAction('default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy');
+				$this->BaseStruct=$this->objectStructureAction('default_db/'.DB::getPDO()->quote($table).'/'.DB::getPDO()->quote($table));
 
-				//self::throwServiceException("Błąd danych");
+				$query = "select `ID` from ".DB::getPDO()->quote($table)." where `".$this->BaseStruct['primaryKey']."` = {$primaryKey}";
+				if (!($ID = DB::getPDO()->fetchValue($query))) {
+					self::throwServiceException("Błąd danych z BaseStruct ");
+				}
 				
-			$this->findRelations($gml, $ID, $resolveDepth);
-
-			foreach ($this->tablesUsed as $table) $this->addAttribute($wfs, "xmlns:default_db__x3A__{$table}", "https://biuro.biall-net.pl/wfs/default_db/{$table}");
-			$attrs = [
-				'numberMatched' => 'unknown',
-				'numberReturned' => '1',
-			];
-			foreach ($attrs as $name => $value) $this->addAttribute($wfs, $name, $value);
-
-			$xml = $this->dom->saveXML();
-			self::output($xml);
-		} catch (Exception $e) {
+			} else {
+				$this->findRelations($gml, $ID, $resolveDepth);
+	
+				foreach ($this->tablesUsed as $table) $this->addAttribute($wfs, "xmlns:default_db__x3A__{$table}", "https://biuro.biall-net.pl/wfs/default_db/{$table}");
+				$attrs = [
+					'numberMatched' => 'unknown',
+					'numberReturned' => '1',
+				];
+				foreach ($attrs as $name => $value) $this->addAttribute($wfs, $name, $value);
+	
+				$xml = $this->dom->saveXML();
+				self::output($xml);
+				
+			} 
+			catch (Exception $e) {
 			$this->objectStructureAction('default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy');
 
 			//self::throwServiceException($e->getMessage());
-		}
+			}
 	}
 
 }