convertGuiXmlToFiltersXML.xsl 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:ui_table="https://biuro.biall-net.pl/SE/version-git/schema/gui/table.gui.xsd"
  5. xmlns:ogc="http://www.opengis.net/ogc"
  6. >
  7. <!-- xmlns:p5_36_TEST_PERMS="https://biuro.biall-net.pl/api/36/TEST_PERMS" -->
  8. <!-- import namespaces from xsd xmlns:p5_36_TEST_PERMS="https://biuro.biall-net.pl/api/36/TEST_PERMS" -->
  9. <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
  10. <!-- from Data_Source
  11. sf_Problemy
  12. $fltrs['Problemy'] = new stdClass();
  13. $fltrs['Problemy']->icon = 'glyphicon glyphicon-warning-sign';
  14. $fltrs['Problemy']->btns = array();
  15. $fltrs['Problemy']->btns['PROBLEMY'] = (object)array('value'=>'PROBLEM');
  16. $fltrs['Problemy']->btns['OSTRZEZENIA'] = (object)array('value'=>'WARNING');
  17. $fltrs['Problemy']->btns['BEZ_PROBLEM.'] = (object)array('value'=>'NORMAL');
  18. sf_Status
  19. $fltrs['Status'] = new stdClass();
  20. $fltrs['Status']->icon = 'glyphicon glyphicon-question-sign';
  21. $fltrs['Status']->btns = array();
  22. $fltrs['Status']->btns['OCZEKUJACY'] = (object)array('value'=>'WAITING');
  23. $fltrs['Status']->btns['AKTYWNI'] = (object)array('value'=>'AKTYWNI');
  24. sf_Spotkania
  25. $fltrs['Spotkania'] = new stdClass();
  26. $fltrs['Spotkania']->icon = 'glyphicon glyphicon-calendar';
  27. $fltrs['Spotkania']->btns = array();
  28. $fltrs['Spotkania']->btns['STARE'] = (object)array('value'=>'OLD');
  29. $fltrs['Spotkania']->btns['ZARAZ'] = (object)array('value'=>'NOW');
  30. $fltrs['Spotkania']->btns['DZISIAJ'] = (object)array('value'=>'TODAY');
  31. $fltrs['Spotkania']->btns['BRAK'] = (object)array('value'=>'BRAK');
  32. sf_Access
  33. $fltrs['Access'] = new stdClass();
  34. $fltrs['Access']->icon = 'glyphicon glyphicon-lock';
  35. $fltrs['Access']->btns = array();
  36. $fltrs['Access']->btns['Pokaż'] = (object)array('value'=>'SHOW');
  37. -->
  38. <!-- from Data_Source
  39. sf_Problemy
  40. case 'Problemy':
  41. if (array_key_exists('A_PROBLEM', $this->_cols)) {
  42. switch ($value) {
  43. case 'PROBLEM':
  44. $sqlFltr = " t.`A_PROBLEM`!='' ";
  45. break;
  46. case 'WARNING':
  47. $sqlFltr = " t.`A_PROBLEM`='WARNING' ";
  48. break;
  49. case 'NORMAL':
  50. $sqlFltr = " t.`A_PROBLEM`='' ";
  51. break;
  52. }
  53. }
  54. break;
  55. case 'Status':
  56. if (array_key_exists('A_STATUS', $this->_cols)) {
  57. switch ($value) {
  58. case 'WAITING':
  59. $sqlFltr = " t.`A_STATUS`='WAITING' ";
  60. break;
  61. case 'AKTYWNI':
  62. $sqlFltr = " t.`A_STATUS` in('NORMAL', 'WARNING') ";
  63. // TODO: $_SESSION['USERS_FILTER_STATUS_SQL']="and (( $thiss->DETECT_TABLE_NAME.A_STATUS='NORMAL' or $thiss->DETECT_TABLE_NAME.A_STATUS='WARNING' ) or ( $thiss->DETECT_TABLE_NAME.A_STATUS='OFF_SOFT' and $thiss->DETECT_TABLE_NAME.A_PROBLEM_DESC not like '%odla%fizy%' and $thiss->DETECT_TABLE_NAME.A_PROBLEM!='' ) or ( $thiss->DETECT_TABLE_NAME.A_STATUS='OFF_SOFT' and $thiss->DETECT_TABLE_NAME.A_PROBLEM='' )) ";
  64. // if ($thiss->DETECT_TABLE_NAME == 'KSIEG_DOKUMENTY') $_SESSION['USERS_FILTER_STATUS_SQL']="and ( $thiss->DETECT_TABLE_NAME.A_STATUS='NORMAL' or $thiss->DETECT_TABLE_NAME.A_STATUS='WARNING' ) ";
  65. break;
  66. }
  67. }
  68. break;
  69. case 'Spotkania':
  70. if (array_key_exists('L_APPOITMENT_DATE', $this->_cols)) {
  71. switch ($value) {
  72. case 'OLD':
  73. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now()) and t.`L_APPOITMENT_DATE`!='' ";
  74. break;
  75. case 'NOW':
  76. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now())+3600 and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>UNIX_TIMESTAMP(now())-3600 ";
  77. break;
  78. case 'TODAY':
  79. $start = mktime(0,0,0, date("m"), date("d"), date("Y"));
  80. $end = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
  81. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  82. break;
  83. case 'TOMORROW':
  84. $start = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
  85. $end = mktime(0,0,0, date("m"), date("d") + 2, date("Y"));
  86. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  87. break;
  88. case 'YESTERDAY':
  89. $start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
  90. $end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
  91. $sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
  92. break;
  93. case 'BRAK':
  94. $start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
  95. $end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
  96. $sqlFltr = " t.`L_APPOITMENT_DATE`='' ";
  97. break;
  98. }
  99. }
  100. break;
  101. case 'Access':
  102. if ('SHOW' != $value && $this->isAccessFltrAllowed()) {
  103. $userLogin = User::getLogin();
  104. $usrAclGroups = User::getLdapGroupsNames();
  105. $usrAclGroups[] = '';// TODO: allow empty for everyone?
  106. $sqlUsrAclGroups = "'" . implode("','", $usrAclGroups) . "'";
  107. $sqlFltr = "
  108. t.`{$this->_fieldGroupWrite}` in({$sqlUsrAclGroups})
  109. and t.`{$this->_fieldGroupRead}` in({$sqlUsrAclGroups})
  110. ";
  111. if (array_key_exists('L_APPOITMENT_USER', $this->_cols)) {
  112. $sqlFltr = "
  113. (
  114. ({$sqlFltr})
  115. or t.`L_APPOITMENT_USER`='{$userLogin}'
  116. )
  117. ";
  118. }
  119. }
  120. -->
  121. <!-- $sqlFltr = " t.`A_STATUS`='WAITING' "; -->
  122. <!-- $sqlFltr = " t.`A_STATUS` in('NORMAL', 'WARNING') "; -->
  123. <!-- $sqlFltr = " (t.`A_STATUS`='NORMAL' or t.`A_STATUS`='WARNING') "; -->
  124. <!-- in('NORMAL', 'WARNING') -->
  125. <!-- ogc:Filter example:
  126. <ogc:Filter>
  127. <ogc:And>
  128. <ogc:Or>
  129. <ogc:PropertyIsEqualTo>
  130. <ogc:PropertyName>ID</ogc:PropertyName>
  131. <ogc:Literal>98400005701</ogc:Literal>
  132. </ogc:PropertyIsEqualTo>
  133. <ogc:PropertyIsEqualTo>
  134. <ogc:PropertyName>ID</ogc:PropertyName>
  135. <ogc:Literal>-1</ogc:Literal>
  136. </ogc:PropertyIsEqualTo>
  137. </ogc:Or>
  138. <ogc:And>
  139. <ogc:PropertyIsLessThanOrEqualTo>
  140. <ogc:PropertyName>MH_DATUM_INGANG</ogc:PropertyName>
  141. <ogc:Literal>2015-02-27T00:00:00Z</ogc:Literal>
  142. </ogc:PropertyIsLessThanOrEqualTo>
  143. <ogc:Or>
  144. <ogc:PropertyIsGreaterThanOrEqualTo>
  145. <ogc:PropertyName>MH_DATUM_EINDE</ogc:PropertyName>
  146. <ogc:Literal>2015-02-27T00:00:00Z</ogc:Literal>
  147. </ogc:PropertyIsGreaterThanOrEqualTo>
  148. <ogc:PropertyIsNull>
  149. <ogc:PropertyName>MH_DATUM_EINDE</ogc:PropertyName>
  150. </ogc:PropertyIsNull>
  151. </ogc:Or>
  152. </ogc:And>
  153. </ogc:And>
  154. </ogc:Filter>
  155. -->
  156. <xsl:template match="/">
  157. <xsl:apply-templates select="ui_table:ui_table/ui_table:filters"/>
  158. </xsl:template>
  159. <xsl:template match="ui_table:filters">
  160. <xsl:apply-templates select="ui_table:filter"/>
  161. </xsl:template>
  162. <!--
  163. <filters>
  164. <filter>
  165. <label>Status</label>
  166. <icon>question-sign</icon>
  167. <name>sf_Status</name>
  168. <filter_buttons>
  169. <filter_button>
  170. <name>OCZEKUJACY</name>
  171. <value>WAITING</value>
  172. <ogc:Filter>
  173. <ogc:PropertyIsEqualTo>
  174. <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  175. <ogc:Literal>WAITING</ogc:Literal>
  176. </ogc:PropertyIsEqualTo>
  177. </ogc:Filter>
  178. </filter_button>
  179. <filter_button>
  180. <name>AKTYWNI</name>
  181. <value>AKTYWNI</value>
  182. <ogc:Filter>
  183. <ogc:Or>
  184. <ogc:PropertyIsEqualTo>
  185. <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  186. <ogc:Literal>NORMAL</ogc:Literal>
  187. </ogc:PropertyIsEqualTo>
  188. </ogc:Or>
  189. <ogc:Or>
  190. <ogc:PropertyIsEqualTo>
  191. <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  192. <ogc:Literal>WARNING</ogc:Literal>
  193. </ogc:PropertyIsEqualTo>
  194. </ogc:Or>
  195. </ogc:Filter>
  196. -->
  197. <xsl:template match="ui_table:filter">
  198. <xsl:element name="ui_filter">
  199. <xsl:attribute name="name"><xsl:value-of select="ui_table:name" /></xsl:attribute>
  200. <xsl:attribute name="label"><xsl:value-of select="ui_table:label" /></xsl:attribute>
  201. <xsl:attribute name="icon"><xsl:value-of select="ui_table:icon" /></xsl:attribute>
  202. <xsl:apply-templates select="ui_table:filter_buttons/ui_table:filter_button"/>
  203. </xsl:element>
  204. </xsl:template>
  205. <xsl:template match="ui_table:filter_button">
  206. <xsl:element name="ui_filter_button">
  207. <xsl:attribute name="value"><xsl:value-of select="ui_table:value" /></xsl:attribute>
  208. <xsl:attribute name="label"><xsl:value-of select="ui_table:name" /></xsl:attribute>
  209. <xsl:apply-templates select="ogc:Filter"/>
  210. </xsl:element>
  211. </xsl:template>
  212. <xsl:template match="ogc:Filter">
  213. <xsl:apply-templates/>
  214. </xsl:template>
  215. <xsl:template match="ogc:Or">
  216. <xsl:element name="sql_filter_openBlock">
  217. <xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
  218. </xsl:element>
  219. <xsl:apply-templates/>
  220. <xsl:element name="sql_filter_closeBlock">
  221. <xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
  222. </xsl:element>
  223. </xsl:template>
  224. <xsl:template match="ogc:And">
  225. <xsl:element name="sql_filter_openBlock">
  226. <xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
  227. </xsl:element>
  228. <xsl:apply-templates/>
  229. <xsl:element name="sql_filter_closeBlock">
  230. <xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
  231. </xsl:element>
  232. </xsl:template>
  233. <!--
  234. <ogc:PropertyIsEqualTo>
  235. <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  236. <ogc:Literal>NORMAL</ogc:Literal>
  237. </ogc:PropertyIsEqualTo>
  238. -->
  239. <!-- TODO: sql variable for table prefix (t) -->
  240. <xsl:template match="ogc:PropertyIsEqualTo">
  241. <xsl:element name="sql_filter_comparisonFieldToValue">
  242. <xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
  243. <xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
  244. <xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
  245. </xsl:element>
  246. </xsl:template>
  247. </xsl:stylesheet>