WfsQgis.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $e->sendResponseXml();
  35. } catch (Exception $e) {
  36. $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
  37. $wfsException->sendResponseXml();
  38. }
  39. $this->DBG("END", __LINE__, __FUNCTION__, __CLASS__);
  40. }
  41. exit;
  42. // return document tree - array of arrays
  43. }
  44. public function wfsServerAction($request) {
  45. }
  46. public function dataSourceAction($request) {
  47. $document = '';
  48. //$userAcl = User::getAcl();
  49. 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>';}
  50. $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
  51. $userAcl->fetchGroups();
  52. if ($this->_idFiltrProces) {
  53. if (!$userAcl->canExecuteProcesInit($this->_idFiltrProces)) {
  54. throw new Api_WfsException("Access Denied for given process");
  55. }
  56. $userAcl->fetchProcesPerms($this->_idFiltrProces, true);
  57. } else {
  58. $userAcl->fetchAllPerms(true);
  59. }
  60. DBG::_('DBG', '>2', 'userAcl', $userAcl, __CLASS__, __FUNCTION__, __LINE__);
  61. $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
  62. $wfsServer = new Api_WfsQgisServer($userAcl);
  63. $wfsServer->setLogger($this->_logger);
  64. $wfsServer->setBaseUri($this->_apiBaseUri);
  65. if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
  66. throw new Api_WfsException("Only WFS Service is allowed");
  67. }
  68. $req = V::get('REQUEST', '', $request->query);
  69. if (!empty($req)) {
  70. $methodName = "{$req}Action";
  71. if (!method_exists($wfsServer, $methodName)) {
  72. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  73. }
  74. $this->DBG("execute: WfsServer->{$methodName}(\$urlQuery)", __LINE__);
  75. $document = $wfsServer->$methodName($urlQuery);
  76. }
  77. else {
  78. $this->DBG("execute: WfsServer->parseXMLRequest()", __LINE__);
  79. $document = $wfsServer->parseXMLRequest();
  80. header('Content-type: application/xml');
  81. echo '<?xml version="1.0" encoding="UTF-8"?>';
  82. echo $document; exit;// TODO: return $document;
  83. }
  84. 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>';}
  85. header('Content-type: application/xml');
  86. echo $document; exit;// TODO: return $document;
  87. }
  88. public function mainWpsAction($request) {
  89. return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
  90. }
  91. }