WpsHelper.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. class Api_WpsHelper {
  3. static function getUserWpsProcessList($userLogin = null) {
  4. // TODO: $userLogin
  5. $defaultWpsProcessList = self::getDefaultWpsProcessList();
  6. if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
  7. $wpsProcessList = [];
  8. // TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
  9. $wpsProcessList = array_merge($defaultWpsProcessList, $wpsProcessList);
  10. return array_map(function ($wpsProcess, $identifier) {
  11. return (object)[ 'identifier' => $identifier, 'title' => $wpsProcess['title'], 'description' => $wpsProcess['description'] ];
  12. }, $wpsProcessList, array_keys($wpsProcessList));
  13. return $wpsProcessList;
  14. }
  15. static function getUserWpsProcess($identifier, $userLogin = null) {
  16. // TODO: $userLogin
  17. $defaultWpsProcessList = self::getDefaultWpsProcessList();
  18. if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
  19. // TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
  20. throw new Exception("Forbidden - wps function not exists or access denied", 403);
  21. }
  22. static function getDefaultWpsProcessList() {
  23. $defaultWpsProcessList = [];
  24. {
  25. $selectFeatureBase = [
  26. 'dataInputs' => [
  27. [
  28. 'maxOccurs' => "1",
  29. 'minOccurs' => "1",
  30. 'identifier' => 'typeName',
  31. 'title' => "Feature typeName",
  32. 'description' => "Feature typeName eg. default_db/PROBLEMS",
  33. 'type' => 'literal',
  34. ],
  35. [
  36. 'maxOccurs' => "unbounded",
  37. 'minOccurs' => "1",
  38. 'identifier' => 'primaryKey',
  39. 'title' => "Feature primaryKey",
  40. 'description' => "Feature primaryKey",
  41. 'type' => 'literal',
  42. ],
  43. ],
  44. // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
  45. 'defaultOutput' => [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ], // TODO: result type - like Insert Wfs Transaction result - list of: Success (primaryKey = 123), ...
  46. 'supportedOutput' => [
  47. [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
  48. [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
  49. [ 'MimeType' => "application/json" ],
  50. // [ 'MimeType' => "application/wfs-collection-1.0" ],
  51. // [ 'MimeType' => "application/wfs-collection-1.1" ],
  52. // [ 'MimeType' => "application/zip" ],
  53. ]
  54. ];
  55. $defaultWpsProcessList['p5:selectFeature'] = array_merge([ 'title' => "Select feature", 'descriptin' => "Select feature (set attribute @selected to true)" ], $selectFeatureBase);
  56. $defaultWpsProcessList['p5:unselectFeature'] = array_merge([ 'title' => "Unselect feature", 'descriptin' => "Unselect feature (set attribute @selected to false)" ], $selectFeatureBase);
  57. }
  58. array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {
  59. $wpsFunction['identifier'] = $identifier;
  60. });
  61. return $defaultWpsProcessList;
  62. }
  63. }