testFetchWfs.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. function testFetchWfs($typeName, $featureId) {
  3. DBG::log([$typeName, $featureId], 'array', "TODO: testFetchWfs");
  4. $dom = new DOMDocument();
  5. $tmp = $dom->createDocumentFragment();
  6. try {
  7. $acl = ACL::getAclByTypeName($typeName);
  8. $pk = substr($featureId, strpos($featureId, '.') + 1);
  9. $item = $acl->buildQuery([ 'cols' => array_keys($acl->getXsdTypes()) ])->getItem($pk);
  10. if (!$item) throw new Exception("Object with primary key = '{$pk}' not found");
  11. DBG::log($item, 'array', "testFetchWfs feature found");
  12. foreach ($item as $fieldName => $value) {
  13. if (is_scalar($value)) {
  14. $tmp->appendXML('<p>' . $fieldName .': "' . $value . '"</p>');
  15. }
  16. else if (is_array($value)) {
  17. $out = '<details open="true"><summary>' . $fieldName .':</summary><div>';
  18. foreach ($value as $refItem) {
  19. if (1 === count($refItem) && !empty($refItem['xlink'])) {
  20. $out .= '<p> - ' . $refItem['xlink'] .':</p>';
  21. }
  22. else {
  23. $out .= '<p>';
  24. foreach ($refItem as $refField => $refValue) {
  25. $out .= '- <b>' . $refField . ':</b> ' . $refValue .'<br>';
  26. }
  27. $out .= '</p>';
  28. }
  29. }
  30. $out .= '</div></details>';
  31. $tmp->appendXML($out);
  32. }
  33. }
  34. } catch (Exception $e) {
  35. $tmp->appendXML('<div class="alert alert-danger">' . $e->getMessage() . '</div>');
  36. }
  37. return $tmp; // TODO: require <xsl:copy-of select="php:function(...)/node() - @see https://en.wikibooks.org/wiki/PHP_Programming/XSL/registerPHPFunctions#XSL_receiving_external_fragments
  38. // return $dom->saveXML($tmp);
  39. }