WfsServerBase.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. <?php
  2. Lib::loadClass('Api_WfsException');
  3. Lib::loadClass('Api_WfsGeomTypeConverter');
  4. class Api_WfsServerBase {
  5. public $_usrAcl;
  6. public $_typeConverter;
  7. public $_apiBaseUri;
  8. public function __construct($usrAcl) {
  9. $this->_usrAcl = $usrAcl;
  10. $this->_typeConverter = new Api_WfsGeomTypeConverter();
  11. $this->_apiBaseUri = '';
  12. }
  13. public function setBaseUri($uri) {
  14. $this->_apiBaseUri = $uri;
  15. }
  16. public function getBaseUri() {
  17. return $this->_apiBaseUri;
  18. }
  19. public function getBaseNamespaceUri() {
  20. $baseNsUri = $this->_apiBaseUri;
  21. $protocolType = '';
  22. if (!empty($baseNsUri)) {
  23. if ('https://' == substr($baseNsUri, 0, 8)) {
  24. $protocolType = 'https';
  25. $baseNsUri = substr($baseNsUri, 8);
  26. } else if ('http://' == substr($baseNsUri, 0, 7)) {
  27. $protocolType = 'http';
  28. $baseNsUri = substr($baseNsUri, 6);
  29. }
  30. }
  31. if (!empty($baseNsUri)) {
  32. if (false !== ($pos = strpos($baseNsUri, '/'))) {
  33. $baseNsUri = substr($baseNsUri, 0, $pos);
  34. }
  35. }
  36. return "{$protocolType}://{$baseNsUri}/wfs";
  37. }
  38. public function isAllowedFeatureType($nsPrefix, $type) {
  39. if ('p5_' != substr($nsPrefix, 0, 3)) return false;
  40. if ('p5_default_db' == $nsPrefix) {
  41. $typeName = "p5_default_db:{$type}";
  42. try {
  43. $acl = $this->getAclFromTypeName($typeName);
  44. } catch (Exception $e) {
  45. return false;
  46. }
  47. if ($acl) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. /**
  54. * @param string $typeName - 'p5_default_db:TEST_PERMS'
  55. */
  56. public function getAclFromTypeName($typeName) {
  57. $typeEx = explode(':', $typeName);
  58. if (2 != count($typeEx)) {
  59. throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
  60. }
  61. if ('p5_' != substr($typeEx[0], 0, 3)) {
  62. throw new Api_WfsException("Could not get acl for '{$typeName}' - prefix error");
  63. }
  64. $sourceName = substr($typeEx[0], 3);
  65. $objName = $typeEx[1];
  66. $acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
  67. if (!$acl) {
  68. throw new Api_WfsException("Could not get acl for '{$typeName}'");
  69. }
  70. $forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
  71. $acl->init($forceTblAclInit);
  72. return $acl;
  73. }
  74. public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
  75. echo '<?xml version="1.0" encoding="UTF-8"?>';
  76. ?>
  77. <WFS_Capabilities version="1.0.0"
  78. xmlns="http://www.opengis.net/wfs"
  79. xmlns:ogc="http://www.opengis.net/ogc"
  80. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81. <?php echo $this->_getXmlNamespaceList(); ?>
  82. xsi:schemaLocation="http://www.opengis.net/wfs <?php echo $this->_getSchemaLocationString(); ?>">
  83. <Service>
  84. <Name>WFS</Name>
  85. <Title><?php echo $serviceTitle; ?></Title>
  86. <Abstract><?php echo $serviceDescription; ?></Abstract>
  87. <Keywords>WFS, WMS</Keywords>
  88. <OnlineResource><?php echo $wfsServerUrl; ?></OnlineResource>
  89. <Fees>NONE</Fees>
  90. <AccessConstraints>NONE</AccessConstraints>
  91. </Service>
  92. <Capability>
  93. <Request>
  94. <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
  95. <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
  96. <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
  97. <?php $this->_printTransactionXml($wfsServerUrl); ?>
  98. <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
  99. <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
  100. </Request>
  101. </Capability>
  102. <FeatureTypeList>
  103. <Operations>
  104. <Query />
  105. <Insert />
  106. <Update />
  107. <Delete />
  108. <Lock />
  109. </Operations>
  110. <?php echo $this->_printFeatureTypeListXml(); ?>
  111. </FeatureTypeList>
  112. <ogc:Filter_Capabilities>
  113. <ogc:Spatial_Capabilities>
  114. <ogc:Spatial_Operators>
  115. <ogc:Disjoint />
  116. <ogc:Equals />
  117. <ogc:DWithin />
  118. <ogc:Beyond />
  119. <ogc:Intersect />
  120. <ogc:Touches />
  121. <ogc:Crosses />
  122. <ogc:Within />
  123. <ogc:Contains />
  124. <ogc:Overlaps />
  125. <ogc:BBOX />
  126. </ogc:Spatial_Operators>
  127. </ogc:Spatial_Capabilities>
  128. <ogc:Scalar_Capabilities>
  129. <ogc:Logical_Operators />
  130. <ogc:Comparison_Operators>
  131. <ogc:Simple_Comparisons />
  132. <ogc:Between />
  133. <ogc:Like />
  134. <ogc:NullCheck />
  135. </ogc:Comparison_Operators>
  136. <ogc:Arithmetic_Operators>
  137. <ogc:Simple_Arithmetic />
  138. <ogc:Functions>
  139. <ogc:Function_Names>
  140. <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
  141. <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
  142. <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
  143. <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
  144. <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
  145. <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
  146. <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
  147. <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
  148. <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
  149. <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
  150. <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
  151. <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
  152. <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
  153. <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
  154. <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
  155. <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
  156. <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
  157. <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
  158. <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
  159. <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
  160. <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
  161. <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
  162. <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
  163. <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
  164. <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
  165. <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
  166. <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
  167. <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
  168. <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
  169. <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
  170. <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
  171. <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
  172. <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
  173. <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
  174. <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
  175. <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
  176. <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
  177. <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
  178. <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
  179. <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
  180. <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
  181. <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
  182. <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
  183. <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
  184. <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
  185. <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
  186. <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
  187. <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
  188. <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
  189. <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
  190. <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
  191. <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
  192. <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
  193. <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
  194. <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
  195. <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
  196. <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
  197. <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
  198. <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
  199. <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
  200. <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
  201. <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
  202. <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
  203. <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
  204. <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
  205. <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
  206. <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
  207. <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
  208. <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
  209. <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
  210. <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
  211. <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
  212. <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
  213. <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
  214. <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
  215. <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
  216. <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
  217. <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
  218. <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
  219. <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
  220. <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
  221. <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
  222. <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
  223. <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
  224. <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
  225. <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
  226. <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
  227. <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
  228. <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
  229. <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
  230. <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
  231. <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
  232. <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
  233. <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
  234. <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
  235. <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
  236. <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
  237. <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
  238. <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
  239. <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
  240. <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
  241. <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
  242. <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
  243. <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
  244. <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
  245. <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
  246. <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
  247. <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
  248. <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
  249. <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
  250. <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
  251. <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
  252. <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
  253. <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
  254. <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
  255. <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
  256. <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
  257. <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
  258. <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
  259. <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
  260. <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
  261. <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
  262. <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
  263. <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
  264. <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
  265. <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
  266. <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
  267. <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
  268. <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
  269. <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
  270. <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
  271. <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
  272. <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
  273. <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
  274. <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
  275. <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
  276. <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
  277. <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
  278. <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
  279. <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
  280. <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
  281. <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
  282. <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
  283. <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
  284. <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
  285. <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
  286. <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
  287. <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
  288. <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
  289. <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
  290. <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
  291. <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
  292. <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
  293. <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
  294. <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
  295. <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
  296. <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
  297. <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
  298. <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
  299. <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
  300. <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
  301. <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
  302. <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
  303. <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
  304. <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
  305. <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
  306. <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
  307. <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
  308. <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
  309. <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
  310. <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
  311. <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
  312. <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
  313. <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
  314. <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
  315. <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
  316. <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
  317. <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
  318. <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
  319. <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
  320. <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
  321. <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
  322. <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
  323. <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
  324. <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
  325. <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
  326. <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
  327. <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
  328. <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
  329. <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
  330. <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
  331. <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
  332. <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
  333. <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
  334. <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
  335. <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
  336. <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
  337. <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
  338. <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
  339. <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
  340. <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
  341. <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
  342. <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
  343. <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
  344. <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
  345. <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
  346. <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
  347. <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
  348. <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
  349. <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
  350. <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
  351. <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
  352. <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
  353. </ogc:Function_Names>
  354. </ogc:Functions>
  355. </ogc:Arithmetic_Operators>
  356. </ogc:Scalar_Capabilities>
  357. </ogc:Filter_Capabilities>
  358. </WFS_Capabilities>
  359. <?php
  360. }
  361. public function _getSchemaLocationString() {
  362. $schemaLocations = array();
  363. // $schemaLocations[] = 'http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
  364. return implode(' ', $schemaLocations);
  365. }
  366. public function _getXmlNamespaceList() {
  367. $baseNsUri = $this->getBaseNamespaceUri();
  368. $namespaceList = $this->_getSourceNsList();
  369. $namespaceListOut = array();
  370. foreach ($namespaceList as $nsObj) {
  371. $ns = "p5_{$nsObj[0]}_{$nsObj[1]}";
  372. $uri = "{$baseNsUri}/{$nsObj[0]}/{$nsObj[1]}";
  373. $namespaceListOut[] = 'xmlns:' . $ns . '="' . $uri . '"';
  374. }
  375. return implode(' ', $namespaceListOut);
  376. }
  377. public function _getSourceNsList() {
  378. $usrObjList = array();
  379. $tblsAcl = $this->_usrAcl->getTablesAcl();
  380. foreach ($tblsAcl as $tblAcl) {
  381. $dataSourceName = 'default_db';// TODO: getSourceName
  382. $tblName = $tblAcl->getName();
  383. $usrObjList[] = array($dataSourceName, $tblName);
  384. }
  385. return $usrObjList;
  386. }
  387. public function _printGetCapabilitiesXml($wfsServerUrl) {
  388. ?>
  389. <GetCapabilities>
  390. <DCPType>
  391. <HTTP>
  392. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
  393. </HTTP>
  394. </DCPType>
  395. <DCPType>
  396. <HTTP>
  397. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  398. </HTTP>
  399. </DCPType>
  400. </GetCapabilities>
  401. <?php
  402. }
  403. public function _printDescribeFeatureTypeXml($wfsServerUrl) {
  404. ?>
  405. <DescribeFeatureType>
  406. <SchemaDescriptionLanguage>
  407. <XMLSCHEMA />
  408. </SchemaDescriptionLanguage>
  409. <DCPType>
  410. <HTTP>
  411. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
  412. </HTTP>
  413. </DCPType>
  414. <DCPType>
  415. <HTTP>
  416. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  417. </HTTP>
  418. </DCPType>
  419. </DescribeFeatureType>
  420. <?php
  421. }
  422. public function _printGetFeatureXml($wfsServerUrl) {
  423. ?>
  424. <GetFeature>
  425. <ResultFormat>
  426. <WFSKMLOutputFormat />
  427. <GML2 />
  428. <GML3 />
  429. <SHAPE-ZIP />
  430. <CSV />
  431. <JSON />
  432. </ResultFormat>
  433. <DCPType>
  434. <HTTP>
  435. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
  436. </HTTP>
  437. </DCPType>
  438. <DCPType>
  439. <HTTP>
  440. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  441. </HTTP>
  442. </DCPType>
  443. </GetFeature>
  444. <?php
  445. }
  446. public function _printTransactionXml($wfsServerUrl) {
  447. ?>
  448. <Transaction>
  449. <DCPType>
  450. <HTTP>
  451. <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
  452. </HTTP>
  453. </DCPType>
  454. <DCPType>
  455. <HTTP>
  456. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  457. </HTTP>
  458. </DCPType>
  459. </Transaction>
  460. <?php
  461. }
  462. public function _printLockFeatureXml($wfsServerUrl) {
  463. ?>
  464. <LockFeature>
  465. <DCPType>
  466. <HTTP>
  467. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
  468. </HTTP>
  469. </DCPType>
  470. <DCPType>
  471. <HTTP>
  472. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  473. </HTTP>
  474. </DCPType>
  475. </LockFeature>
  476. <?php
  477. }
  478. public function _printGetFeatureWithLockXml($wfsServerUrl) {
  479. ?>
  480. <GetFeatureWithLock>
  481. <ResultFormat>
  482. <GML2 />
  483. </ResultFormat>
  484. <DCPType>
  485. <HTTP>
  486. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
  487. </HTTP>
  488. </DCPType>
  489. <DCPType>
  490. <HTTP>
  491. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  492. </HTTP>
  493. </DCPType>
  494. </GetFeatureWithLock>
  495. <?php
  496. }
  497. public function _printFeatureTypeListXml() {
  498. $featureTypes = array();
  499. $tblsAcl = $this->_usrAcl->getTablesAcl();
  500. foreach ($tblsAcl as $tblAcl) {
  501. $dataSourceName = 'default_db';// TODO: getSourceName
  502. $tblName = $tblAcl->getName();
  503. $usrObjList[] = array($dataSourceName, $tblName);
  504. $featureType = array();
  505. $featureType['ns'] = "p5_{$dataSourceName}";
  506. $featureType['Title'] = $tblAcl->getRawLabel();
  507. $featureType['Abstract'] = $tblAcl->getRawLabel();
  508. $featureType['Keywords'] = array();
  509. $featureType['Keywords'][] = $tblAcl->getID();
  510. $featureType['Keywords'][] = $tblName;
  511. $featureType['Keywords'][] = $tblAcl->getRawLabel();
  512. $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
  513. $featureType['SRS'] = "EPSG:4326";
  514. $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
  515. $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
  516. $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
  517. $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
  518. $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
  519. $featureTypes[$tblName] = $featureType;
  520. }
  521. /*
  522. <FeatureType>
  523. <Name>ppr06:AMBITIPAESAGGIO</Name>
  524. <Title>AMBITIPAESAGGIO</Title>
  525. <Abstract />
  526. <Keywords>features, AMBITIPAESAGGIO</Keywords>
  527. <SRS>EPSG:4326</SRS>
  528. <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
  529. </FeatureType>
  530. */
  531. $featureTypesXml = '';
  532. foreach ($featureTypes as $tblName => $feature) {
  533. $featureTypesXml .= '<FeatureType>' . "\n";
  534. $featureTypesXml .= '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
  535. $featureTypesXml .= '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
  536. if (!empty($feature['Abstract'])) {
  537. $featureTypesXml .= '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
  538. } else {
  539. $featureTypesXml .= '<Abstract/>' . "\n";
  540. }
  541. if (!empty($feature['Keywords'])) {
  542. $featureTypesXml .= '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
  543. } else {
  544. $featureTypesXml .= '<Keywords/>' . "\n";
  545. }
  546. $featureTypesXml .= '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
  547. if (!empty($feature['LatLongBoundingBox'])) {
  548. $latLongBoundingBoxOut = array();
  549. $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
  550. $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
  551. $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
  552. $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
  553. $featureTypesXml .= '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />';
  554. }
  555. $featureTypesXml .= '</FeatureType>' . "\n";
  556. }
  557. return $featureTypesXml;
  558. }
  559. public function _parseTransactionXmlStruct($requestXml, $requestXmlTags) {
  560. $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
  561. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  562. if ('Transaction' != $rootTagName) {
  563. throw new Exception("Parse Request xml error #" . __LINE__);
  564. }
  565. // 1. convert request: wfs.transaction.convert-wfs-request.xsl
  566. // 2. validate converted request: wfs.transaction-converted-request.xsd
  567. // 3. execute request in data source
  568. // ? acl check?
  569. $usedSourceNsList = array();
  570. $sourceNsList = $this->_getSourceNsList();
  571. //$sourceNsList = array();
  572. //foreach ($requestXmlTags[0]['attributes'] as $attrName => $attrValue) {
  573. // if ('xmlns:p5_' == substr($attrName, 0, 9)) {
  574. // $sourceNsList[substr($attrName, 6)] = $attrValue;
  575. // }
  576. //}
  577. {// get used typeNames
  578. $usedTypeNames = array();
  579. // <Update xmlns="http://www.opengis.net/wfs" typeName="p5_default_db:TEST_PERMS">
  580. foreach ($requestXmlTags as $tag) {
  581. if ('Update' == $tag['tag'] && 'open' == $tag['type']) {
  582. $typeName = $tag['attributes']['typeName'];
  583. foreach ($sourceNsList as $nsInd => $ns) {
  584. if ("p5_{$ns[0]}:{$ns[1]}" == $typeName) {
  585. $usedSourceNsList[$nsInd] = $ns;
  586. }
  587. }
  588. }
  589. }
  590. // TODO: check: <Transaction xmlns:p5_default_db="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS"
  591. // <Insert xmlns="http://www.opengis.net/wfs">
  592. // <TEST_PERMS xmlns="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS">
  593. $lastTagName = '';
  594. foreach ($requestXmlTags as $tag) {
  595. if ('Insert' == $lastTagName) {
  596. $typeName = $tag['tag'];
  597. foreach ($sourceNsList as $nsInd => $ns) {
  598. if ("{$ns[1]}" == $typeName) {
  599. $usedSourceNsList[$nsInd] = $ns;
  600. }
  601. }
  602. }
  603. $lastTagName = $tag['tag'];
  604. }
  605. }
  606. if (empty($usedSourceNsList)) {
  607. throw new Exception("Parse Request xml error #" . __LINE__ . ": not implemented");
  608. }
  609. $convertedTransaction = $this->_convertTransactionXml($requestXml, $usedSourceNsList);
  610. if($DBG){echo '$convertedTransaction:';print_r($convertedTransaction);echo "\n";}
  611. if (empty($convertedTransaction)) {
  612. throw new Exception("Parse Request xml error #" . __LINE__ . ": convert Transaction");
  613. }
  614. //echo "\ntags[0]:\n" . json_encode($requestXmlTags[0]) . "\n";
  615. //echo "\nconvertedTransaction:\n" . $convertedTransaction . "\n";
  616. //echo "\nsourceNsList:\n" . json_encode($sourceNsList) . "\n";
  617. if (!$this->_validateConvertedTransactionXml($convertedTransaction, $usedSourceNsList)) {
  618. throw new Exception("Parse Request xml error #" . __LINE__ . ": schema validation failed");
  619. }
  620. $parserXml = xml_parser_create();
  621. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  622. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  623. if (0 == xml_parse_into_struct($parserXml, $convertedTransaction, $tags)) {
  624. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction failed");
  625. }
  626. xml_parser_free($parserXml);
  627. if (empty($tags)) {
  628. throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction returns empty structure");
  629. }
  630. // [{"tag":"Transaction","type":"open","level":1,"attributes":{"version":"1.0.0","service":"WFS"}},
  631. // {"tag":"Update","type":"open","level":2,"attributes":
  632. // {"typeName":"p5_default_db_13051:TEST_PERMS","featureId":"TEST_PERMS.25"}},
  633. // {"tag":"PARENT_ID","type":"complete","level":3,"value":"0"},
  634. // {"tag":"Update","type":"close","level":2},
  635. // {"tag":"Transaction","type":"close","level":1}]
  636. if($DBG){echo "\nTODO: tags L." . __LINE__ . ":\n"; print_r($tags);echo "\n";}
  637. $actionTag = null;
  638. $prevTagName = '';
  639. $theGeomField = 'the_geom';// TODO: get the geom field name from acl
  640. $itemPatchs = array();
  641. foreach ($tags as $tag) {
  642. switch (substr($tag['tag'], 0, 6)) {
  643. case 'Transa': continue; break;// Transaction
  644. case 'Update':
  645. case 'Insert':
  646. case 'Delete':
  647. case 'Native':
  648. if ('open' == $tag['type']) {
  649. $actionTag = array();
  650. $actionTag['tag'] = substr($tag['tag'], 0, 6);
  651. $actionTag['typeName'] = $tag['attributes']['typeName'];
  652. if ('Insert' == substr($tag['tag'], 0, 6)) {
  653. $actionTag['typeName'] = "p5_default_db:{$actionTag['typeName']}";
  654. }
  655. $featureEx = explode('.', $tag['attributes']['featureId'], 2);
  656. $actionTag['featureId'] = $featureEx[1];
  657. if ('Update' == substr($tag['tag'], 0, 6) && empty($actionTag['featureId'])) {
  658. throw new Api_WfsException("Syntax error - could not read feature id!");
  659. }
  660. $actionTag['itemPatch'] = array();
  661. } else {
  662. $itemPatchs[] = $actionTag;
  663. $actionTag = null;
  664. }
  665. break;
  666. default: {// fields
  667. if (3 != $tag['level'] && 'close' == $tag['type']) {
  668. $actionTag = null;
  669. }
  670. if (3 != $tag['level']) continue;
  671. if (empty($actionTag)) continue;
  672. if ('Update' == $actionTag['tag']) {
  673. if ($theGeomField == $tag['tag']) {
  674. $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
  675. } else {
  676. $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
  677. }
  678. }
  679. else if ('Insert' == $actionTag['tag']) {
  680. if ($theGeomField == $tag['tag']) {
  681. $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
  682. } else {
  683. $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
  684. }
  685. }
  686. }
  687. }
  688. if (empty($prevTagName)) $prevTagName = $tag['tag'];
  689. }
  690. if($DBG){echo "\nTODO: itemPatchs L." . __LINE__ . ":\n"; print_r($itemPatchs);echo "\n";}
  691. if($DBG){echo "\nTODO: _user_id L." . __LINE__ . ":\n"; print_r($this->_usrAcl->_user_id);echo "\n";}
  692. $changesList = array();
  693. if (!empty($itemPatchs)) {
  694. foreach ($itemPatchs as $itemPatchInfo) {
  695. if($DBG){echo "itemPatchInfo['itemPatch']:\n";print_r($itemPatchInfo['itemPatch']);}
  696. if (empty($itemPatchInfo['itemPatch'])) continue;
  697. $acl = $this->getAclFromTypeName($itemPatchInfo['typeName']);
  698. $itemPatch = $itemPatchInfo['itemPatch'];
  699. if ('Update' == $itemPatchInfo['tag']) {
  700. $itemPatch[$acl->getPrimaryKeyField()] = $itemPatchInfo['featureId'];
  701. }
  702. else if ('Insert' == $itemPatchInfo['tag']) {
  703. if (!empty($itemPatch[$acl->getPrimaryKeyField()])) {
  704. $itemPatchInfo['featureId'] = $itemPatch[$acl->getPrimaryKeyField()];
  705. }
  706. else {
  707. //throw new Exception("TODO: Insert #" . __LINE__ . ": Create new record");
  708. }
  709. }
  710. if($DBG){echo "TODO '" . ($itemPatchInfo['tag'])? 'Insert' : 'Update' . "' itemPatch:\n";print_r($itemPatch);}
  711. if ('Insert' == $itemPatchInfo['tag'] && empty($itemPatch[$acl->getPrimaryKeyField()])) {
  712. $newId = $acl->addItem($itemPatch);
  713. $changesList[$newId] = array('Status'=>(($newId > 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"created {$newId}.");
  714. if ($newId > 0) {
  715. $changesList[$newId]['fid'] = $acl->getName() . '.' . $newId;
  716. }
  717. if($DBG){echo "created {$newId}.\n";}
  718. } else {
  719. $affected = $acl->updateItem($itemPatch);
  720. $changesList[$itemPatchInfo['featureId']] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"affected {$affected}.");
  721. if($DBG){echo "affected {$affected}.\n";}
  722. }
  723. }
  724. //throw new Exception("TODO: run query #" . __LINE__ . " \nitemPatchs:\n" . json_encode($itemPatchs) . " \ntags:\n" . json_encode($tags) . "\n");
  725. }
  726. else {
  727. throw new Exception("Parse Request xml error #" . __LINE__ . ": Nothing to change");
  728. }
  729. return $this->_transactionResponse($changesList);
  730. }
  731. public function _transactionResponse($changesList) {
  732. // <WFS_TransactionResponse>
  733. // <TransactionResult>
  734. // <Status> : SUCCESS / FAILED / PARTIAL
  735. // [<Locator]
  736. // [<Message]
  737. $messageTag = '';
  738. $statusTag = '';
  739. $statusIsFailed = false;
  740. $statusAll = null;
  741. $createdFetureId = '';
  742. foreach ($changesList as $featureId => $change) {
  743. if ('FAILED' == $change['Status']) {
  744. $statusIsFailed = true;
  745. }
  746. if ('SUCCESS' == $change['Status'] && !empty($change['fid'])) {
  747. $createdFetureId = $change['fid'];
  748. }
  749. if (!empty($change['Message'])) $messageTag .= "Feature '{$featureId}' {$change['Status']}: {$change['Message']}\n";
  750. }
  751. $statusTag = ($statusIsFailed)? 'FAILED' : 'SUCCESS';
  752. $statusTag = "<wfs:{$statusTag}/>";
  753. $messageTag = '';//"<wfs:Message>{$messageTag}</wfs:Message>";
  754. /* Example:
  755. <?xml version="1.0" encoding="UTF-8"?>
  756. <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
  757. xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  758. xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd">
  759. <wfs:InsertResult>
  760. <ogc:FeatureId fid="archsites.26" />
  761. </wfs:InsertResult>
  762. <wfs:TransactionResult handle="Updating Signature rock label">
  763. <wfs:Status>
  764. <wfs:SUCCESS />
  765. </wfs:Status>
  766. </wfs:TransactionResult>
  767. </wfs:WFS_TransactionResponse>*/
  768. // TODO: build xml by DOMDocument
  769. // TODO: xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd"
  770. $wfsInsertResult = '';
  771. if (!empty($createdFetureId)) {
  772. $wfsInsertResult = <<<EOF
  773. <wfs:InsertResult>
  774. <ogc:FeatureId fid="{$createdFetureId}" xmlns:ogc="http://www.opengis.net/ogc"/>
  775. </wfs:InsertResult>
  776. EOF;
  777. }
  778. $tranRes = <<<EOF
  779. <wfs:WFS_TransactionResponse version="1.0.0"
  780. xmlns:wfs="http://www.opengis.net/wfs"
  781. xmlns:ogc="http://www.opengis.net/ogc"
  782. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  783. {$wfsInsertResult}
  784. <wfs:TransactionResult>
  785. <wfs:Status>{$statusTag}</wfs:Status>
  786. {$messageTag}
  787. </wfs:TransactionResult>
  788. </wfs:WFS_TransactionResponse>
  789. EOF;
  790. return $tranRes;
  791. }
  792. public function _convertTransactionXml($requestXmlString, $sourceNsList) {
  793. $DBG = (V::get('DBG_XSL', '', $_GET) > 0);// TODO: Profiler
  794. if($DBG){echo 'sourceNsList:';print_r($sourceNsList);echo "\n";}
  795. $updateActionsXsd = array();
  796. $insertActionsXsd = array();
  797. //<!-- TODO: create tag Update{X} where X is namespace index -->
  798. foreach ($sourceNsList as $nsInd => $sourceNs) {
  799. // <Update>
  800. $theGeomField = 'the_geom';// TODO: get from fields list
  801. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  802. $updateElementName = "UpdateNs{$nsInd}";
  803. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  804. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  805. $acl = $this->getAclFromTypeName($typeName);
  806. $geomType = $acl->getGeomFieldType($theGeomField);
  807. if ('polygon' == $geomType) {
  808. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  809. $geomCoordsUpdateXpath = "((<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>))";
  810. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  811. $geomCoordsInsertXpath = "((<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>))";
  812. } else if ('linestring' == $geomType) {
  813. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:coordinates";
  814. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  815. $geomCoordsInsertXpath = "//*/gml:coordinates";
  816. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  817. } else if ('point' == $geomType) {
  818. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:coordinates";
  819. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  820. $geomCoordsInsertXpath = "//*/gml:coordinates";
  821. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  822. }
  823. $actionXsd = <<<EOF
  824. <xsl:when test="@typeName = '{$typeName}'">
  825. <xsl:element name="{$updateElementName}">
  826. <xsl:attribute name="typeName"><xsl:value-of select="@typeName" /></xsl:attribute>
  827. <xsl:attribute name="featureId"><xsl:value-of select="ogc:Filter/ogc:FeatureId/@fid" /></xsl:attribute>
  828. <xsl:for-each select="wfs:Property">
  829. <xsl:element name="{wfs:Name}">
  830. <xsl:choose>
  831. <xsl:when test="wfs:Name = '{$theGeomField}'"><xsl:value-of select="local-name(//wfs:Value/*[1])"/>{$geomCoordsUpdateXpath}</xsl:when>
  832. <xsl:otherwise><xsl:value-of select="wfs:Value"/></xsl:otherwise>
  833. </xsl:choose>
  834. </xsl:element>
  835. </xsl:for-each>
  836. </xsl:element>
  837. </xsl:when>
  838. EOF;
  839. $updateActionsXsd[] = $actionXsd;
  840. $typeName = "{$sourceNs[1]}";//"p5_{$sourceNs[0]}:{$sourceNs[1]}";
  841. $insertElementName = "InsertNs{$nsInd}";
  842. $actionXsd = <<<EOF
  843. <xsl:when test="local-name() = '{$typeName}'">
  844. <xsl:element name="{$insertElementName}">
  845. <xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
  846. <xsl:for-each select="*">
  847. <xsl:element name="{local-name()}">
  848. <xsl:choose>
  849. <xsl:when test="local-name() = '{$theGeomField}'"><xsl:value-of select="local-name(*[1])"/>{$geomCoordsInsertXpath}</xsl:when>
  850. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  851. </xsl:choose>
  852. </xsl:element>
  853. </xsl:for-each>
  854. </xsl:element>
  855. </xsl:when>
  856. EOF;
  857. $insertActionsXsd[] = $actionXsd;
  858. }
  859. if (!empty($updateActionsXsd)) {
  860. $updateActionsXsd = implode("\n", $updateActionsXsd);
  861. $updateActionsXsd = <<<EOF
  862. <xsl:choose>
  863. {$updateActionsXsd}
  864. </xsl:choose>
  865. EOF;
  866. } else {
  867. $updateActionsXsd = '';
  868. }
  869. if (!empty($insertActionsXsd)) {
  870. $insertActionsXsd = implode("\n", $insertActionsXsd);
  871. $insertActionsXsd = <<<EOF
  872. <xsl:choose>
  873. {$insertActionsXsd}
  874. </xsl:choose>
  875. EOF;
  876. } else {
  877. $insertActionsXsd = '';
  878. }
  879. $convertTransactionXslString = <<<EOF
  880. <?xml version="1.0"?>
  881. <xsl:transform version="1.0"
  882. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  883. xmlns:wfs="http://www.opengis.net/wfs"
  884. xmlns:ogc="http://www.opengis.net/ogc"
  885. xmlns:gml="http://www.opengis.net/gml">
  886. <xsl:template match="/">
  887. <xsl:for-each select="wfs:Transaction">
  888. <Transaction>
  889. <xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
  890. <xsl:attribute name="service"><xsl:value-of select="@service" /></xsl:attribute>
  891. <xsl:for-each select="wfs:Update">
  892. {$updateActionsXsd}
  893. </xsl:for-each>
  894. <!-- TODO: Insert -->
  895. <xsl:for-each select="wfs:Insert/*">
  896. {$insertActionsXsd}
  897. </xsl:for-each>
  898. <!-- TODO: Delete -->
  899. <!-- TODO: Native -->
  900. </Transaction>
  901. </xsl:for-each>
  902. </xsl:template>
  903. </xsl:transform>
  904. EOF;
  905. if($DBG){echo '$convertTransactionXslString:' . $convertTransactionXslString . "\n";}
  906. $requestXml = new DOMDocument();
  907. $requestXml->loadXml($requestXmlString);
  908. $convertTransactionXsl = new DOMDocument();
  909. $convertTransactionXsl->loadXml($convertTransactionXslString);
  910. $proc = new XSLTProcessor();
  911. $proc->importStylesheet($convertTransactionXsl);
  912. return $proc->transformToXML($requestXml);
  913. }
  914. public function _validateConvertedTransactionXml($convertedTransaction, $sourceNsList) {
  915. $DBG = (V::get('DBG_XSD', '', $_GET) > 0);// TODO: Profiler
  916. if($DBG){echo 'sourceNsList:';print_r($sourceNsList);echo "\n";}
  917. $dom = new DOMDocument('1.0', 'utf-8');
  918. $dom->formatOutput = true;
  919. $dom->preserveWhiteSpace = false;
  920. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  921. $dom->appendChild($rootNode);
  922. // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  923. // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
  924. $rootNode->setAttribute('elementFormDefault', 'qualified');
  925. // $rootNode->setAttribute('targetNamespace', $wfsNsUri);
  926. $rootNode->setAttribute('version', '1.0');
  927. {// <xsd:element name="Transaction" type="TransactionType">
  928. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  929. $rootNode->appendChild($elNode);
  930. $elNode->setAttribute('name', 'Transaction');
  931. $elNode->setAttribute('type', 'TransactionType');
  932. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  933. $rootNode->appendChild($cTypeNode);
  934. $cTypeNode->setAttribute('name', 'TransactionType');
  935. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  936. $cTypeNode->appendChild($seqNode);
  937. $choiceNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:choice');
  938. $seqNode->appendChild($choiceNode);
  939. $choiceNode->setAttribute('minOccurs', '0');
  940. $choiceNode->setAttribute('maxOccurs', 'unbounded');
  941. // <!-- <xsd:element ref="Update"/> -->
  942. foreach ($sourceNsList as $nsInd => $sourceNs) {
  943. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  944. $updateElementName = "UpdateNs{$nsInd}";
  945. $updateElementType = "UpdateNs{$nsInd}ElementType";
  946. $updateElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  947. $choiceNode->appendChild($updateElemNode);
  948. $updateElemNode->setAttribute('name', $updateElementName);
  949. $updateElemNode->setAttribute('type', $updateElementType);
  950. }
  951. // <!-- <xsd:element ref="Insert"/> -->
  952. foreach ($sourceNsList as $nsInd => $sourceNs) {
  953. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  954. $insertElementName = "InsertNs{$nsInd}";
  955. $insertElementType = "InsertNs{$nsInd}ElementType";
  956. $insertElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  957. $choiceNode->appendChild($insertElemNode);
  958. $insertElemNode->setAttribute('name', $insertElementName);
  959. $insertElemNode->setAttribute('type', $insertElementType);
  960. }
  961. // <!-- <xsd:element ref="Delete"/> -->
  962. // <!-- <xsd:element ref="Native"/> -->
  963. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  964. $cTypeNode->appendChild($attrNode);
  965. $attrNode->setAttribute('name', 'version');
  966. $attrNode->setAttribute('type', 'xsd:string');
  967. $attrNode->setAttribute('use', 'required');
  968. $attrNode->setAttribute('fixed', '1.0.0');
  969. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  970. $cTypeNode->appendChild($attrNode);
  971. $attrNode->setAttribute('name', 'service');
  972. $attrNode->setAttribute('type', 'xsd:string');
  973. $attrNode->setAttribute('use', 'required');
  974. $attrNode->setAttribute('fixed', 'WFS');
  975. }
  976. foreach ($sourceNsList as $nsInd => $sourceNs) {
  977. $transactionTypesList = array();
  978. $transactionTypesList[] = 'Update';
  979. $transactionTypesList[] = 'Insert';
  980. foreach ($transactionTypesList as $transactionType) {
  981. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  982. $acl = $this->getAclFromTypeName($typeName);
  983. $updateElementName = "{$transactionType}Ns{$nsInd}";
  984. $updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
  985. /*
  986. <xsd:complexType name="{$updateElementType}">
  987. <xsd:sequence>
  988. <xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />
  989. </xsd:sequence>
  990. */
  991. $updateTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  992. $rootNode->appendChild($updateTypeNode);
  993. $updateTypeNode->setAttribute('name', $updateElementType);
  994. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  995. $updateTypeNode->appendChild($seqNode);
  996. $pKeyField = $acl->getPrimaryKeyField();
  997. $fldList = $acl->getRealFieldList();
  998. foreach ($fldList as $fldName) {
  999. if ($acl->isGeomField($fldName)) continue;
  1000. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1001. $seqNode->appendChild($elNode);
  1002. $elNode->setAttribute('name', $fldName);
  1003. $minOccurs = 0;
  1004. if ($pKeyField == $fldName) {
  1005. $minOccurs = '1';
  1006. } else {
  1007. $minOccurs = '0';
  1008. }
  1009. $elNode->setAttribute('minOccurs', $minOccurs);
  1010. $fldType = null;
  1011. if ($acl->isIntegerField($fldName)) {
  1012. $fldType = 'xsd:integer';
  1013. }
  1014. else if ($acl->isDecimalField($fldName)) {
  1015. $fldType = 'xsd:decimal';
  1016. }
  1017. else if ($acl->isDateField($fldName)) {
  1018. $fldType = 'xsd:date';
  1019. }
  1020. else if ($acl->isDateTimeField($fldName)) {
  1021. $fldType = 'xsd:dateTime';
  1022. }
  1023. else if ($acl->isGeomField($fldName)) {
  1024. //$fldType = 'gml:GeometryPropertyType';
  1025. // TODO: use geom types from gml to wkt
  1026. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  1027. $patternWkt = '';// TODO: error if empty - unsupported geom type
  1028. $patternNum = '\-?\d+\.?\d*';
  1029. $patternPoint = $patternNum . ',' . $patternNum;
  1030. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  1031. $geomType = $acl->getGeomFieldType($fldName);
  1032. if ('polygon' == $geomType) {
  1033. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  1034. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  1035. } else if ('linestring' == $geomType) {
  1036. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  1037. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  1038. } else if ('point' == $geomType) {
  1039. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  1040. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  1041. }
  1042. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1043. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1044. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1045. $restrictionNode->setAttribute('base', 'xsd:string');
  1046. $patternNode->setAttribute('value', $patternWkt);
  1047. $restrictionNode->appendChild($patternNode);
  1048. $simpleTypeNode->appendChild($restrictionNode);
  1049. $elNode->appendChild($simpleTypeNode);
  1050. }
  1051. else {
  1052. $fldType = 'xsd:string';
  1053. }
  1054. if ($fldType) $elNode->setAttribute('type', $fldType);
  1055. $elNode->setAttribute('nillable', 'true');
  1056. $elNode->setAttribute('minOccurs', '0');
  1057. }
  1058. foreach ($fldList as $fldName) {
  1059. if (!$acl->isGeomField($fldName)) continue;
  1060. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1061. $seqNode->appendChild($elNode);
  1062. $elNode->setAttribute('name', $fldName);
  1063. $minOccurs = 0;
  1064. if ($pKeyField == $fldName) {
  1065. $minOccurs = '1';
  1066. } else {
  1067. $minOccurs = '0';
  1068. }
  1069. $elNode->setAttribute('minOccurs', $minOccurs);
  1070. if ($acl->isGeomField($fldName)) {
  1071. //$fldType = 'gml:GeometryPropertyType';
  1072. // TODO: use geom types from gml to wkt
  1073. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  1074. $patternWkt = '';// TODO: error if empty - unsupported geom type
  1075. $patternNum = '\-?\d+\.?\d*';
  1076. $patternPoint = $patternNum . ',' . $patternNum;
  1077. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  1078. $geomType = $acl->getGeomFieldType($fldName);
  1079. if ('polygon' == $geomType) {
  1080. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  1081. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  1082. } else if ('linestring' == $geomType) {
  1083. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  1084. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  1085. } else if ('point' == $geomType) {
  1086. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  1087. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  1088. }
  1089. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1090. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1091. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1092. $restrictionNode->setAttribute('base', 'xsd:string');
  1093. $patternNode->setAttribute('value', $patternWkt);
  1094. $restrictionNode->appendChild($patternNode);
  1095. $simpleTypeNode->appendChild($restrictionNode);
  1096. $elNode->appendChild($simpleTypeNode);
  1097. }
  1098. $elNode->setAttribute('nillable', 'true');
  1099. $elNode->setAttribute('minOccurs', '0');
  1100. }
  1101. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1102. $updateTypeNode->appendChild($attrNode);
  1103. $attrNode->setAttribute('name', 'typeName');
  1104. $attrNode->setAttribute('type', 'xsd:token');
  1105. $attrNode->setAttribute('use', 'required');
  1106. if ($transactionType == 'Update') {
  1107. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1108. $updateTypeNode->appendChild($attrNode);
  1109. $attrNode->setAttribute('name', 'featureId');
  1110. $attrNode->setAttribute('use', 'required');
  1111. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1112. $attrNode->appendChild($sTypeNode);
  1113. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1114. $sTypeNode->appendChild($resNode);
  1115. $resNode->setAttribute('base', 'xsd:string');
  1116. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1117. $resNode->appendChild($patternNode);
  1118. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1119. }
  1120. }
  1121. }
  1122. $validateConvertedTransactionXsdString = $dom->saveXml();
  1123. if($DBG){echo '$validateConvertedTransactionXsdString:';print_r($validateConvertedTransactionXsdString);echo "\n";}
  1124. $reqXml = new DOMDocument();
  1125. $reqXml->loadXml($convertedTransaction);
  1126. // TODO: fetch PHP Warning: DOMDocument::schemaValidateSource(): Element 'PARENT_ID': 'abc' is not a valid value of the atomic type 'xs:integer'.
  1127. return $reqXml->schemaValidateSource($validateConvertedTransactionXsdString);
  1128. }
  1129. public function _generateXsdTypeNode($ns, $typeName, $dom, $parentNode) {
  1130. //$fieldsXsd = '';
  1131. //$fieldsXsd .= '<xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />';
  1132. $acl = $this->getAclFromTypeName($typeName);
  1133. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1134. $rootNode = $cTypeNode;
  1135. $cTypeNode->setAttribute('name', $typeName);
  1136. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  1137. $cTypeNode->appendChild($cConNode);
  1138. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  1139. $cConNode->appendChild($extNode);
  1140. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  1141. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');// or xsd:all ?
  1142. $extNode->appendChild($seqNode);
  1143. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  1144. $pKeyField = $acl->getPrimaryKeyField();
  1145. $fldList = $acl->getRealFieldList();
  1146. foreach ($fldList as $fldName) {
  1147. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1148. $seqNode->appendChild($elNode);
  1149. $elNode->setAttribute('name', $fldName);
  1150. $minOccurs = 0;
  1151. if ($pKeyField == $fldName) {
  1152. $minOccurs = '1';
  1153. } else {
  1154. $minOccurs = '0';
  1155. }
  1156. $elNode->setAttribute('minOccurs', $minOccurs);
  1157. if ($acl->isIntegerField($fldName)) {
  1158. $fldType = 'xsd:integer';
  1159. }
  1160. else if ($acl->isDecimalField($fldName)) {
  1161. $fldType = 'xsd:decimal';
  1162. }
  1163. else if ($acl->isDateField($fldName)) {
  1164. $fldType = 'xsd:date';
  1165. }
  1166. else if ($acl->isDateTimeField($fldName)) {
  1167. $fldType = 'xsd:dateTime';
  1168. }
  1169. else if ($acl->isGeomField($fldName)) {
  1170. $fldType = 'gml:GeometryPropertyType';
  1171. //$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
  1172. }
  1173. else {
  1174. $fldType = 'xsd:string';
  1175. }
  1176. $elNode->setAttribute('type', $fldType);
  1177. $elNode->setAttribute('nillable', 'true');
  1178. }
  1179. /*
  1180. <xsd:attribute name="typeName" type="xsd:token" use="required"/>
  1181. <xsd:attribute name="featureId" use="required">
  1182. <xsd:simpleType>
  1183. <xsd:restriction base="xsd:string">
  1184. <xsd:pattern value="[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*"/>
  1185. </xsd:restriction>
  1186. </xsd:simpleType>
  1187. </xsd:attribute>
  1188. */
  1189. $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1190. $rootNode->appendChild($cAttrNode);
  1191. $cAttrNode->setAttribute('name', 'typeName');
  1192. $cAttrNode->setAttribute('type', 'xsd:token');
  1193. $cAttrNode->setAttribute('use', 'required');
  1194. $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1195. $rootNode->appendChild($cAttrNode);
  1196. $cAttrNode->setAttribute('name', 'featureId');
  1197. $cAttrNode->setAttribute('use', 'required');
  1198. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1199. $cAttrNode->appendChild($sTypeNode);
  1200. $restrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1201. $cAttrNode->appendChild($restrNode);
  1202. $restrNode->setAttribute('base', 'xsd:string');
  1203. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1204. $restrNode->appendChild($patternNode);
  1205. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1206. return $dom->saveXml($cTypeNode);
  1207. $typeXsd = <<<EOF
  1208. <xsd:complexType name="{$typeName}">
  1209. <xsd:all>
  1210. {$fieldsXsd}
  1211. </xsd:all>
  1212. <xsd:attribute name="typeName" type="xsd:token" use="required"/>
  1213. <xsd:attribute name="featureId" use="required">
  1214. <xsd:simpleType>
  1215. <xsd:restriction base="xsd:string">
  1216. <xsd:pattern value="[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*"/>
  1217. </xsd:restriction>
  1218. </xsd:simpleType>
  1219. </xsd:attribute>
  1220. </xsd:complexType>
  1221. EOF;
  1222. return $typeXsd;
  1223. }
  1224. }