fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [15474] convert datatype XML to JSON


From: sigurdne
Subject: [Fmsystem-commits] [15474] convert datatype XML to JSON
Date: Tue, 16 Aug 2016 18:43:58 +0000 (UTC)

Revision: 15474
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15474
Author:   sigurdne
Date:     2016-08-16 18:43:57 +0000 (Tue, 16 Aug 2016)
Log Message:
-----------
convert datatype XML to JSON

Modified Paths:
--------------
    trunk/bim/inc/class.sobimitem.inc.php
    trunk/bim/setup/setup.inc.php
    trunk/bim/setup/tables_current.inc.php
    trunk/bim/setup/tables_update.inc.php
    trunk/property/inc/class.boentity.inc.php
    trunk/property/inc/class.soadmin_entity.inc.php
    trunk/property/inc/class.soentity.inc.php
    trunk/property/inc/class.soproject.inc.php
    trunk/property/inc/class.uiimport.inc.php
    trunk/property/inc/import/import_update_generic.php

Modified: trunk/bim/inc/class.sobimitem.inc.php
===================================================================
--- trunk/bim/inc/class.sobimitem.inc.php       2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/bim/inc/class.sobimitem.inc.php       2016-08-16 18:43:57 UTC (rev 
15474)
@@ -53,14 +53,14 @@
                {
                $itemTable = self::bimItemTable;
                $typeTable = self::bimTypeTable;
-                       $sql = "SELECT $itemTable.id, fm_bim_type.name AS type, 
 $itemTable.guid,  $itemTable.xml_representation " .
+                       $sql = "SELECT $itemTable.id, fm_bim_type.name AS type, 
 $itemTable.guid,  $itemTable.json_representation " .
                        "FROM public. $itemTable,  public.$typeTable " .
                                        "WHERE   $itemTable.type = 
$typeTable.id";
                $bimItemArray = array();
                $this->db->query($sql);
                while($this->db->next_record())
                {
-                               $bimItem = new BimItem($this->db->f('id'), 
$this->db->f('guid'), $this->db->f('type'), $this->db->f('xml_representation', 
true));
+                               $bimItem = new BimItem($this->db->f('id'), 
$this->db->f('guid'), $this->db->f('type'), 
$this->db->f('json_representation'));
                        array_push($bimItemArray, $bimItem);
                }
 
@@ -71,7 +71,7 @@
                {
                $itemTable = self::bimItemTable;
                $typeTable = self::bimTypeTable;
-                       $sql = "SELECT $itemTable.id, fm_bim_type.name AS type, 
$itemTable.guid, $itemTable.xml_representation, $itemTable.model " .
+                       $sql = "SELECT $itemTable.id, fm_bim_type.name AS type, 
$itemTable.guid, $itemTable.json_representation, $itemTable.model " .
                        "FROM public.$itemTable,  public.$typeTable " .
                                        "WHERE  $itemTable.type = $typeTable.id 
" .
                                "AND $itemTable.guid ='$bimObjectGuid'";
@@ -83,7 +83,7 @@
                        else
                        {
                        $this->db->next_record();
-                               return new BimItem($this->db->f('id'), 
$this->db->f('guid'), $this->db->f('type'), $this->db->f('xml_representation', 
true), $this->db->f('model'));
+                               return new BimItem($this->db->f('id'), 
$this->db->f('guid'), $this->db->f('type'), 
$this->db->f('json_representation'), $this->db->f('model'));
                }
        }
        
@@ -100,7 +100,7 @@
                $type = $this->db->f('type');
                        $id = $this->db->next_id('fm_bim_item', array('type' => 
$type));
 
-                       $sql = "INSERT INTO " . self::bimItemTable . " (type, 
id, guid, xml_representation, model) values ($type, $id,";
+                       $sql = "INSERT INTO " . self::bimItemTable . " (type, 
id, guid, json_representation, model) values ($type, $id,";
        //      $sql = $sql."(select id from ".self::bimTypeTable." where name 
= '".$bimItem->getType()."'),";
                        $sql = $sql . "'" . $bimItem->getGuid() . "', '" . 
$this->db->db_addslashes($bimItem->getXml()) . "', " . $bimItem->getModelId() . 
")";
                        try
@@ -164,7 +164,7 @@
                        {
                        throw new Exception("Item does not exist!");
                }
-                       $sql = "Update " . self::bimItemTable . " set 
xml_representation='" . $this->db->db_addslashes($bimItem->getXml()) . "' where 
guid='" . $bimItem->getGuid() . "'";
+                       $sql = "Update " . self::bimItemTable . " set 
json_representation='" . $bimItem->getXml() . "' where guid='" . 
$bimItem->getGuid() . "'";
                
                        if(is_null($this->db->query($sql, __LINE__, __FILE__)))
                        {
@@ -191,8 +191,8 @@
                {
                $columnAlias = "attribute_values";
                $itemTable = self::bimItemTable;
-               //$sql = "select 
xpath('descendant-or-self::*[$attribute]/$attribute/text()', (select 
xml_representation from fm_bim_data where guid='$bimItemGuid'))";
-               $sql = "select 
array_to_string(xpath('descendant-or-self::*[$attribute]/$attribute/text()', 
(select xml_representation from $itemTable where guid='$bimItemGuid')), ',') as 
$columnAlias";
+               //$sql = "select 
xpath('descendant-or-self::*[$attribute]/$attribute/text()', (select 
json_representation from fm_bim_data where guid='$bimItemGuid'))";
+               $sql = "select 
array_to_string(xpath('descendant-or-self::*[$attribute]/$attribute/text()', 
(select json_representation from $itemTable where guid='$bimItemGuid')), ',') 
as $columnAlias";
                        $this->db->query($sql, __LINE__, __FILE__);
                        if($this->db->num_rows() == 0)
                        {

Modified: trunk/bim/setup/setup.inc.php
===================================================================
--- trunk/bim/setup/setup.inc.php       2016-08-16 00:01:02 UTC (rev 15473)
+++ trunk/bim/setup/setup.inc.php       2016-08-16 18:43:57 UTC (rev 15474)
@@ -11,7 +11,7 @@
        * @version $Id: setup.inc.php 6982 2011-02-14 20:01:17Z sigurdne $
        */
        $setup_info['bim']['name']                      = 'bim';
-       $setup_info['bim']['version']           = '0.9.17.510';
+       $setup_info['bim']['version']           = '0.9.17.511';
        $setup_info['bim']['app_order']         = 8;
        $setup_info['bim']['enable']            = 1;
        $setup_info['bim']['app_group']         = 'office';

Modified: trunk/bim/setup/tables_current.inc.php
===================================================================
--- trunk/bim/setup/tables_current.inc.php      2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/bim/setup/tables_current.inc.php      2016-08-16 18:43:57 UTC (rev 
15474)
@@ -50,7 +50,7 @@
                                'id' => array('type' => 'int', 'precision' => 
4, 'nullable' => False),
                                'type' => array('type' => 'int', 'precision' => 
4, 'nullable' => False),
                                'guid' => array('type' => 'varchar', 
'precision' => 50, 'nullable' => False),
-                               'xml_representation' => array('type' => 'xml', 
'nullable' => False),
+                               'json_representation' => array('type' => 
'jsonb', 'nullable' => False),
                                'model' => array('type' => 'int', 'precision' 
=> 4, 'nullable' => False),
                                'p_location_id' => array('type' => 'int', 
'precision' => '4', 'nullable' => True),
                                'p_id' => array('type' => 'int', 'precision' => 
'4', 'nullable' => True),

Modified: trunk/bim/setup/tables_update.inc.php
===================================================================
--- trunk/bim/setup/tables_update.inc.php       2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/bim/setup/tables_update.inc.php       2016-08-16 18:43:57 UTC (rev 
15474)
@@ -253,4 +253,54 @@
                        $GLOBALS['setup_info']['bim']['currentver'] = 
'0.9.17.510';
                        return $GLOBALS['setup_info']['bim']['currentver'];
                }
-       }
\ No newline at end of file
+       }
+       /**
+       * Update bim version from 0.9.17.510 to 0.9.17.511
+       */
+       $test[] = '0.9.17.510';
+
+       function bim_upgrade0_9_17_510()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               $GLOBALS['phpgw_setup']->oProc->AddColumn('fm_bim_item', 
'json_representation', array(
+                       'type' => 'jsonb', 'nullable' => true));
+
+               $GLOBALS['phpgw_setup']->oProc->query("SELECT 
id,location_id,xml_representation FROM fm_bim_item", __LINE__, __FILE__);
+
+               $items = array();
+               while($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $items[] = array
+                       (
+                               'id'                    => 
(int)$GLOBALS['phpgw_setup']->oProc->f('id'),
+                               'location_id'   => 
(int)$GLOBALS['phpgw_setup']->oProc->f('location_id'),
+                               'xml_representation' => 
$GLOBALS['phpgw_setup']->oProc->f('xml_representation', true),
+                       );
+               }
+
+               $xmlparse = CreateObject('property.XmlToArray');
+               $xmlparse->setEncoding('UTF-8');
+               $xmlparse->setDecodesUTF8Automaticly(false);
+
+               foreach ($items as $item)
+               {
+                       $xmldata = $item['xml_representation'];
+                       $var_result = $xmlparse->parse($xmldata);
+
+                       $jsondata = json_encode($var_result, JSON_HEX_APOS);
+                       $GLOBALS['phpgw_setup']->oProc->query("UPDATE 
fm_bim_item SET json_representation = '{$jsondata}'"
+                       . " WHERE id = {$item['id']} AND location_id = 
{$item['location_id']}", __LINE__, __FILE__);
+               }
+
+               $GLOBALS['phpgw_setup']->oProc->AlterColumn('fm_bim_item', 
'json_representation', array(
+                       'type' => 'jsonb', 'nullable' => False));
+
+               $GLOBALS['phpgw_setup']->oProc->DropColumn('fm_bim_item', 
array(), 'xml_representation');
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['bim']['currentver'] = 
'0.9.17.511';
+                       return $GLOBALS['setup_info']['bim']['currentver'];
+               }
+       }

Modified: trunk/property/inc/class.boentity.inc.php
===================================================================
--- trunk/property/inc/class.boentity.inc.php   2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/property/inc/class.boentity.inc.php   2016-08-16 18:43:57 UTC (rev 
15474)
@@ -418,7 +418,9 @@
                                                {
                                                        if ($category['is_eav'])
                                                        {
-                                                               
$attrib_filter[] = "xmlexists('//{$attrib['column_name']}[text() = 
''$_attrib_filter_value'']' PASSING BY REF xml_representation)";
+                                                       //      
$attrib_filter[] = "xmlexists('//{$attrib['column_name']}[text() = 
''$_attrib_filter_value'']' PASSING BY REF xml_representation)";
+                                                               
$attrib_filter[] = "json_representation->>'{$attrib['column_name']}' = 
'{$_attrib_filter_value}'";
+
                                                        }
                                                        else
                                                        {
@@ -432,7 +434,8 @@
                                                {
                                                        if ($category['is_eav'])
                                                        {
-                                                               
$attrib_filter[] = 
"xmlexists('//{$attrib['column_name']}[contains(.,'',$_attrib_filter_value,'')]'
 PASSING BY REF xml_representation)";
+//                                                             
$attrib_filter[] = 
"xmlexists('//{$attrib['column_name']}[contains(.,'',$_attrib_filter_value,'')]'
 PASSING BY REF xml_representation)";
+                                                               
$attrib_filter[] = "json_representation->>'{$attrib['column_name']}' 
{$GLOBALS['phpgw']->db->like} '%,{$_attrib_filter_value},%'";
                                                        }
                                                        else
                                                        {

Modified: trunk/property/inc/class.soadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_entity.inc.php     2016-08-16 00:01:02 UTC 
(rev 15473)
+++ trunk/property/inc/class.soadmin_entity.inc.php     2016-08-16 18:43:57 UTC 
(rev 15474)
@@ -1189,7 +1189,7 @@
                                                while ($this->db->next_record())
                                                {
                                                        $data = 
$this->db->Record;
-
+/*
                                                        $xmldata = 
phpgwapi_xmlhelper::toXML($data, 
"_{$this->type}_{$category['entity_id']}_{$category['id']}");
                                                        $doc = new 
DOMDocument('1.0', 'utf-8');
                                                        $doc->loadXML($xmldata);
@@ -1206,7 +1206,7 @@
                                                        
$doc->preserveWhiteSpace = true;
                                                        $doc->formatOutput = 
true;
                                                        $xml = $doc->saveXML();
-
+*/
                                                        $p_location_id = '';
                                                        if ($data['p_cat_id'])
                                                        {
@@ -1233,7 +1233,8 @@
                                                                'location_id' 
=> $location_id,
                                                                'type' => $type,
                                                                'guid' => $guid,
-                                                               
'xml_representation' => $this->db->db_addslashes($xml),
+//                                                             
'xml_representation' => $this->db->db_addslashes($xml),
+                                                               
'json_representation' => json_encode($data),
                                                                'model' => 0,
                                                                'p_location_id' 
=> $p_location_id,
                                                                'p_id' => 
isset($data['p_num']) && $data['p_num'] ? (int)$data['p_num'] : '',

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/property/inc/class.soentity.inc.php   2016-08-16 18:43:57 UTC (rev 
15474)
@@ -284,17 +284,20 @@
                                                        case '=':
                                                        case 'equal':
                                                        case 'eq':
-                                                               $_querymethod[] 
= "xmlexists('//{$attribute_name}[text() = ''{$condition['value']}'']' PASSING 
BY REF xml_representation)";
+                               //                              $_querymethod[] 
= "xmlexists('//{$attribute_name}[text() = ''{$condition['value']}'']' PASSING 
BY REF xml_representation)";
+                                                               $_querymethod[] 
= "CAST(json_representation->>'{$attribute_name}' AS integer) = 
{$condition['value']}";
                                                                break;
                                                        case 'gt':
                                                        case '>':
                                                                $operator = '>';
-                                                               $_querymethod[] 
= "xmlexists('//{$attribute_name}[number() {$operator} 
''{$condition['value']}'']' PASSING BY REF xml_representation)";
+                               //                              $_querymethod[] 
= "xmlexists('//{$attribute_name}[number() {$operator} 
''{$condition['value']}'']' PASSING BY REF xml_representation)";
+                                                               $_querymethod[] 
= "CAST(json_representation->>'{$attribute_name}' AS integer) {$operator} 
{$condition['value']}";
                                                                break;
                                                        case 'lt':
                                                        case '<':
                                                                $operator = '<';
-                                                               $_querymethod[] 
= "xmlexists('//{$attribute_name}[number() {$operator} 
''{$condition['value']}'']' PASSING BY REF xml_representation)";
+//                                                             $_querymethod[] 
= "xmlexists('//{$attribute_name}[number() {$operator} 
''{$condition['value']}'']' PASSING BY REF xml_representation)";
+                                                               $_querymethod[] 
= "CAST(json_representation->>'{$attribute_name}' AS integer) {$operator} 
{$condition['value']}";
                                                                break;
                                                        default:
                                                                throw new 
Exception('ERROR: Not a valid operator on conditions');
@@ -303,10 +306,13 @@
                                                break;
                                        case 'CH':
                                                $__querymethod = array(); // 
remove block
-                                               $_querymethod[] = 
"xmlexists('//{$attribute_name}[contains(.,'',{$condition['value']},'')]' 
PASSING BY REF xml_representation)";
+//                                             $_querymethod[] = 
"xmlexists('//{$attribute_name}[contains(.,'',{$condition['value']},'')]' 
PASSING BY REF xml_representation)";
+                                               $_querymethod[] = 
"json_representation->>'{$attribute_name}' {$this->like} 
'%,{$condition['value']},%'";
+
                                                break;
                                        default:
-                                               $_querymethod[] = 
"xmlexists('//{$attribute_name}[text() = ''{$condition['value']}'']' PASSING BY 
REF xml_representation)";
+//                                             $_querymethod[] = 
"xmlexists('//{$attribute_name}[text() = ''{$condition['value']}'']' PASSING BY 
REF xml_representation)";
+                                               $_querymethod[] = 
"json_representation->>'{$attribute_name}' = '{$condition['value']}'";
                                                $__querymethod = array(); // 
remove block
                                }
                        }
@@ -320,7 +326,7 @@
                                $querymethod = " $where (" . implode(' AND ', 
$_querymethod) . ')';
                                unset($_querymethod);
                        }
-                       $sql = "SELECT id, location_code, p_location_id, p_id, 
org_unit_id, xml_representation FROM fm_bim_item WHERE location_id = 
{$location_id} $querymethod";
+                       $sql = "SELECT id, location_code, p_location_id, p_id, 
org_unit_id, json_representation FROM fm_bim_item WHERE location_id = 
{$location_id} $querymethod";
 
                        $sql_cnt = "SELECT count(id) as cnt FROM fm_bim_item 
WHERE location_id = {$location_id} $querymethod";
 
@@ -344,15 +350,14 @@
                        $j = 0;
                        while ($this->db->next_record())
                        {
-                               $xmldata = $this->db->f('xml_representation');
+                               $jsondata = 
json_decode($this->db->f('json_representation'), true);
 
+//                             $xml = new DOMDocument('1.0', 'utf-8');
+//                             $xml->loadXML($xmldata);
 
-                               $xml = new DOMDocument('1.0', 'utf-8');
-                               $xml->loadXML($xmldata);
-
                                foreach ($attributes as $attrib_id => $field)
                                {
-                                       if (!$value = 
$xml->getElementsByTagName($field['name'])->item(0)->nodeValue)
+                                       if (!$value = $jsondata[$field['name']])
                                        {
                                                $value = 
$this->db->f($field['name'], true);
                                        }
@@ -683,7 +688,8 @@
                                                        case 'T':
                                                                if 
(!$criteria_id)
                                                                {
-                                                                       
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . 
"[contains(.,''$query'')]' PASSING BY REF xml_representation)";
+//                                                                     
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . 
"[contains(.,''$query'')]' PASSING BY REF xml_representation)";
+                                                                       
$_querymethod[] = "json_representation->>'". $this->db->f('column_name') ."' 
{$this->like} '%{$query}%'";
                                                                        
$__querymethod = array(); // remove block
                                                                }
                                                                break;
@@ -701,7 +707,8 @@
                                                                        
$this->db2->query("SELECT phpgw_cust_choice.id FROM phpgw_cust_choice 
{$_filter_choise}", __LINE__, __FILE__);
                                                                        while 
($this->db2->next_record())
                                                                        {
-                                                                               
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . 
"[contains(.,''," . $this->db2->f('id') . ",'')]' PASSING BY REF 
xml_representation)";
+//                                                                             
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . 
"[contains(.,''," . $this->db2->f('id') . ",'')]' PASSING BY REF 
xml_representation)";
+                                                                               
$_querymethod[] = "json_representation->>'". $this->db->f('column_name') ."' 
{$this->like} '%,{$query},%'";
                                                                        }
                                                                }
                                                                break;
@@ -717,7 +724,9 @@
                                                                        
$__filter_choise = array();
                                                                        while 
($this->db2->next_record())
                                                                        {
-                                                                               
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+//                                                                             
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+                                                                               
$_querymethod[] = "CAST( json_representation->>'". $this->db->f('column_name') 
."' AS integer) = " .(int)$this->db2->f('id');
+
                                                                        }
                                                                        
$__querymethod = array(); // remove block
                                                                }
@@ -725,7 +734,9 @@
                                                        case 'I':
                                                                if 
(ctype_digit($query) && !$criteria_id)
                                                                {
-                                                                       
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$query . "'']' PASSING BY REF xml_representation)";
+//                                                                     
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$query . "'']' PASSING BY REF xml_representation)";
+                                                                       
$_querymethod[] = "CAST( json_representation->>'". $this->db->f('column_name') 
."' AS integer) = " .(int)$query;
+
                                                                        
$__querymethod = array(); // remove block
                                                                }
                                                                break;
@@ -736,7 +747,8 @@
                                                                        
$__filter_choise = array();
                                                                        while 
($this->db2->next_record())
                                                                        {
-                                                                               
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+//                                                                             
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+                                                                               
$_querymethod[] = "CAST( json_representation->>'". $this->db->f('column_name') 
."' AS integer) = " .(int)$this->db2->f('id');
                                                                        }
 
                                                                        
$__querymethod = array(); // remove block
@@ -749,7 +761,8 @@
                                                                        
$__filter_choise = array();
                                                                        while 
($this->db2->next_record())
                                                                        {
-                                                                               
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+//                                                                             
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+                                                                               
$_querymethod[] = "CAST( json_representation->>'". $this->db->f('column_name') 
."' AS integer) = " .(int)$this->db2->f('id');
                                                                        }
 
                                                                        
$__querymethod = array(); // remove block
@@ -762,7 +775,8 @@
                                                                        
$__filter_choise = array();
                                                                        while 
($this->db2->next_record())
                                                                        {
-                                                                               
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+//                                                                             
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''" . (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
+                                                                               
$_querymethod[] = "CAST( json_representation->>'". $this->db->f('column_name') 
."' AS integer) = " .(int)$this->db2->f('id');
                                                                        }
                                                                        
$__querymethod = array(); // remove block
                                                                }
@@ -770,7 +784,8 @@
                                                        default:
                                                                if 
(!$criteria_id)
                                                                {
-                                                                       
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''$query'']' PASSING BY REF xml_representation)";
+//                                                                     
$_querymethod[] = "xmlexists('//" . $this->db->f('column_name') . "[text() = 
''$query'']' PASSING BY REF xml_representation)";
+                                                                       
$_querymethod[] = "json_representation->>'". $this->db->f('column_name') ."' = 
'{$query}'";
                                                                        
$__querymethod = array(); // remove block
                                                                }
                                                }
@@ -913,9 +928,10 @@
                                                $ordermethod = " ORDER BY 
{$entity_table}.loc1 {$sort}";
                                                break;
                                        default:
-                                               $xml_order = ',cast 
(_order_field[1] as text) as _order_field_text';
-                                               $sql = str_replace('FROM 
fm_bim_item', "FROM (SELECT fm_bim_item.*, xpath('$order/text()', 
xml_representation) as _order_field FROM fm_bim_item", $sql);
-                                               $sql .= ") as fm_bim_item ORDER 
BY _order_field_text {$sort}";
+                                               $ordermethod = " ORDER BY 
{$entity_table}.json_representation->>'{$order}' {$sort}";
+//                                             $xml_order = ',cast 
(_order_field[1] as text) as _order_field_text';
+//                                             $sql = str_replace('FROM 
fm_bim_item', "FROM (SELECT fm_bim_item.*, xpath('$order/text()', 
xml_representation) as _order_field FROM fm_bim_item", $sql);
+//                                             $sql .= ") as fm_bim_item ORDER 
BY _order_field_text {$sort}";
                                }
                        }
                        else
@@ -978,13 +994,15 @@
 //_debug_array($uicols);
                        while ($this->db->next_record())
                        {
-                               $xmldata = $this->db->f('xml_representation');
-                               $xml = new DOMDocument('1.0', 'utf-8');
-                               $xml->loadXML($xmldata);
+//                             $xmldata = $this->db->f('xml_representation');
+//                             $xml = new DOMDocument('1.0', 'utf-8');
+//                             $xml->loadXML($xmldata);
+                               $jsondata = 
json_decode($this->db->f('json_representation'), true);
 
                                foreach ($cols_return as $key => $field)
                                {
-                                       if (!$value = 
$xml->getElementsByTagName($field)->item(0)->nodeValue)
+                       //              if (!$value = 
$xml->getElementsByTagName($field)->item(0)->nodeValue)
+                                       if (!$value = $jsondata[$field])
                                        {
                                                $value = $this->db->f($field, 
true);
                                        }
@@ -1006,7 +1024,8 @@
 
                                foreach ($cache_attributes[$location_id] as 
$key => $attribute)
                                {
-                                       $description_value = 
$xml->getElementsByTagName($attribute['name'])->item(0)->nodeValue;
+//                                     $description_value = 
$xml->getElementsByTagName($attribute['name'])->item(0)->nodeValue;
+                                       $description_value = 
$jsondata[$attribute['name']];
 
                                        if 
(isset($cache_attributes[$location_id][$key]['choice']) && 
$cache_attributes[$location_id][$key]['choice'])
                                        {
@@ -2020,15 +2039,18 @@
                                $values['org_unit_id'] = 
$this->db->f('org_unit_id');
                                $values['entity_group_id'] = 
$this->db->f('entity_group_id');
 
-                               $xmldata = $this->db->f('xml_representation', 
true);
-                               $xml = new DOMDocument('1.0', 'utf-8');
-                               $xml->loadXML($xmldata);
+//                             $xmldata = $this->db->f('xml_representation', 
true);
+//                             $xml = new DOMDocument('1.0', 'utf-8');
+//                             $xml->loadXML($xmldata);
 
+                               $jsondata = 
json_decode($this->db->f('json_representation'), true);
+
                                if (isset($values['attributes']) && 
is_array($values['attributes']))
                                {
                                        foreach ($values['attributes'] as 
&$attr)
                                        {
-                                               $attr['value'] = 
$xml->getElementsByTagName($attr['column_name'])->item(0)->nodeValue;
+//                                             $attr['value'] = 
$xml->getElementsByTagName($attr['column_name'])->item(0)->nodeValue;
+                                               $attr['value'] = 
$jsondata[$attr['column_name']];
                                        }
                                }
                        }
@@ -2310,24 +2332,24 @@
                        $type = $this->db->f('type');
                        $id = $this->db->next_id('fm_bim_item', array('type' => 
$type));
 
-                       phpgw::import_class('phpgwapi.xmlhelper');
-                       $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
-                       $doc = new DOMDocument;
-                       $doc->preserveWhiteSpace = true;
-                       $doc->loadXML($xmldata);
-                       $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
-                       $domAttribute = $doc->createAttribute('appname');
-                       $domAttribute->value = $this->type_app[$this->type];
+//                     phpgw::import_class('phpgwapi.xmlhelper');
+//                     $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
+//                     $doc = new DOMDocument;
+//                     $doc->preserveWhiteSpace = true;
+//                     $doc->loadXML($xmldata);
+//                     $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+//                     $domAttribute = $doc->createAttribute('appname');
+//                     $domAttribute->value = $this->type_app[$this->type];
+//
+//                     // Don't forget to append it to the element
+//                     $domElement->appendChild($domAttribute);
+//
+//                     // Append it to the document itself
+//                     $doc->appendChild($domElement);
+//                     $doc->formatOutput = true;
+//
+//                     $xml = $doc->saveXML();
 
-                       // Don't forget to append it to the element
-                       $domElement->appendChild($domAttribute);
-
-                       // Append it to the document itself
-                       $doc->appendChild($domElement);
-                       $doc->formatOutput = true;
-
-                       $xml = $doc->saveXML();
-
                        //      _debug_array($xml);
 
                        if (function_exists('com_create_guid') === true)
@@ -2345,7 +2367,8 @@
                                'location_id' => $location_id,
                                'type' => $type,
                                'guid' => $guid,
-                               'xml_representation' => 
$this->db->db_addslashes($xml),
+//                             'xml_representation' => 
$this->db->db_addslashes($xml),
+                               'json_representation' => json_encode($data),
                                'model' => 0,
                                'p_location_id' => 
isset($data['p_location_id']) && $data['p_location_id'] ? 
$data['p_location_id'] : '',
                                'p_id' => isset($data['p_id']) && $data['p_id'] 
? $data['p_id'] : '',
@@ -2373,43 +2396,29 @@
 
                        $location_name = str_replace('.', '_', $location_name);
 
-                       phpgw::import_class('phpgwapi.xmlhelper');
+//                     phpgw::import_class('phpgwapi.xmlhelper');
+//
+//                     $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
+//                     $doc = new DOMDocument;
+//                     $doc->preserveWhiteSpace = true;
+//                     $doc->loadXML($xmldata);
+//                     $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+//                     $domAttribute = $doc->createAttribute('appname');
+//                     $domAttribute->value = $this->type_app[$this->type];
+//
+//                     // Don't forget to append it to the element
+//                     $domElement->appendChild($domAttribute);
+//
+//                     // Append it to the document itself
+//                     $doc->appendChild($domElement);
+//
+//                     $doc->formatOutput = true;
+//                     $xml = $doc->saveXML();
 
-                       /*
-                         // FIXME: not working
-                         if($data)
-                         {
-                         foreach ($data as $key => &$value)
-                         {
-                         if(preg_match('/[<>&]/', $value)) // or use CDATA..
-                         {
-                         $value =  str_ireplace ( array('&lt;','&gt;','<','>') 
, array('[',']', '[', ']') , $value);
-                         }
-                         }
-                         }
-                        */
-                       $xmldata = phpgwapi_xmlhelper::toXML($data, 
$location_name);
-                       $doc = new DOMDocument;
-                       $doc->preserveWhiteSpace = true;
-                       $doc->loadXML($xmldata);
-                       $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
-                       $domAttribute = $doc->createAttribute('appname');
-                       $domAttribute->value = $this->type_app[$this->type];
-
-                       // Don't forget to append it to the element
-                       $domElement->appendChild($domAttribute);
-
-                       // Append it to the document itself
-                       $doc->appendChild($domElement);
-
-                       $doc->formatOutput = true;
-                       $xml = $doc->saveXML();
-
-//                     _debug_array($xml);
-
                        $value_set = array
                                (
-                               'xml_representation' => 
$this->db->db_addslashes($xml),
+//                             'xml_representation' => 
$this->db->db_addslashes($xml),
+                               'json_representation' => json_encode($data),
                                'p_location_id' => 
isset($data['p_location_id']) && $data['p_location_id'] ? 
$data['p_location_id'] : '',
                                'p_id' => isset($data['p_id']) && $data['p_id'] 
? $data['p_id'] : '',
                                'location_code' => $data['location_code'],
@@ -2532,10 +2541,13 @@
                                                        $this->db->query($sql, 
__LINE__, __FILE__);
 
                                                        
$this->db->next_record();
-                                                       $xmldata = 
$this->db->f('xml_representation');
-                                                       $xml = new 
DOMDocument('1.0', 'utf-8');
-                                                       $xml->loadXML($xmldata);
-                                                       $old_value = 
$xml->getElementsByTagName($entry['name'])->item(0)->nodeValue;
+//                                                     $xmldata = 
$this->db->f('xml_representation');
+//                                                     $xml = new 
DOMDocument('1.0', 'utf-8');
+//                                                     $xml->loadXML($xmldata);
+//                                                     $old_value = 
$xml->getElementsByTagName($entry['name'])->item(0)->nodeValue;
+                                                       $jsondata = 
json_decode($this->db->f('json_representation'), true);
+                                                       $old_value = 
$jsondata[$entry['name']];
+
                                                }
 
                                                if ($entry['datatype'] == 'D')

Modified: trunk/property/inc/class.soproject.inc.php
===================================================================
--- trunk/property/inc/class.soproject.inc.php  2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/property/inc/class.soproject.inc.php  2016-08-16 18:43:57 UTC (rev 
15474)
@@ -967,19 +967,21 @@
 
                        if ($category['is_eav'])
                        {
-                               $sql = "SELECT * FROM fm_bim_item"
+                               $sql = "SELECT 
json_representation->>'maaler_nr' as maaler_nr FROM fm_bim_item"
                                        . " WHERE location_code = 
'{$location_code}'"
                                        . " AND location_id = 
'{$category['location_id']}'"
-                                       . " AND xmlexists('//category[text() = 
''1'']' PASSING BY REF xml_representation)";
+                                       . " AND  
json_representation->>'category' = '1'";
+                               //      . " AND xmlexists('//category[text() = 
''1'']' PASSING BY REF xml_representation)";
 
                                $this->db->query($sql, __LINE__, __FILE__);
 
                                $this->db->next_record();
 
-                               $xmldata = $this->db->f('xml_representation');
-                               $xml = new DOMDocument('1.0', 'utf-8');
-                               $xml->loadXML($xmldata);
-                               return 
$xml->getElementsByTagName('maaler_nr')->item(0)->nodeValue;
+       //                      $xmldata = $this->db->f('xml_representation');
+       //                      $xml = new DOMDocument('1.0', 'utf-8');
+       //                      $xml->loadXML($xmldata);
+       //                      return 
$xml->getElementsByTagName('maaler_nr')->item(0)->nodeValue;
+                               return $this->db->f('maaler_nr');
                        }
                        else
                        {

Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php   2016-08-16 00:01:02 UTC (rev 
15473)
+++ trunk/property/inc/class.uiimport.inc.php   2016-08-16 18:43:57 UTC (rev 
15474)
@@ -452,7 +452,7 @@
 
                                        foreach ($metadata as $field => $info)
                                        {
-                                               if ($field == 
'xml_representation' || $field == 'guid')
+                                               if ($field == 
'json_representation' || $field == 'xml_representation' || $field == 'guid')
                                                {
                                                        continue;
                                                }
@@ -474,13 +474,15 @@
                                                        $_row_data[$_field] = 
$this->db->f($_field, true);
                                                }
 
-                                               $xmldata = 
$this->db->f('xml_representation', true);
-                                               $xml = new DOMDocument('1.0', 
'utf-8');
-                                               $xml->loadXML($xmldata);
+//                                             $xmldata = 
$this->db->f('xml_representation', true);
+//                                             $xml = new DOMDocument('1.0', 
'utf-8');
+//                                             $xml->loadXML($xmldata);
+                                               $jsondata = 
json_decode($this->db->f('json_representation'), true);
 
                                                foreach ($attributes as 
$attribute)
                                                {
-                                                       
$_row_data[$attribute['column_name']] = 
$xml->getElementsByTagName($attribute['column_name'])->item(0)->nodeValue;
+//                                                     
$_row_data[$attribute['column_name']] = 
$xml->getElementsByTagName($attribute['column_name'])->item(0)->nodeValue;
+                                                       
$_row_data[$attribute['column_name']] = $jsondata[$attribute['column_name']];
                                                }
 
                                                $data[] = $_row_data;

Modified: trunk/property/inc/import/import_update_generic.php
===================================================================
--- trunk/property/inc/import/import_update_generic.php 2016-08-16 00:01:02 UTC 
(rev 15473)
+++ trunk/property/inc/import/import_update_generic.php 2016-08-16 18:43:57 UTC 
(rev 15474)
@@ -186,28 +186,29 @@
                                        unset($value_set[$remove_key]);
                                }
 
-                               phpgw::import_class('phpgwapi.xmlhelper');
+//                             phpgw::import_class('phpgwapi.xmlhelper');
+//
+//                             $xmldata = 
phpgwapi_xmlhelper::toXML($value_set, $location_name);
+//                             $doc = new DOMDocument;
+//                             $doc->preserveWhiteSpace = true;
+//                             $doc->loadXML($xmldata);
+//                             $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+//                             $domAttribute = 
$doc->createAttribute('appname');
+//                             $domAttribute->value = 'property';
+//
+//                             // Don't forget to append it to the element
+//                             $domElement->appendChild($domAttribute);
+//
+//                             // Append it to the document itself
+//                             $doc->appendChild($domElement);
+//
+//                             $doc->formatOutput = true;
+//                             $xml = $doc->saveXML();
 
-                               $xmldata = 
phpgwapi_xmlhelper::toXML($value_set, $location_name);
-                               $doc = new DOMDocument;
-                               $doc->preserveWhiteSpace = true;
-                               $doc->loadXML($xmldata);
-                               $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
-                               $domAttribute = 
$doc->createAttribute('appname');
-                               $domAttribute->value = 'property';
-
-                               // Don't forget to append it to the element
-                               $domElement->appendChild($domAttribute);
-
-                               // Append it to the document itself
-                               $doc->appendChild($domElement);
-
-                               $doc->formatOutput = true;
-                               $xml = $doc->saveXML();
-
                                $_value_set = array
                                        (
-                                       'xml_representation' => 
$this->db->db_addslashes($xml),
+//                                     'xml_representation' => 
$this->db->db_addslashes($xml),
+                                       'json_representation' => 
json_encode($value_set),
                                        'p_location_id' => 
isset($value_set['p_location_id']) && $value_set['p_location_id'] ? 
$value_set['p_location_id'] : '',
                                        'p_id' => isset($value_set['p_id']) && 
$value_set['p_id'] ? $value_set['p_id'] : '',
                                        'location_code' => 
$value_set['location_code'],
@@ -223,24 +224,24 @@
                        {
                                $this->warnings[] = "Denne er ny: {$id}, legger 
til";
 
-                               phpgw::import_class('phpgwapi.xmlhelper');
-                               $xmldata = 
phpgwapi_xmlhelper::toXML($value_set, $location_name);
-                               $doc = new DOMDocument;
-                               $doc->preserveWhiteSpace = true;
-                               $doc->loadXML($xmldata);
-                               $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
-                               $domAttribute = 
$doc->createAttribute('appname');
-                               $domAttribute->value = 'property';
+//                             phpgw::import_class('phpgwapi.xmlhelper');
+//                             $xmldata = 
phpgwapi_xmlhelper::toXML($value_set, $location_name);
+//                             $doc = new DOMDocument;
+//                             $doc->preserveWhiteSpace = true;
+//                             $doc->loadXML($xmldata);
+//                             $domElement = 
$doc->getElementsByTagName($location_name)->item(0);
+//                             $domAttribute = 
$doc->createAttribute('appname');
+//                             $domAttribute->value = 'property';
+//
+//                             // Don't forget to append it to the element
+//                             $domElement->appendChild($domAttribute);
+//
+//                             // Append it to the document itself
+//                             $doc->appendChild($domElement);
+//                             $doc->formatOutput = true;
+//
+//                             $xml = $doc->saveXML();
 
-                               // Don't forget to append it to the element
-                               $domElement->appendChild($domAttribute);
-
-                               // Append it to the document itself
-                               $doc->appendChild($domElement);
-                               $doc->formatOutput = true;
-
-                               $xml = $doc->saveXML();
-
                                if (function_exists('com_create_guid') === true)
                                {
                                        $guid = trim(com_create_guid(), '{}');
@@ -256,7 +257,8 @@
                                        'type' => $type,
                                        'location_id' => $location_id,
                                        'guid' => $guid,
-                                       'xml_representation' => 
$this->db->db_addslashes($xml),
+//                                     'xml_representation' => 
$this->db->db_addslashes($xml),
+                                       'json_representation' => 
json_encode($value_set),
                                        'model' => 0,
                                        'p_location_id' => 
isset($value_set['p_location_id']) && $value_set['p_location_id'] ? 
$value_set['p_location_id'] : '',
                                        'p_id' => isset($value_set['p_id']) && 
$value_set['p_id'] ? $value_set['p_id'] : '',




reply via email to

[Prev in Thread] Current Thread [Next in Thread]