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

+ 104 - 42
SE/se-lib/Route/WfsBiAudit.php

@@ -28,6 +28,7 @@ EOT;
 
 	public function objectStructureAction($namespace) { // objectStructAction
 		Lib::loadClass('SchemaFactory');
+		Lib::ACL('SchemaFactory');
 
 		try {
 			error_log('objectStructureAction for '.$namespace);
@@ -59,6 +60,12 @@ public function objectStructView($item) {
 		foreach($item['field'] as $ind=>$refs) {
 			
 			$return['refs'][]=$refs['fieldNamespace'];
+			$return['refs__rootTableName'][]=$refs['_rootTableName'];
+			$return['refs__objectNamespace'][]=$refs['objectNamespace'];
+
+
+			
+
 		}
 		
 		$return['table']=$item['name'];
@@ -95,59 +102,104 @@ public function objectStructView($item) {
 		return $this->relations[$ID];
         }
         
-    private function findRelations_base($node, $ID, $resolveDepth, $relation = null) {
+    private function findRelations_base($node, $ID, $resolveDepth, $relation = null, $BaseStruct,$table) {
 	    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 #102 findRelations_base");
-		}
-		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']}");
-		}
+		
+		foreach($BaseStruct['objectNamespace'] as $ind=>$refs){
+				$getRefTable=ACL::getRefTable('default_db/'.$table.'/'.$table,$refs);
+				
+				$query = "select `REMOTE_PRIMARY_KEY`  from `".$getRefTable."` where `PRIMARY_KEY` = {$ID}";
+				if (!($row = DB::getPDO()->fetchFirst($query))) {
+					
+				} else {
+						/*{
+							$this->objectStructureAction('default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy');
+							 self::throwServiceException("Błąd danych #102 findRelations_base");
+						}*/
+				
+				if (!in_array($BaseStruct[$ind]['_rootTableName'], $this->tablesUsed)) $this->tablesUsed[] = $BaseStruct[$ind]['_rootTableName'];
+				}
+				
+				if ($resolveDepth) {
+					$feature = $this->addChild($node, $BaseStruct[$ind]['refs']);
+					$this->addAttribute($feature, 'fid', $BaseStruct[$ind]['_rootTableName'].$row['REMOTE_PRIMARY_KEY']);
+					$this->addChild($feature, "default_db__x3A__".$BaseStruct[$ind]['_rootTableName'].":ID", $row['REMOTE_PRIMARY_KEY']);
+					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}" : "";
+					$RefBaseStruct=$this->objectStructureAction($BaseStruct[$ind]['objectNamespace']); 
+					
+					$query = "select `".$RefBaseStruct['primaryKey']."` from `".$RefBaseStruct['table']."` where `".$RefBaseStruct['primaryKey']."` = ".$row['REMOTE_PRIMARY_KEY'] ;
+					$result = DB::getPDO()->fetchAll($query);
+					foreach ($result as $row) $this->findRelations($feature, $row['REMOTE_PRIMARY_KEY'], $resolveDepth - 1, null,$BaseStruct['table'],$RefBaseStruct['table']);
+				} else {
+					$xlink = $this->addChild($node, $BaseStruct[$ind]['fieldNamespace']);
+					$this->addAttribute($xlink, 'xlink:href', "https://biuro.biall-net.pl/wfs/default_db/{$RefBaseStruct['table']}?BI_audit_ALL_ref_RELATIONS={$relation}#{$RefBaseStruct['table']}.{$row['REMOTE_PRIMARY_KEY']}");
+				}
 		array_pop($this->path);
+		}
+		
 
 	}
 
-	private function findRelations($node, $ID, $resolveDepth, $relation = null) {
+	private function findRelations($node, $ID, $resolveDepth, $relation = null,$BaseTableFrom,$BaseTableTo) {
 		if (in_array($ID, $this->path)) return;
 		$this->path[] = $ID;
-		$query = "select `REMOTE_TABLE`, `REMOTE_ID` from `BI_audit_ALL` where `ID` = {$ID}";
+		if(isset($BaseTableFrom)) {
+			$query = "select `REMOTE_TABLE`, `REMOTE_ID` from `BI_audit_ALL` where `ID` = {$ID} and `REMOTE_TABLE`='".$BaseTableTo."'"; //todo nie wiem czy nie na odwrot $BaseTableTo
+		} else {
+			$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 findRelations #130");
-		}
-		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']);
+				//$this->objectStructureAction('default_db/BI_audit_CEIDG_pelnomocnicy/BI_audit_CEIDG_pelnomocnicy');
+				// self::throwServiceException("Błąd danych findRelations #130");
+				 $this->BaseStruct=$this->objectStructureAction("default_db/".$BaseTableTo."/".$BaseTableTo );
+				 $query = "select `".$this->BaseStruct['primaryKey']."` from `".$BaseTableTo."` where ".$this->BaseStruct['primaryKey']." = {$ID}";
+				if (!($ID = DB::getPDO()->fetchValue($query))) {
+					self::throwServiceException("Błąd danych z BaseStruct/findRelations #162 ");
+				}
+				
+				if (!in_array($BaseTableTo, $this->tablesUsed)) $this->tablesUsed[] = $BaseTableTo;
+				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'],);
+						findRelations_base($node, $ID, $resolveDepth, $relation = null, $this->BaseStruct,$BaseTableTo) ;
+
+					} else {
+						$xlink = $this->addChild($node, "default_db__x3A__{$BaseTableTo}:{$BaseTableTo}");
+						$this->addAttribute($xlink, 'xlink:href', "https://biuro.biall-net.pl/wfs/default_db/{$BaseTableTo]}?BI_audit_ALL_ref_RELATIONS={$relation}#{$BaseTableTo}.{$row[$this->BaseStruct['primaryKey']]}");
+					}
+					array_pop($this->path);
+								 
 		} 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']}");
+					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);
 		}
-		array_pop($this->path);
 	}
 
 	public function defaultAction() {
@@ -182,11 +234,21 @@ public function objectStructView($item) {
 				$this->BaseStruct=$this->objectStructureAction("default_db/".$table."/".$table );
 					
 									
-									
 				$query = "select `".$this->BaseStruct['primaryKey']."` from `".$table."` where ".$this->BaseStruct['primaryKey']." = {$primaryKey}";
 				if (!($ID = DB::getPDO()->fetchValue($query))) {
 					self::throwServiceException("Błąd danych z BaseStruct ");
 				}
+					$this->findRelations_base($gml, $ID, $resolveDepth,$this->BaseStruct,$table);
+			
+						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);
 				
 				} else {
 					$this->findRelations($gml, $ID, $resolveDepth);