{$message} EOT; self::output($xml); die(); } public function objectStructureAction($namespace) { // objectStructAction try { if (empty($namespace)) throw new Exception("Missing param namespace"); $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]); $this->objectStructView($item); } catch (Exception $e) { //error_log('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); DBG::log($e); } } //input param $item['namespace']='default_db/BI_audit_CEIDG_powiazania/BI_audit_CEIDG_powiazania' public function objectStructView($item) { $namespace = $item['namespace']; $thisGetLink = [ $this, 'getLink' ]; $getBackRefList=ACL::getBackRefList($item['namespace']); echo "item"; print_r($item); echo "thisGetLink"; print_r($thisGetLink); echo "getBackRefList"; print_r($getBackRefList); //$refTable = ACL::getRefTable($field['objectNamespace'], $field['fieldNamespace']); } 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 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}"; if (!($row = DB::getPDO()->fetchFirst($query))) { 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); } 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()); } } }