WfsQgis.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. Lib::loadClass('ApiRouteBase');
  3. Lib::loadClass('Api_WfsException');
  4. Lib::loadClass('Api_WfsQgisServer');
  5. Lib::loadClass('UserAcl');
  6. Lib::loadClass('Api_WfsLogger');
  7. class Api_WfsQgis extends ApiRouteBase {// TODO: extends Api_WfsBase which extends ApiBase
  8. public $_apiUser;
  9. public $_apiBaseUri;
  10. public $_idFiltrProces;
  11. public $_dataSourceName;
  12. public $_tblName;
  13. public $_tblSchema;
  14. public function execute($request) {
  15. $wfsLogger = new Api_WfsLogger();
  16. $this->setLogger($wfsLogger);
  17. $this->reqDBG($request);
  18. if (empty($request->segments)) {
  19. //$this->mainWpsAction($request);// show list of posible data source
  20. throw new HttpException("Bad Request", 400);
  21. } else {
  22. $pathPart = array_shift($request->segments);
  23. if ('filtr_proces_' == substr($pathPart, 0, 13)) {
  24. $this->_idFiltrProces = (int)substr($pathPart, 13);
  25. if (!$this->_idFiltrProces) throw new Api_WfsException("Wrong filtr process number");
  26. $this->DBG("filtr procesu({$idProcesFiltr})", __LINE__, __FUNCTION__, __CLASS__);
  27. $pathPart = array_shift($request->segments);
  28. }
  29. $this->_dataSourceName = $pathPart;
  30. $this->DBG("_dataSourceName:$this->_dataSourceName", __LINE__, __FUNCTION__, __CLASS__);
  31. try {
  32. $this->dataSourceAction($request);
  33. } catch (Api_WfsException $e) {
  34. DBG::logAuth($e);
  35. $e->sendResponseXml();
  36. } catch (Exception $e) {
  37. DBG::logAuth($e);
  38. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  39. $wfsException->sendResponseXml();
  40. }
  41. $this->DBG("END", __LINE__, __FUNCTION__, __CLASS__);
  42. }
  43. exit;
  44. // return document tree - array of arrays
  45. }
  46. public function wfsServerAction($request) {
  47. }
  48. public function dataSourceAction($request) {
  49. $document = '';
  50. //$userAcl = User::getAcl();
  51. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">user (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_apiUser);echo'</pre>';}
  52. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  53. $userAcl->fetchGroups();
  54. if ($this->_idFiltrProces) {
  55. if (!$userAcl->canExecuteProcesInit($this->_idFiltrProces)) {
  56. throw new Api_WfsException("Access Denied for given process");
  57. }
  58. $userAcl->fetchProcesPerms($this->_idFiltrProces, true);
  59. } else {
  60. $userAcl->fetchAllPerms(true);
  61. }
  62. User::getAcl($userAcl);// force set acl
  63. DBG::_('DBG', '>2', 'userAcl', $userAcl, __CLASS__, __FUNCTION__, __LINE__);
  64. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  65. $wfsServer = new Api_WfsQgisServer($userAcl);
  66. $wfsServer->setLogger($this->_logger);
  67. $wfsServer->setBaseUri($this->_apiBaseUri);
  68. if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
  69. throw new Api_WfsException("Only WFS Service is allowed");
  70. }
  71. $req = V::get('REQUEST', '', $request->query);
  72. if (!empty($req)) {
  73. $methodName = "{$req}Action";
  74. if (!method_exists($wfsServer, $methodName)) {
  75. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  76. }
  77. $this->DBG("execute: WfsServer->{$methodName}(\$urlQuery)", __LINE__);
  78. $document = $wfsServer->$methodName($urlQuery);
  79. }
  80. else {
  81. $this->DBG("execute: WfsServer->parseXMLRequest()", __LINE__);
  82. $document = $wfsServer->parseXMLRequest();
  83. header('Content-type: application/xml');
  84. echo '<?xml version="1.0" encoding="UTF-8"?>';
  85. echo $document; exit;// TODO: return $document;
  86. }
  87. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$document (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($document);echo'</pre>';}
  88. header('Content-type: application/xml');
  89. echo $document; exit;// TODO: return $document;
  90. }
  91. public function mainWpsAction($request) {
  92. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  93. }
  94. }