fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [9556] eav


From: Sigurd Nes
Subject: [Fmsystem-commits] [9556] eav
Date: Tue, 12 Jun 2012 09:43:45 +0000

Revision: 9556
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9556
Author:   sigurdne
Date:     2012-06-12 09:43:44 +0000 (Tue, 12 Jun 2012)
Log Message:
-----------
eav

Modified Paths:
--------------
    trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb

Modified: trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb      
2012-06-12 09:32:40 UTC (rev 9555)
+++ trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb      
2012-06-12 09:43:44 UTC (rev 9556)
@@ -6,12 +6,26 @@
                public $warnings = array();
                public $errors = array();
                public $debug = true;
+               protected $is_eav;
+               protected $location_id;
+               protected $bim_type_id;
 
                public function __construct()
                {
                        set_time_limit(10000); //Set the time limit for this 
request
                        $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->db           = & $GLOBALS['phpgw']->db;
+                       $this->join                     = $this->db->join;
+                       $admin_entity   = 
CreateObject('property.soadmin_entity');
+                       $admin_entity->type = 'entity';
+                       $category = $admin_entity->read_single_category(4, 1);
+                       $this->is_eav = !!$category['is_eav'];
+                       $this->location_id = 
$GLOBALS['phpgw']->locations->get_id('property', ".entity.4.1");
+
+                       $sql = "SELECT fm_bim_type.id FROM fm_bim_type WHERE 
location_id = {$this->location_id}";
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $this->bim_type_id = $this->db->f('id');
                }
 
                public function add($data)
@@ -32,7 +46,7 @@
     [12] => Tilstand
 */
                        $error = false;
-                       $table = 'fm_entity_4_1';
+
                        $plassering = explode('.', $data[3]);
                        $byggid = $plassering[1];
                        if(!$byggid)
@@ -63,16 +77,16 @@
 
                        $location_code = substr($byggid,0,4) . '-0' . 
substr($byggid,-1);
 //_debug_array($location_code);
+
                        $location_data = 
execMethod('property.solocation.read_single', $location_code );
-//_debug_array($data);
-//_debug_array($location_data);die();
-                       if(!$location_data)
+                       if(!$location_data['loc1'])
                        {
                                $this->errors[] = "Error importing location: 
{$location_code}";
                                $error = true;
-                               return false;
+                               return true;
                        }
 
+
                        if($location_data['street_name'])
                        {
                                $address[]= $location_data['street_name'];
@@ -80,6 +94,29 @@
                                $address        = 
$this->db->db_addslashes(implode(" ", $address));
                        }
 
+
+                       $loc3_data = explode('.........',$data[3]);
+
+                       $loc3_data2 = explode('.',$loc3_data[1] );
+
+                       if(ctype_digit($loc3_data2[0]))
+                       {
+                               $location_code .= '-' . 
sprintf("%02s",$loc3_data2[0]);
+                       }
+
+/*
+_debug_array($loc3_data2);
+_debug_array($location_code);
+die();
+*/
+                       $_location_data = 
execMethod('property.solocation.read_single', $location_code );
+//_debug_array($data);
+                       if(!$_location_data['loc1'])
+                       {
+                               $location_code = substr($byggid,0,4) . '-0' . 
substr($byggid,-1);
+                       }
+
+
                        if(!$address)
                        {
                                $address = 
$this->db->db_addslashes($location_data['loc1_name']);
@@ -117,6 +154,7 @@
                        $value_set['tilstand']                          = 
$this->db->db_addslashes($data[12]);
                $value_set['tilstandsgrad']                     = 
(int)substr($data[12],0,1) + 1;
                $value_set['paafort_text']                      = 
$this->db->db_addslashes($data[13]);
+
 /*
 *    [0] => Identifikasjonsnr
 *    [1] => Betegnelse
@@ -132,7 +170,134 @@
 *    [11] => Historikk
 *    [12] => Tilstand
 */
+                       if($this->is_eav)
+                       {
+                               $ok = $this->_add_eav($id,$value_set);
+                       }
+                       else
+                       {
+                               $ok = $this->_add_eav($id,$value_set);          
        
+                       }
+                       
+                       return $ok;
 
+               }
+               
+               private function _add_eav($id,$data)
+               {
+                       $location_id = (int)$this->location_id;
+                       $sql = "SELECT fm_bim_item.id FROM fm_bim_item WHERE 
fm_bim_item.type = {$this->bim_type_id} AND fm_bim_item.id = {$id}";
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+//                     $this->db->query("SELECT id as type FROM fm_bim_type 
WHERE location_id = {$location_id}",__LINE__,__FILE__);
+//                     $this->db->next_record();
+                       $type = (int)$this->bim_type_id;
+
+
+                       $location_name = '_entity_4_1';
+               
+                       if($this->db->next_record())
+                       {
+                               $this->warnings[] = "ID finnes fra før: {$id}, 
oppdaterer";
+
+
+                               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 = '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();
+
+//                             _debug_array($xml);
+
+                               $value_set = array
+                               (
+                                       'xml_representation'    => 
$this->db->db_addslashes($xml),
+                                       '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'],
+                                       'loc1'                                  
=> $data['loc1'],
+                                       'address'                               
=> $data['address'],
+                               );
+
+                               $value_set      = 
$this->db->validate_update($value_set);
+
+                               return $this->db->query("UPDATE fm_bim_item SET 
$value_set WHERE id = $id AND type = {$type}",__LINE__,__FILE__);
+                       }
+                       else
+                       {
+                               $data['id'] = $id;
+                               $this->warnings[] = "Denne er ny: {$id}, legger 
til";
+
+                               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 = '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();
+
+                       //      _debug_array($xml);
+
+                               if (function_exists('com_create_guid') === true)
+                               {
+                                       $guid = trim(com_create_guid(), '{}');
+                               }
+                               else
+                               {
+                                       $guid = 
sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 
65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), 
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
+                               }
+
+                               $values_insert = array
+                               (
+                                       'id'                                    
=> $id,
+                                       'type'                                  
=> $type,
+                                       'guid'                                  
=> $guid,
+                                       'xml_representation'    => 
$this->db->db_addslashes($xml),
+                                       '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'] : '',
+                                       'location_code'                 => 
$data['location_code'],
+                                       'loc1'                                  
=> $data['loc1'],
+                                       'address'                               
=> $data['address'],
+                                       'entry_date'                    => 
time(),
+                                       'user_id'                               
=> $this->account
+                               );
+
+                               return $this->db->query("INSERT INTO 
fm_bim_item (" . implode(',',array_keys($values_insert)) . ') VALUES ('
+                                . 
$this->db->validate_insert(array_values($values_insert)) . 
')',__LINE__,__FILE__);
+
+                       }
+
+               }
+
+               private function _add_sql()
+               {
+                       $request_ok = false;
+                       $table = 'fm_entity_4_1';               
+
                        $this->db->query("SELECT id FROM {$table} WHERE id = 
{$id}",__LINE__,__FILE__);
                        if($this->db->next_record())
                        {
@@ -159,7 +324,7 @@
                                $request_ok = 
$this->db->query($sql,__LINE__,__FILE__);
                        }
 
-                       if(!$error)
+                       if(!$request_ok)
                        {
                                $this->messages[] = "Successfully imported 
location: Title ({$data[1]})";
                                $ok = true;
@@ -170,5 +335,7 @@
                                $ok = false;
                        }
                        return $ok;
+
                }
+
        }




reply via email to

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