浏览代码

Gui xml - convert gui xml by php using xsl

Piotr Labudda 10 年之前
父节点
当前提交
693c7cd437

+ 13 - 7
SE/schema/gui/Makefile

@@ -1,16 +1,22 @@
 
-testConvertGuiXmlToFilters-test_perms:
-	xsltproc testConvertGuiXmlToFilters.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$'
+php-convertGuiXml-test_perms:
+	php convertGuiXml.php
 
-testConvertGuiXmlToFilters-test_perms-no-dbg:
-	xsltproc testConvertGuiXmlToFilters.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$'|grep -v '^#'
+convertGuiXmlToFiltersXML-test_perms:
+	xsltproc convertGuiXmlToFiltersXML.xsl default_db/test_perms.gui.xml | xmllint --format -
 
-testConvertGuiXmlToFilters-test_perms-save:
-	xsltproc testConvertGuiXmlToFilters.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$' > tmp.test_perms.php
+convertGuiXmlToFiltersPHP-test_perms:
+	xsltproc convertGuiXmlToFiltersPHP.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$'
+
+convertGuiXmlToFiltersPHP-test_perms-no-dbg:
+	xsltproc convertGuiXmlToFiltersPHP.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$'|grep -v '^#'
+
+convertGuiXmlToFiltersPHP-test_perms-save:
+	xsltproc convertGuiXmlToFiltersPHP.xsl default_db/test_perms.gui.xml |grep -v '^[[:space:]]*$$' > tmp.test_perms.php
 	echo "cat tmp.test_perms.php"
 	cat tmp.test_perms.php
 
-all: testConvertGuiXmlToFilters-test_perms
+all: convertGuiXmlToFiltersPHP-test_perms
 
 clean:
 	rm tmp.* class.*.php

+ 121 - 0
SE/schema/gui/convertGuiXml.php

@@ -0,0 +1,121 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../se-lib/bootstrap.php';
+Lib::loadClass('SqlQueryWhereBuilder');
+
+function convertGuiXmlToCmdList($guiXmlString, $convertGuiXslString) {
+		$requestXml = new DOMDocument();
+		$requestXml->loadXml($guiXmlString);
+
+		$convertGuiXsl = new DOMDocument();
+		$convertGuiXsl->loadXml($convertGuiXslString);
+		$proc = new XSLTProcessor();
+		$proc->importStylesheet($convertGuiXsl);
+		return $proc->transformToXML($requestXml);
+}
+
+$guiXmlString = file_get_contents('default_db/test_perms.gui.xml');
+$convertGuiXslString = file_get_contents('convertGuiXmlToFiltersXML.xsl');
+$convertedGuiXml = convertGuiXmlToCmdList($guiXmlString, $convertGuiXslString);
+
+/*
+<?xml version="1.0"?>
+<ui_filter name="sf_Status" label="Status" icon="question-sign">
+  <ui_filter_button value="WAITING" label="OCZEKUJACY">
+    <sql_filter_comparisonFieldToValue fieldName="A_STATUS" comparisonSign="=" value="WAITING"/>
+  </ui_filter_button>
+  <ui_filter_button value="AKTYWNI" label="AKTYWNI">
+    <sql_filter_openBlock type="or"/>
+    <sql_filter_comparisonFieldToValue fieldName="A_STATUS" comparisonSign="=" value="NORMAL"/>
+    <sql_filter_comparisonFieldToValue fieldName="A_STATUS" comparisonSign="=" value="WARNING"/>
+    <sql_filter_closeBlock type="or"/>
+  </ui_filter_button>
+</ui_filter>
+*/
+echo $convertedGuiXml . "\n-----\n";
+
+$DBG = true;
+		$tags = array();
+		$parserXml = xml_parser_create();
+		xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
+		xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
+		if (0 == xml_parse_into_struct($parserXml, $convertedGuiXml, $tags)) {
+			throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction failed");
+		}
+		xml_parser_free($parserXml);
+		if (empty($tags)) {
+			throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction returns empty structure");
+		}
+
+// [{"tag":"ui_filter","type":"open","level":1,"attributes":{"name":"sf_Status","label":"Status","icon":"question-sign"}}
+// ,{"tag":"ui_filter_button","type":"open","level":2,"attributes":{"value":"WAITING","label":"OCZEKUJACY"}}
+// ,{"tag":"sql_filter_comparisonFieldToValue","type":"complete","level":3,"attributes":{"fieldName":"A_STATUS","comparisonSign":"=","value":"WAITING"}}
+// ,{"tag":"ui_filter_button","type":"close","level":2}
+// ,{"tag":"ui_filter_button","type":"open","level":2,"attributes":{"value":"AKTYWNI","label":"AKTYWNI"}}
+// ,{"tag":"sql_filter_openBlock","type":"complete","level":3,"attributes":{"type":"or"}}
+// ,{"tag":"sql_filter_comparisonFieldToValue","type":"complete","level":3,"attributes":{"fieldName":"A_STATUS","comparisonSign":"=","value":"NORMAL"}}
+// ,{"tag":"sql_filter_comparisonFieldToValue","type":"complete","level":3,"attributes":{"fieldName":"A_STATUS","comparisonSign":"=","value":"WARNING"}}
+// ,{"tag":"sql_filter_closeBlock","type":"complete","level":3,"attributes":{"type":"or"}}
+// ,{"tag":"ui_filter_button","type":"close","level":2}
+// ,{"tag":"ui_filter","type":"close","level":1}]
+
+		if($DBG){echo "\ntags L." . __LINE__ . ":\n" . json_encode($tags) . "\n";}
+
+$filters = array();
+$filter = null;
+$filterButton = null;
+foreach ($tags as $tag) {
+	switch ($tag['tag']) {
+		case 'ui_filter': {
+			if ('open' == $tag['type']) {
+				$filter = new stdClass();
+				$filter->name = V::get('name', '', $tag['attributes']);
+				$filter->label = V::get('label', '', $tag['attributes']);
+				$filter->icon = V::get('icon', '', $tag['attributes']);
+				$filter->buttons = array();
+				if (empty($filter->name)) throw new Exception("Empty root tag name #" . __LINE__);
+			} else if ('close' == $tag['type']) {
+				$filters[$filter->name] = $filter;
+			} else throw new Exception("Wrong ui_filter tag typ");
+		}
+			break;
+		case 'ui_filter_button': {
+			if ('open' == $tag['type']) {
+				$filterButton = new stdClass();
+				$filterButton->name = V::get('value', '', $tag['attributes']);
+				$filterButton->label = V::get('label', '', $tag['attributes']);
+				$filterButton->queryWhere = new SqlQueryWhereBuilder();
+				if (empty($filterButton->name)) throw new Exception("Empty root tag name #" . __LINE__);
+			} else if ('close' == $tag['type']) {
+				//$filterButton->rawQueryWhere = $filterButton->queryWhere->getQueryWhere();
+				$filter->buttons[$filterButton->name] = $filterButton;
+			} else throw new Exception("Wrong ui_filter tag typ");
+		}
+			break;
+		case 'sql_filter_comparisonFieldToValue': {
+			$fieldName = V::get('fieldName', '', $tag['attributes']);
+			$comparisonSign = V::get('comparisonSign', '', $tag['attributes']);
+			$value = V::get('value', '', $tag['attributes']);
+			$filterButton->queryWhere->addComparisonFieldToValue($fieldName, $comparisonSign, $value);
+		}
+			break;
+		case 'sql_filter_openBlock': {
+			$blockType = V::get('type', '', $tag['attributes']);
+echo "sql_filter_openBlock block Type {$blockType} attrs = " . json_encode($tag) . "\n";
+			$filterButton->queryWhere->openBlock($blockType);
+		}
+			break;
+		case 'sql_filter_closeBlock': {
+			$blockType = V::get('type', '', $tag['attributes']);
+			$filterButton->queryWhere->closeBlock($blockType);
+		}
+			break;
+		default: {
+echo "filter = "; print_r($filter);
+echo "filterButton = "; print_r($filterButton);
+echo "filters = "; print_r($filters);
+			throw new Exception("TODO: tag {$tag['tag']}");
+		}
+	}
+}
+echo "filters = "; print_r($filters);

+ 0 - 0
SE/schema/gui/testConvertGuiXmlToFilters.xsl → SE/schema/gui/convertGuiXmlToFiltersPHP.xsl


+ 256 - 0
SE/schema/gui/convertGuiXmlToFiltersXML.xsl

@@ -0,0 +1,256 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+								xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+								xmlns:ui_table="https://biuro.biall-net.pl/SE/version-git/schema/gui/table.gui.xsd"
+								xmlns:ogc="http://www.opengis.net/ogc"
+								>
+<!--								xmlns:p5_36_TEST_PERMS="https://biuro.biall-net.pl/api/36/TEST_PERMS" -->
+<!-- import namespaces from xsd xmlns:p5_36_TEST_PERMS="https://biuro.biall-net.pl/api/36/TEST_PERMS" -->
+	<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
+
+<!-- from Data_Source
+sf_Problemy
+		$fltrs['Problemy'] = new stdClass();
+		$fltrs['Problemy']->icon = 'glyphicon glyphicon-warning-sign';
+		$fltrs['Problemy']->btns = array();
+		$fltrs['Problemy']->btns['PROBLEMY'] = (object)array('value'=>'PROBLEM');
+		$fltrs['Problemy']->btns['OSTRZEZENIA'] = (object)array('value'=>'WARNING');
+		$fltrs['Problemy']->btns['BEZ_PROBLEM.'] = (object)array('value'=>'NORMAL');
+sf_Status
+		$fltrs['Status'] = new stdClass();
+		$fltrs['Status']->icon = 'glyphicon glyphicon-question-sign';
+		$fltrs['Status']->btns = array();
+		$fltrs['Status']->btns['OCZEKUJACY'] = (object)array('value'=>'WAITING');
+		$fltrs['Status']->btns['AKTYWNI'] = (object)array('value'=>'AKTYWNI');
+sf_Spotkania
+		$fltrs['Spotkania'] = new stdClass();
+		$fltrs['Spotkania']->icon = 'glyphicon glyphicon-calendar';
+		$fltrs['Spotkania']->btns = array();
+		$fltrs['Spotkania']->btns['STARE'] = (object)array('value'=>'OLD');
+		$fltrs['Spotkania']->btns['ZARAZ'] = (object)array('value'=>'NOW');
+		$fltrs['Spotkania']->btns['DZISIAJ'] = (object)array('value'=>'TODAY');
+		$fltrs['Spotkania']->btns['BRAK'] = (object)array('value'=>'BRAK');
+sf_Access
+		$fltrs['Access'] = new stdClass();
+		$fltrs['Access']->icon = 'glyphicon glyphicon-lock';
+		$fltrs['Access']->btns = array();
+		$fltrs['Access']->btns['Pokaż'] = (object)array('value'=>'SHOW');
+-->
+<!-- from Data_Source
+sf_Problemy
+			case 'Problemy':
+				if (array_key_exists('A_PROBLEM', $this->_cols)) {
+					switch ($value) {
+						case 'PROBLEM':
+							$sqlFltr = " t.`A_PROBLEM`!='' ";
+							break;
+						case 'WARNING':
+							$sqlFltr = " t.`A_PROBLEM`='WARNING' ";
+							break;
+						case 'NORMAL':
+							$sqlFltr = " t.`A_PROBLEM`='' ";
+							break;
+					}
+				}
+				break;
+			case 'Status':
+				if (array_key_exists('A_STATUS', $this->_cols)) {
+					switch ($value) {
+						case 'WAITING':
+							$sqlFltr = " t.`A_STATUS`='WAITING' ";
+							break;
+						case 'AKTYWNI':
+							$sqlFltr = " t.`A_STATUS` in('NORMAL', 'WARNING') ";
+			// 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='' )) ";
+			// 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'  )  ";
+							break;
+					}
+				}
+				break;
+			case 'Spotkania':
+				if (array_key_exists('L_APPOITMENT_DATE', $this->_cols)) {
+					switch ($value) {
+						case 'OLD':
+							$sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now()) and t.`L_APPOITMENT_DATE`!='' ";
+							break;
+						case 'NOW':
+							$sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<UNIX_TIMESTAMP(now())+3600 and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>UNIX_TIMESTAMP(now())-3600 ";
+							break;
+						case 'TODAY':
+							$start = mktime(0,0,0, date("m"), date("d"), date("Y"));
+							$end = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
+							$sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
+							break;
+						case 'TOMORROW':
+							$start = mktime(0,0,0, date("m"), date("d") + 1, date("Y"));
+							$end = mktime(0,0,0, date("m"), date("d") + 2, date("Y"));
+							$sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
+							break;
+						case 'YESTERDAY':
+							$start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
+							$end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
+							$sqlFltr = " UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)>'{$start}' and UNIX_TIMESTAMP(t.`L_APPOITMENT_DATE`)<'{$end}' ";
+							break;
+						case 'BRAK':
+							$start = mktime(0,0,0, date("m"), date("d") - 1, date("Y"));
+							$end = mktime(0,0,0, date("m"), date("d") - 2, date("Y"));
+							$sqlFltr = " t.`L_APPOITMENT_DATE`='' ";
+							break;
+					}
+				}
+				break;
+			case 'Access':
+				if ('SHOW' != $value && $this->isAccessFltrAllowed()) {
+					$userLogin = User::getLogin();
+					$usrAclGroups = User::getLdapGroupsNames();
+					$usrAclGroups[] = '';// TODO: allow empty for everyone?
+					$sqlUsrAclGroups = "'" . implode("','", $usrAclGroups) . "'";
+					$sqlFltr = "
+						t.`{$this->_fieldGroupWrite}` in({$sqlUsrAclGroups})
+						and t.`{$this->_fieldGroupRead}` in({$sqlUsrAclGroups})
+					";
+					if (array_key_exists('L_APPOITMENT_USER', $this->_cols)) {
+						$sqlFltr = "
+							(
+								({$sqlFltr})
+								or t.`L_APPOITMENT_USER`='{$userLogin}'
+							)
+						";
+					}
+				}
+-->
+					<!-- $sqlFltr = " t.`A_STATUS`='WAITING' "; -->
+					<!-- $sqlFltr = " t.`A_STATUS` in('NORMAL', 'WARNING') "; -->
+					<!-- $sqlFltr = " (t.`A_STATUS`='NORMAL' or t.`A_STATUS`='WARNING') "; -->
+						<!-- in('NORMAL', 'WARNING') -->
+<!-- ogc:Filter example:
+<ogc:Filter>
+		<ogc:And>
+				<ogc:Or>
+						<ogc:PropertyIsEqualTo>
+								<ogc:PropertyName>ID</ogc:PropertyName>
+								<ogc:Literal>98400005701</ogc:Literal>
+						</ogc:PropertyIsEqualTo>
+						<ogc:PropertyIsEqualTo>
+								<ogc:PropertyName>ID</ogc:PropertyName>
+								<ogc:Literal>-1</ogc:Literal>
+						</ogc:PropertyIsEqualTo>
+				</ogc:Or>
+				<ogc:And>
+						<ogc:PropertyIsLessThanOrEqualTo>
+								<ogc:PropertyName>MH_DATUM_INGANG</ogc:PropertyName>
+								<ogc:Literal>2015-02-27T00:00:00Z</ogc:Literal>
+						</ogc:PropertyIsLessThanOrEqualTo>
+						<ogc:Or>
+								<ogc:PropertyIsGreaterThanOrEqualTo>
+										<ogc:PropertyName>MH_DATUM_EINDE</ogc:PropertyName>
+										<ogc:Literal>2015-02-27T00:00:00Z</ogc:Literal>
+								</ogc:PropertyIsGreaterThanOrEqualTo>
+								<ogc:PropertyIsNull>
+										<ogc:PropertyName>MH_DATUM_EINDE</ogc:PropertyName>
+								</ogc:PropertyIsNull>
+						</ogc:Or>
+				</ogc:And>
+		</ogc:And>
+</ogc:Filter>
+-->
+
+	<xsl:template match="/">
+		<xsl:apply-templates select="ui_table:ui_table/ui_table:filters"/>
+	</xsl:template>
+
+	<xsl:template match="ui_table:filters">
+<xsl:apply-templates select="ui_table:filter"/>
+	</xsl:template>
+<!--
+<filters>
+		<filter>
+			<label>Status</label>
+			<icon>question-sign</icon>
+			<name>sf_Status</name>
+			<filter_buttons>
+				<filter_button>
+					<name>OCZEKUJACY</name>
+					<value>WAITING</value>
+					<ogc:Filter>
+						<ogc:PropertyIsEqualTo>
+							<ogc:PropertyName>A_STATUS</ogc:PropertyName>
+							<ogc:Literal>WAITING</ogc:Literal>
+						</ogc:PropertyIsEqualTo>
+					</ogc:Filter>
+				</filter_button>
+				<filter_button>
+					<name>AKTYWNI</name>
+					<value>AKTYWNI</value>
+					<ogc:Filter>
+						<ogc:Or>
+							<ogc:PropertyIsEqualTo>
+								<ogc:PropertyName>A_STATUS</ogc:PropertyName>
+								<ogc:Literal>NORMAL</ogc:Literal>
+							</ogc:PropertyIsEqualTo>
+						</ogc:Or>
+						<ogc:Or>
+							<ogc:PropertyIsEqualTo>
+								<ogc:PropertyName>A_STATUS</ogc:PropertyName>
+								<ogc:Literal>WARNING</ogc:Literal>
+							</ogc:PropertyIsEqualTo>
+						</ogc:Or>
+					</ogc:Filter>
+-->
+	<xsl:template match="ui_table:filter">
+		<xsl:element name="ui_filter">
+			<xsl:attribute name="name"><xsl:value-of select="ui_table:name" /></xsl:attribute>
+			<xsl:attribute name="label"><xsl:value-of select="ui_table:label" /></xsl:attribute>
+			<xsl:attribute name="icon"><xsl:value-of select="ui_table:icon" /></xsl:attribute>
+			<xsl:apply-templates select="ui_table:filter_buttons/ui_table:filter_button"/>
+		</xsl:element>
+	</xsl:template>
+
+	<xsl:template match="ui_table:filter_button">
+		<xsl:element name="ui_filter_button">
+			<xsl:attribute name="value"><xsl:value-of select="ui_table:value" /></xsl:attribute>
+			<xsl:attribute name="label"><xsl:value-of select="ui_table:name" /></xsl:attribute>
+			<xsl:apply-templates select="ogc:Filter"/>
+		</xsl:element>
+	</xsl:template>
+
+	<xsl:template match="ogc:Filter">
+<xsl:apply-templates/>
+	</xsl:template>
+
+	<xsl:template match="ogc:Or">
+		<xsl:element name="sql_filter_openBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
+		</xsl:element>
+		<xsl:apply-templates/>
+		<xsl:element name="sql_filter_closeBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'or'" /></xsl:attribute>
+		</xsl:element>
+	</xsl:template>
+
+	<xsl:template match="ogc:And">
+		<xsl:element name="sql_filter_openBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
+		</xsl:element>
+		<xsl:apply-templates/>
+		<xsl:element name="sql_filter_closeBlock">
+			<xsl:attribute name="type"><xsl:value-of select="'and'" /></xsl:attribute>
+		</xsl:element>
+	</xsl:template>
+
+<!--
+							<ogc:PropertyIsEqualTo>
+								<ogc:PropertyName>A_STATUS</ogc:PropertyName>
+								<ogc:Literal>NORMAL</ogc:Literal>
+							</ogc:PropertyIsEqualTo>
+-->
+<!-- TODO: sql variable for table prefix (t) -->
+	<xsl:template match="ogc:PropertyIsEqualTo">
+		<xsl:element name="sql_filter_comparisonFieldToValue">
+			<xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
+			<xsl:attribute name="comparisonSign"><xsl:value-of select="'='" /></xsl:attribute>
+			<xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
+		</xsl:element>
+	</xsl:template>
+
+</xsl:stylesheet>