fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [16336] convert to eav


From: sigurdne
Subject: [Fmsystem-commits] [16336] convert to eav
Date: Sat, 18 Feb 2017 11:46:54 -0500 (EST)

Revision: 16336
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16336
Author:   sigurdne
Date:     2017-02-18 11:46:54 -0500 (Sat, 18 Feb 2017)
Log Message:
-----------
convert to eav

Modified Paths:
--------------
    trunk/property/inc/class.interlink.inc.php
    trunk/property/inc/class.soadmin_location.inc.php
    trunk/property/inc/class.soentity.inc.php
    trunk/property/inc/cron/default/oppdater_antall_leieobjekt.php
    trunk/property/inc/custom/default/hent_maaler_nr_til_besikt_rapport.php
    trunk/property/inc/custom/default/innflyttetdato_entity_2_11_BBB.php
    trunk/property/inc/custom/default/kalkuler_risiko_for_ros.php
    trunk/sms/bin/default/log_firealarm.php

Modified: trunk/property/inc/class.interlink.inc.php
===================================================================
--- trunk/property/inc/class.interlink.inc.php  2017-02-17 15:18:40 UTC (rev 
16335)
+++ trunk/property/inc/class.interlink.inc.php  2017-02-18 16:46:54 UTC (rev 
16336)
@@ -407,21 +407,32 @@
                                $entity_id = $type[2];
                                $cat_id = $type[3];
                                $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity_id}.{$cat_id}");
-                               $metadata = 
$this->_db->metadata("fm_entity_{$entity_id}_{$cat_id}");
-                               if (isset($metadata['status']))
+                               if ($location_id)
                                {
-                                       $sql = "SELECT status FROM 
fm_entity_{$entity_id}_{$cat_id} WHERE id = {$id}";
-                                       $this->_db->query($sql, __LINE__, 
__FILE__);
-                                       $this->_db->next_record();
-                                       $status_id = 
(int)$this->_db->f('status');
+                                       $metadata = 
$this->_db->metadata("fm_entity_{$entity_id}_{$cat_id}");
+                                       if (isset($metadata['status']))
+                                       {
+                                               $sql = "SELECT status FROM 
fm_entity_{$entity_id}_{$cat_id} WHERE id = {$id}";
+                                       }
+                                       else
+                                       {
+                                               $sql = "SELECT 
json_representation->>'status' as status FROM fm_bim_item"
+                                               . " WHERE location_id = 
{$location_id}"
+                                               . " AND id='{$id}'";
+                                       }
 
-                                       $sql = "SELECT phpgw_cust_choice.value 
as status FROM phpgw_cust_attribute"
-                                               . " {$this->_join} 
phpgw_cust_choice ON phpgw_cust_attribute.location_id = 
phpgw_cust_choice.location_id "
-                                               . " AND phpgw_cust_attribute.id 
= phpgw_cust_choice.attrib_id WHERE phpgw_cust_attribute.column_name = 'status'"
-                                               . " AND phpgw_cust_choice.id = 
{$status_id} AND phpgw_cust_attribute.location_id = {$location_id}";
                                        $this->_db->query($sql, __LINE__, 
__FILE__);
                                        $this->_db->next_record();
-                                       $relation_info['statustext'] = 
$this->_db->f('status');
+                                       if($status_id = 
(int)$this->_db->f('status'))
+                                       {
+                                               $sql = "SELECT 
phpgw_cust_choice.value as status FROM phpgw_cust_attribute"
+                                                       . " {$this->_join} 
phpgw_cust_choice ON phpgw_cust_attribute.location_id = 
phpgw_cust_choice.location_id "
+                                                       . " AND 
phpgw_cust_attribute.id = phpgw_cust_choice.attrib_id WHERE 
phpgw_cust_attribute.column_name = 'status'"
+                                                       . " AND 
phpgw_cust_choice.id = {$status_id} AND phpgw_cust_attribute.location_id = 
{$location_id}";
+                                               $this->_db->query($sql, 
__LINE__, __FILE__);
+                                               $this->_db->next_record();
+                                               $relation_info['statustext'] = 
$this->_db->f('status');
+                                       }
                                }
 
                                $relation_info['title'] = 'N∕A';

Modified: trunk/property/inc/class.soadmin_location.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_location.inc.php   2017-02-17 15:18:40 UTC 
(rev 16335)
+++ trunk/property/inc/class.soadmin_location.inc.php   2017-02-18 16:46:54 UTC 
(rev 16336)
@@ -525,6 +525,10 @@
                                $cat_list = 
$entity->read_category(array('allrows' => true, 'entity_id' => $entry['id']));
                                foreach ($cat_list as $category)
                                {
+                                       if($category['is_eav'])
+                                       {
+                                               continue;
+                                       }
                                        $tables[] = 
"fm_entity_{$entry['id']}_{$category['id']}";
                                }
                        }

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2017-02-17 15:18:40 UTC (rev 
16335)
+++ trunk/property/inc/class.soentity.inc.php   2017-02-18 16:46:54 UTC (rev 
16336)
@@ -2345,7 +2345,7 @@
                                }
 
                                $location_id = 
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], 
".{$this->type}.{$entity_id}.{$cat_id}");
-                               $values['id'] = 
$this->_save_eav($values_insert, $location_id, 
".{$this->type}.{$entity_id}.{$cat_id}");
+                               $values['id'] = 
$this->_save_eav($values_insert, $location_id);
                        }
                        else
                        {
@@ -2398,10 +2398,9 @@
                        return $receipt;
                }
 
-               protected function _save_eav( $data = array(), $location_id, 
$location_name )
+               public function _save_eav( $data = array(), $location_id )
                {
                        $location_id = (int)$location_id;
-                       $location_name = str_replace('.', '_', $location_name);
 
                        $this->db->query("SELECT id as type FROM fm_bim_type 
WHERE location_id = {$location_id}", __LINE__, __FILE__);
                        $this->db->next_record();
@@ -2408,26 +2407,6 @@
                        $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];
-//
-//                     // 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)
                        {
                                $guid = trim(com_create_guid(), '{}');
@@ -2443,7 +2422,6 @@
                                'location_id' => $location_id,
                                'type' => $type,
                                'guid' => $guid,
-//                             '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'] : '',

Modified: trunk/property/inc/cron/default/oppdater_antall_leieobjekt.php
===================================================================
--- trunk/property/inc/cron/default/oppdater_antall_leieobjekt.php      
2017-02-17 15:18:40 UTC (rev 16335)
+++ trunk/property/inc/cron/default/oppdater_antall_leieobjekt.php      
2017-02-18 16:46:54 UTC (rev 16336)
@@ -46,6 +46,10 @@
 
                function execute()
                {
+                       return;
+                       
+                       //konverter til eav-modell.
+
                        $this->db->transaction_begin();
 
                        $sql = "SELECT kunde_nr_lev, fm_entity_1_3.loc1, 
fm_entity_1_3.loc2, Count(fm_location4.location_code) AS antall_leieobjekt, 
fm_entity_1_3.location_code

Modified: 
trunk/property/inc/custom/default/hent_maaler_nr_til_besikt_rapport.php
===================================================================
--- trunk/property/inc/custom/default/hent_maaler_nr_til_besikt_rapport.php     
2017-02-17 15:18:40 UTC (rev 16335)
+++ trunk/property/inc/custom/default/hent_maaler_nr_til_besikt_rapport.php     
2017-02-18 16:46:54 UTC (rev 16336)
@@ -27,7 +27,13 @@
 
                function update_data( $values, $values_attribute = array() )
                {
-                       $sql = "SELECT maaler_nr as maaler_nr FROM 
fm_entity_1_11 WHERE location_code='{$values['location_code']}'";
+
+                       $location_id_maaler = 
$GLOBALS['phpgw']->locations->get_id('property', '.entity.1.11');
+
+//                     $sql = "SELECT maaler_nr as maaler_nr FROM 
fm_entity_1_11 WHERE location_code='{$values['location_code']}'";
+                       $sql = "SELECT json_representation->>'maaler_nr' as 
maaler_nr FROM fm_bim_item"
+                               . " WHERE location_id = {$location_id_maaler}"
+                               . " AND 
location_code='{$values['location_code']}'";
                        $this->db->query($sql, __LINE__, __FILE__);
                        $this->db->next_record();
                        $maaler_nr = $this->db->f('maaler_nr');
@@ -36,12 +42,21 @@
                        {
                                if ($maaler_nr)
                                {
-                                       $sql = "UPDATE fm_entity_2_17 SET 
maaler_nr= '{$maaler_nr}' WHERE location_code='{$values['location_code']}'";
+                                       $location_id_rapport = 
$GLOBALS['phpgw']->locations->get_id('property', '.entity.2.17');
+//                                     $sql = "UPDATE fm_entity_2_17 SET 
maaler_nr= '{$maaler_nr}' WHERE location_code='{$values['location_code']}'";
+                                       $sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{maaler_nr}', 
'\"{$maaler_nr}\"', true)"
+                                               . " WHERE location_id = 
{$location_id_rapport}"
+                                               . " AND 
location_code='{$values['location_code']}'"
+                                               . " AND 
json_representation->>'maaler_nr' IS NULL";
                                        $this->db->query($sql, __LINE__, 
__FILE__);
                                }
                        }
 
-                       $sql = "SELECT beskrivelse FROM fm_entity_1_14 WHERE 
location_code='{$values['location_code']}'";
+                       $location_id_bod = 
$GLOBALS['phpgw']->locations->get_id('property', '.entity.1.14');
+//                     $sql = "SELECT beskrivelse FROM fm_entity_1_14 WHERE 
location_code='{$values['location_code']}'";
+                       $sql = "SELECT json_representation->>'beskrivelse' as 
beskrivelse FROM fm_bim_item"
+                               . " WHERE location_id = {$location_id_bod}"
+                               . " AND 
location_code='{$values['location_code']}'";
                        $this->db->query($sql, __LINE__, __FILE__);
                        $this->db->next_record();
                        $bod_beskrivelse = $this->db->f('beskrivelse');
@@ -51,7 +66,11 @@
                        {
                                if ($bod_beskrivelse)
                                {
-                                       $sql = "UPDATE fm_entity_2_17 SET 
boder_antall= '{$bod_beskrivelse}' WHERE 
location_code='{$values['location_code']}'";
+//                                     $sql = "UPDATE fm_entity_2_17 SET 
boder_antall= '{$bod_beskrivelse}' WHERE 
location_code='{$values['location_code']}'";
+                                       $sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{boder_antall}', 
'\"{$bod_beskrivelse}\"', true)"
+                                               . " WHERE location_id = 
{$location_id_rapport}"
+                                               . " AND 
location_code='{$values['location_code']}'"
+                                               . " AND 
json_representation->>'boder_antall' IS NULL";
                                        $this->db->query($sql, __LINE__, 
__FILE__);
                                }
                        }
@@ -88,7 +107,12 @@
                                                        {
                                                                $new_value = 
$entry['value'];
 
-                                                               
$this->db->query("SELECT maaler_stand, id FROM fm_entity_1_11 WHERE maaler_nr = 
'{$maaler_nr}' AND location_code ='{$values['location_code']}'", __LINE__, 
__FILE__);
+//                                                             $sql = "SELECT 
maaler_stand, id FROM fm_entity_1_11 WHERE maaler_nr = '{$maaler_nr}' AND 
location_code ='{$values['location_code']}'";
+                                                               $sql = "SELECT 
json_representation->>'maaler_stand' as maaler_stand, id FROM fm_bim_item"
+                                                                       . " 
WHERE location_id = {$location_id_maaler}"
+                                                                       . " AND 
location_code='{$values['location_code']}'"
+                                                                       . " AND 
json_representation->>'maaler_nr' = '{$maaler_nr}'";
+                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                
$this->db->next_record();
                                                                $old_value = 
$this->db->f('maaler_stand');
                                                                $id = 
$this->db->f('id');
@@ -99,7 +123,12 @@
                                                                        {
                                                                                
$historylog = CreateObject('property.historylog', 'entity_1_11');
                                                                                
$historylog->add('SO', $id, $new_value, false, $attrib_id, $besiktet_dato);
-                                                                               
$this->db->query("UPDATE fm_entity_1_11 SET maaler_stand = '{$new_value}' WHERE 
maaler_nr = '{$maaler_nr}' AND location_code ='{$values['location_code']}'", 
__LINE__, __FILE__);
+
+//                                                                             
$sql ="UPDATE fm_entity_1_11 SET maaler_stand = '{$new_value}' WHERE maaler_nr 
= '{$maaler_nr}' AND location_code ='{$values['location_code']}'";
+                                                                               
$sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{maaler_stand}', 
'\"{$new_value}\"', true)"
+                                                                               
        . " WHERE location_id = {$location_id_maaler}"
+                                                                               
        . " AND location_code='{$values['location_code']}'";
+                                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                        }
                                                                }
                                                        }
@@ -110,7 +139,12 @@
                                                        {
                                                                $new_value = 
$entry['value'];
 
-                                                               
$this->db->query("SELECT beskrivelse, id FROM fm_entity_1_14 WHERE 
location_code ='{$values['location_code']}'", __LINE__, __FILE__);
+                                                               //      
$location_id_bod
+//                                                             $sql = "SELECT 
beskrivelse, id FROM fm_entity_1_14 WHERE location_code 
='{$values['location_code']}'";
+                                                               $sql = "SELECT 
json_representation->>'beskrivelse' as beskrivelse, id FROM fm_bim_item"
+                                                                       . " 
WHERE location_id = {$location_id_bod}"
+                                                                       . " AND 
location_code='{$values['location_code']}'";
+                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                
$this->db->next_record();
                                                                $old_value = 
$this->db->f('beskrivelse');
                                                                $id = 
$this->db->f('id');
@@ -121,7 +155,11 @@
                                                                        {
                                                                                
$historylog = CreateObject('property.historylog', 'entity_1_14');
                                                                                
$historylog->add('SO', $id, $new_value, false, $attrib_id, $besiktet_dato);
-                                                                               
$this->db->query("UPDATE fm_entity_1_14 SET beskrivelse = '{$new_value}' WHERE 
location_code ='{$values['location_code']}'", __LINE__, __FILE__);
+//                                                                             
$sql = "UPDATE fm_entity_1_14 SET beskrivelse = '{$new_value}' WHERE 
location_code ='{$values['location_code']}'";
+                                                                               
$sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{beskrivelse}', 
'\"{$new_value}\"', true)"
+                                                                               
        . " WHERE location_id = {$location_id_bod}"
+                                                                               
        . " AND location_code='{$values['location_code']}'";
+                                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                        }
                                                                }
                                                                else
@@ -142,8 +180,13 @@
                                                case 'br_slokk_app_skiftet':
                                                        if ($entry['value'])
                                                        {
+                                                               
$location_id_br_slokk_app = $GLOBALS['phpgw']->locations->get_id('property', 
'.entity.1.10');
                                                                $new_value = 
$entry['value'];
-                                                               
$this->db->query("SELECT skiftet, id FROM fm_entity_1_10 WHERE location_code 
='{$values['location_code']}'", __LINE__, __FILE__);
+//                                                             $sql = "SELECT 
skiftet, id FROM fm_entity_1_10 WHERE location_code 
='{$values['location_code']}'";
+                                                               $sql = "SELECT 
json_representation->>'skiftet' as skiftet, id FROM fm_bim_item"
+                                                                       . " 
WHERE location_id = {$location_id_br_slokk_app}"
+                                                                       . " AND 
location_code='{$values['location_code']}'";
+                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                
$this->db->next_record();
                                                                $old_value = 
$this->db->f('skiftet');
                                                                $id = 
$this->db->f('id');
@@ -154,7 +197,12 @@
                                                                        {
                                                                                
$historylog = CreateObject('property.historylog', 'entity_1_10');
                                                                                
$historylog->add('SO', $id, $new_value, false, $attrib_id, $besiktet_dato);
-                                                                               
$this->db->query("UPDATE fm_entity_1_10 SET skiftet = '{$new_value}' WHERE 
location_code ='{$values['location_code']}'", __LINE__, __FILE__);
+                                                                               
//                                                                      $sql = 
"UPDATE fm_entity_1_10 SET skiftet = '{$new_value}' WHERE location_code 
='{$values['location_code']}'";
+                                                                               
$sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{skiftet}', 
'\"{$new_value}\"', true)"
+                                                                               
        . " WHERE location_id = {$location_id_br_slokk_app}"
+                                                                               
        . " AND location_code='{$values['location_code']}'";
+
+                                                                               
$this->db->query($sql, __LINE__, __FILE__);
                                                                        }
                                                                }
                                                                else
@@ -180,7 +228,7 @@
 
                private function add_bod( $beskrivelse, $location_code, 
$address )
                {
-                       $table = 'fm_entity_1_14';
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', '.entity.1.14');
                        $location = explode('-', $location_code);
                        $value_set = array();
 
@@ -195,8 +243,6 @@
                                }
                        }
 
-                       $value_set['id'] = $this->bocommon->next_id($table);
-                       $value_set['num'] = $value_set['id'];
                        $value_set['address'] = $address;
                        $value_set['beskrivelse'] = $beskrivelse;
                        $value_set['location_code'] = $location_code;
@@ -203,16 +249,16 @@
                        $value_set['entry_date'] = time();
                        $value_set['user_id'] = $this->account;
 
-                       $cols = implode(',', array_keys($value_set));
-                       $values = 
$this->db->validate_insert(array_values($value_set));
-                       $this->db->query("INSERT INTO $table ({$cols}) VALUES 
({$values})", __LINE__, __FILE__);
+                       $soentity = CreateObject('property.soentity');
+                       $id = $soentity->_save_eav( $value_set, $location_id );
+
                        $historylog = CreateObject('property.historylog', 
'entity_1_14');
-                       $historylog->add('SO', $value_set['id'], $beskrivelse, 
false, $attrib_id = 1, time());
+                       $historylog->add('SO', $id, $beskrivelse, false, 
$attrib_id = 1, time());
                }
 
                private function br_slokk_app( $date, $location_code, $address )
                {
-                       $table = 'fm_entity_1_10';
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', '.entity.1.10');
                        $location = explode('-', $location_code);
                        $value_set = array();
 
@@ -227,8 +273,6 @@
                                }
                        }
 
-                       $value_set['id'] = $this->bocommon->next_id($table);
-                       $value_set['num'] = $value_set['id'];
                        $value_set['address'] = $address;
                        $value_set['skiftet'] = $date;
                        $value_set['location_code'] = $location_code;
@@ -235,11 +279,11 @@
                        $value_set['entry_date'] = time();
                        $value_set['user_id'] = $this->account;
 
-                       $cols = implode(',', array_keys($value_set));
-                       $values = 
$this->db->validate_insert(array_values($value_set));
-                       $this->db->query("INSERT INTO $table ({$cols}) VALUES 
({$values})", __LINE__, __FILE__);
+                       $soentity = CreateObject('property.soentity');
+                       $id = $soentity->_save_eav( $value_set, $location_id );
+
                        $historylog = CreateObject('property.historylog', 
'entity_1_10');
-                       $historylog->add('SO', $value_set['id'], $date, false, 
$attrib_id = 2, time());
+                       $historylog->add('SO', $id, $date, false, $attrib_id = 
2, time());
                }
        }
        $data_sync = new entity_data_sync();

Modified: trunk/property/inc/custom/default/innflyttetdato_entity_2_11_BBB.php
===================================================================
--- trunk/property/inc/custom/default/innflyttetdato_entity_2_11_BBB.php        
2017-02-17 15:18:40 UTC (rev 16335)
+++ trunk/property/inc/custom/default/innflyttetdato_entity_2_11_BBB.php        
2017-02-18 16:46:54 UTC (rev 16336)
@@ -6,7 +6,14 @@
 
        $db = & $GLOBALS['phpgw']->db;
 
-       $sql = "SELECT innflyttet FROM fm_entity_2_11 WHERE location_code ='" . 
$values['location_code'] . "'";
+       $location_id = $GLOBALS['phpgw']->locations->get_id('property', 
'.entity.2.11');
+
+//     $sql = "SELECT innflyttet FROM fm_entity_2_11 WHERE location_code ='" . 
$values['location_code'] . "'";
+
+       $sql = "SELECT id, json_representation->>'innflyttet' as innflyttet 
FROM fm_bim_item"
+               . " WHERE location_id = {$location_id}"
+               . " AND location_code='{$values['location_code']}'"
+               . " ORDER BY id DESC";
        $db->query($sql, __LINE__, __FILE__);
        $db->next_record();
        $innflyttetdato_old = $db->f('innflyttet');
@@ -19,10 +26,15 @@
 
        if ($tenant_id == $values['extra']['tenant_id'] && !$innflyttetdato_old)
        {
-               $value_set['innflyttet'] = $innflyttetdato;
-               $value_set = $db->validate_update($value_set);
+//             $value_set['innflyttet'] = $innflyttetdato;
+//             $value_set = $db->validate_update($value_set);
                $db->transaction_begin();
-               $db->query("UPDATE fm_entity_2_11 set $value_set WHERE id=" . 
(int)$receipt['id'], __LINE__, __FILE__);
+//             $sql = "UPDATE fm_entity_2_11 set $value_set WHERE id=" . 
(int)$receipt['id'];
+               $sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{innflyttet}', 
'\"{$innflyttetdato}\"', true)"
+                       . " WHERE location_id = {$location_id}"
+                       . " AND id=" . (int)$receipt['id'];
+
+               $db->query($sql, __LINE__, __FILE__);
                $db->transaction_commit();
        }
 

Modified: trunk/property/inc/custom/default/kalkuler_risiko_for_ros.php
===================================================================
--- trunk/property/inc/custom/default/kalkuler_risiko_for_ros.php       
2017-02-17 15:18:40 UTC (rev 16335)
+++ trunk/property/inc/custom/default/kalkuler_risiko_for_ros.php       
2017-02-18 16:46:54 UTC (rev 16336)
@@ -73,8 +73,19 @@
                        }
                }
 
-               $value_set = $db->validate_update($value_set);
                $db->transaction_begin();
-               $db->query("UPDATE fm_entity_2_6 set $value_set WHERE id=" . 
(int)$receipt['id'], __LINE__, __FILE__);
+
+               $location_id = $GLOBALS['phpgw']->locations->get_id('property', 
'.entity.2.6');
+
+//             $sql = "UPDATE fm_entity_2_6 set $value_set WHERE id=" . 
(int)$receipt['id'];
+
+               foreach ($value_set as $_key => $_value)
+               {
+                       $sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{{$_key}}', 
'\"{$_value}\"', true)"
+                               . " WHERE location_id = {$location_id}"
+                               . " AND id=" . (int)$receipt['id'];
+                       $db->query($sql, __LINE__, __FILE__);
+               }
+
                $db->transaction_commit();
        }

Modified: trunk/sms/bin/default/log_firealarm.php
===================================================================
--- trunk/sms/bin/default/log_firealarm.php     2017-02-17 15:18:40 UTC (rev 
16335)
+++ trunk/sms/bin/default/log_firealarm.php     2017-02-18 16:46:54 UTC (rev 
16336)
@@ -20,7 +20,7 @@
        $dateformat = "Y-m-d"; //postgres
        $target_field = 'last_alarm';
 
-       $entity_table = 'fm_entity_' . $entity_id . '_' . $cat_id;
+//     $entity_table = 'fm_entity_' . $entity_id . '_' . $cat_id;
 
        $location_id = $GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity_id}.{$cat_id}");
 
@@ -31,18 +31,26 @@
 
        $param = explode(' ', $command_param);
 
-       if (ctype_digit($param[0]))
+       if (ctype_digit($param[0]) && $location_id)
        {
-               $id = $param[0];
+               $id = $this->db->db_addslashes($param[0]);
                //      $status = $status_code[$param[1]];
 
-               $this->db->query("SELECT id as record_id  FROM $entity_table 
WHERE $id_field='$id'", __LINE__, __FILE__);
+//             $sql = "SELECT id as record_id FROM $entity_table WHERE 
$id_field='$id'";
+               $sql = "SELECT id as record_id FROM fm_bim_item"
+                       . " WHERE location_id = {$location_id}"
+                       . " AND json_representation->>'securitnet_nr' = '$id'";
+
+               $this->db->query($sql, __LINE__, __FILE__);
                if ($this->db->next_record())
                {
                        $record_id = $this->db->f('record_id');
                        $date = date($dateformat, time());
 
-                       $this->db->query("UPDATE $entity_table set last_alarm 
='$date' WHERE $id_field='$id'", __LINE__, __FILE__);
+                       $sql = "UPDATE fm_bim_item SET 
json_representation=jsonb_set(json_representation, '{last_alarm}', 
'\"{$date}\"', true)"
+                               . " WHERE location_id = {$location_id}"
+                               . " AND json_representation->>'securitnet_nr' = 
'$id'";
+                       $this->db->query($sql, __LINE__, __FILE__);
                        $historylog = CreateObject('property.historylog', 
'entity_' . $entity_id . '_' . $cat_id);
                        // temporary - fix this
                        $historylog->account = 6;




reply via email to

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