{$message} EOT; self::output($xml); die(); } private function addChild($node, $name, $value = null) { $child = $this->dom->createElement($name, $value); $node->appendChild($child); return $child; } private function addAttribute($node, $name, $value) { $attr = $this->dom->createAttribute($name); $attr->value = $value; $node->appendChild($attr); } private function findRelations($node, $ID, $resolveDepth) { 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))) 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']); $query = "select `ID2` from `BI_audit_ALL_ref` where `ID1` = {$ID}"; $result = DB::getPDO()->fetchAll($query); foreach ($result as $row) $this->findRelations($feature, $row['ID2'], $resolveDepth - 1); } 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']}"); } array_pop($this->path); } public function defaultAction() { $TYPENAME = V::get('TYPENAME', '', $_GET); $primaryKey = V::get('primaryKey', 0, $_GET, 'int'); $resolveDepth = V::get('resolveDepth', 1, $_GET, 'int'); $TYPENAME_exploded = explode(":", $TYPENAME); if (!(count($TYPENAME_exploded) == 2 && $primaryKey && $resolveDepth >= 1 && $resolveDepth <= self::maxResolveDepth)) self::throwServiceException("WFS request error"); $table = $TYPENAME_exploded[1]; try { $this->dom = new DOMDocument('1.0', 'UTF-8'); $this->dom->preserveWhiteSpace = false; $this->dom->formatOutput = true; $attrs = [ 'xmlns:wfs' => 'http://www.opengis.net/wfs', 'xmlns' => 'http://www.opengis.net/wfs', 'xmlns:gml' => 'http://www.opengis.net/gml', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xlink' => 'http://www.w3.org/1999/xlink', ]; $wfs = $this->addChild($this->dom, 'wfs:FeatureCollection'); foreach ($attrs as $name => $value) $this->addAttribute($wfs, $name, $value); $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))) self::throwServiceException("Błąd danych"); $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) { self::throwServiceException($e->getMessage()); } } }