WpsHelper.php 3.0 KB

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