Parcourir la source

Drobne poprawki

Mariusz Muszyński il y a 8 ans
Parent
commit
8bfc29d8a3
1 fichiers modifiés avec 15 ajouts et 10 suppressions
  1. 15 10
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 15 - 10
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -2181,6 +2181,7 @@ class BiAuditPowiazania {
 	private $results = [];
 	private $items_results = [];
 	private $relations = [];
+	private $srcTables = ['BI_audit_ENERGA_PRACOWNICY'];
 	private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person'];
 	private $step = 0;
 	private $tasksDirLocation;
@@ -2280,24 +2281,28 @@ class BiAuditPowiazania {
 		$subQueries = [];
 		foreach ($this->destTables as $destTable) {
 			$refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $destTable, true);
-			$subQueries[] = "select `all`.ID from BI_audit_ALL `all` join `{$refTable}` ref on `all`.REMOTE_TABLE = '{$destTable}' and `all`.REMOTE_ID = ref.REMOTE_PRIMARY_KEY and ref.PRIMARY_KEY = '{$this->ID}'";
+			$subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$destTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
 		}
-		$query = implode(" union ", $subQueries);
-		$resultDst = DB::getPDO()->fetchAll($query);
-		if ((!$resultDst) && $this->onlyTargets) self::throwException("Błąd danych - nie zdefinowano żadnego końcowego obiektu");
+		$query = implode(" union ", $subQueries) . " order by `ID` asc";
+		$resultDest = DB::getPDO()->fetchAll($query);
+		if ((!$resultDest) && $this->onlyTargets) self::throwException("Błąd danych - nie zdefinowano żadnego końcowego obiektu");
 
-		$refPowiazaniaToPracownicy = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', 'BI_audit_ENERGA_PRACOWNICY', true);
-		$query = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refPowiazaniaToPracownicy}` `ref`
-			on `all`.`REMOTE_TABLE` = 'BI_audit_ENERGA_PRACOWNICY' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}' order by `all`.`ID` asc";
+		$subQueries = [];
+		foreach ($this->srcTables as $srcTable) {
+			$refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $srcTable, true);
+			$subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$srcTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
+		}
+		$query = implode(" union ", $subQueries) . " order by `ID` asc";
 		$resultSrc = DB::getPDO()->fetchAll($query);
 		if (!$resultSrc) self::throwException("Błąd danych - nie zdefinowano żadnego początkowego obiektu");
 
-		if (count($resultSrc) <= count($resultDst) || (!$this->onlyTargets)) {
+		if (count($resultSrc) <= count($resultDest) || (!$this->onlyTargets)) {
 			$result = $resultSrc;
-			$this->endNodes = array_map('reset', $resultDst);
+			$this->endNodes = array_map('reset', $resultDest);
+			$this->reverseSearch = false;
 			$this->query = "select ref.ID2 as ID, RELATION_ID from BI_audit_ALL_ref ref where ref.ID1";
 		} else {
-			$result = $resultDst;
+			$result = $resultDest;
 			$this->endNodes = array_map('reset', $resultSrc);
 			$this->reverseSearch = true;
 			$this->query = "select ref.ID1 as ID, RELATION_ID from BI_audit_ALL_ref ref where ref.ID2";