| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- Lib::loadClass('ApiRouteBase');
- Lib::loadClass('Api_WfsException');
- Lib::loadClass('Api_WfsQgisServer');
- Lib::loadClass('UserAcl');
- Lib::loadClass('Api_WfsLogger');
- class Api_WfsQgis extends ApiRouteBase {// TODO: extends Api_WfsBase which extends ApiBase
- public $_apiUser;
- public $_apiBaseUri;
- public $_idFiltrProces;
- public $_dataSourceName;
- public $_tblName;
- public $_tblSchema;
- public function execute($request) {
- $wfsLogger = new Api_WfsLogger();
- $this->setLogger($wfsLogger);
- $this->reqDBG($request);
- if (empty($request->segments)) {
- //$this->mainWpsAction($request);// show list of posible data source
- throw new HttpException("Bad Request", 400);
- } else {
- $pathPart = array_shift($request->segments);
- if ('filtr_proces_' == substr($pathPart, 0, 13)) {
- $this->_idFiltrProces = (int)substr($pathPart, 13);
- if (!$this->_idFiltrProces) throw new Api_WfsException("Wrong filtr process number");
- $this->DBG("filtr procesu({$idProcesFiltr})", __LINE__, __FUNCTION__, __CLASS__);
- $pathPart = array_shift($request->segments);
- }
- $this->_dataSourceName = $pathPart;
- $this->DBG("_dataSourceName:$this->_dataSourceName", __LINE__, __FUNCTION__, __CLASS__);
- try {
- $this->dataSourceAction($request);
- } catch (Api_WfsException $e) {
- DBG::logAuth($e);
- $e->sendResponseXml();
- } catch (Exception $e) {
- DBG::logAuth($e);
- $wfsException = new Api_WfsException($e->getMessage(), $e->getCode(), $e);
- $wfsException->sendResponseXml();
- }
- $this->DBG("END", __LINE__, __FUNCTION__, __CLASS__);
- }
- exit;
- // return document tree - array of arrays
- }
- public function wfsServerAction($request) {
- }
- public function dataSourceAction($request) {
- $document = '';
- //$userAcl = User::getAcl();
- 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>';}
- $userAcl = new UserAcl($this->_apiUser->getID(), $use_cache = true);
- $userAcl->fetchGroups();
- if ($this->_idFiltrProces) {
- if (!$userAcl->canExecuteProcesInit($this->_idFiltrProces)) {
- throw new Api_WfsException("Access Denied for given process");
- }
- $userAcl->fetchProcesPerms($this->_idFiltrProces, true);
- } else {
- $userAcl->fetchAllPerms(true);
- }
- User::getAcl($userAcl);// force set acl
- DBG::_('DBG', '>2', 'userAcl', $userAcl, __CLASS__, __FUNCTION__, __LINE__);
- $this->DBG("usr:" . $this->_apiUser->getID(), __LINE__, __FUNCTION__, __CLASS__);
- $wfsServer = new Api_WfsQgisServer($userAcl);
- $wfsServer->setLogger($this->_logger);
- $wfsServer->setBaseUri($this->_apiBaseUri);
- if ('WFS' != V::get('SERVICE', '', $request->query) and ('WFS' != V::get('service', '', $request->query))) {
- throw new Api_WfsException("Only WFS Service is allowed");
- }
- $req = V::get('REQUEST', '', $request->query);
- if (!empty($req)) {
- $methodName = "{$req}Action";
- if (!method_exists($wfsServer, $methodName)) {
- throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
- }
- $this->DBG("execute: WfsServer->{$methodName}(\$urlQuery)", __LINE__);
- $document = $wfsServer->$methodName($urlQuery);
- }
- else {
- $this->DBG("execute: WfsServer->parseXMLRequest()", __LINE__);
- $document = $wfsServer->parseXMLRequest();
- header('Content-type: application/xml');
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- echo $document; exit;// TODO: return $document;
- }
- 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>';}
- header('Content-type: application/xml');
- echo $document; exit;// TODO: return $document;
- }
- public function mainWpsAction($request) {
- return array('TODO:'=>'TODO: Show main WPS GetCapabilities');
- }
- }
|