[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15435]
From: |
nelson . guerra |
Subject: |
[Fmsystem-commits] [15435] |
Date: |
Tue, 9 Aug 2016 01:03:02 +0000 (UTC) |
Revision: 15435
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15435
Author: nelson224
Date: 2016-08-09 01:03:02 +0000 (Tue, 09 Aug 2016)
Log Message:
-----------
Modified Paths:
--------------
branches/dev-syncromind-2/property/inc/import/import_update_components.php
Modified:
branches/dev-syncromind-2/property/inc/import/import_update_components.php
===================================================================
--- branches/dev-syncromind-2/property/inc/import/import_update_components.php
2016-08-09 01:02:41 UTC (rev 15434)
+++ branches/dev-syncromind-2/property/inc/import/import_update_components.php
2016-08-09 01:03:02 UTC (rev 15435)
@@ -2,9 +2,16 @@
class import_components
{
-
+
protected $db;
-
+ var $type = 'entity';
+ protected $sql;
+ protected $type_app = array
+ (
+ 'entity' => 'property',
+ 'catch' => 'catch'
+ );
+
public function __construct()
{
$this->account =
(int)$GLOBALS['phpgw_info']['user']['account_id'];
@@ -12,9 +19,10 @@
$this->join = $this->db->join;
$this->bo = CreateObject('property.boadmin_entity',
true);
$this->bo_entity = CreateObject('property.boentity',
true);
- $this->type = $this->bo_entity->type;
- $this->type_app = $this->bo_entity->type_app;
+ //$this->type = $this->bo_entity->type;
+ //$this->type_app = $this->bo_entity->type_app;
$this->custom = CreateObject('property.custom_fields');
+ $this->bocommon = CreateObject('property.bocommon');
}
public function get_entity_categories ($data = array())
@@ -85,6 +93,22 @@
return $attributes;
}
+ /*public function set_parent($values, $attributes)
+ {
+ foreach($attributes as &$attribute)
+ {
+ foreach ($values as $value)
+ {
+ if ($attribute['name'] ==
$value['name'])
+ {
+ $attribute['value'] =
$value['value'];
+ }
+ }
+ }
+
+ return $attributes;
+ }*/
+
public function add_entity_categories ($buildingpart_out_table)
{
$buildingparts = array();
@@ -128,11 +152,55 @@
return $buildingparts;
}
- public function add_bim_item($entity_categories, $location)
+ public function add_bim_item($entity_categories, $location_code)
{
- $components_not_added = array();
- foreach ($entity_categories as $entity)
+ $components_added = array();
+ $count = 0;
+
+ $this->db->transaction_begin();
+
+ try
{
+ $this->db->Exception_On_Error = true;
+ foreach ($entity_categories as $entity)
+ {
+ if ($entity['cat_id'])
+ {
+ $attributes =
$this->get_attributes($entity['entity_id'], $entity['cat_id']);
+
+ $not_added = array();
+ foreach ($entity['components']
as $values)
+ {
+ $attributes_values =
$this->set_attributes_values($values, $attributes);
+ $values_insert =
$this->_populate(array('location_code' => $location_code), $attributes_values);
+ //$receipt =
$this->bo_entity->save(array('location' => $location_code), $attributes_values,
'add', $entity['entity_id'], $entity['cat_id']);
+
+ $values['id'] =
$this->_save_eav($values_insert, $entity['entity_id'], $entity['cat_id']);
+ if (!$receipt['id'])
+ {
+ throw new
Exception('import - missing id');
+ }
+
$components_added[$values['benevnelse']] = $receipt['id'];
+ }
+ }
+ }
+ $this->db->Exception_On_Error = false;
+ }
+ catch (Exception $e)
+ {
+ if ($e)
+ {
+ $this->db->transaction_abort();
+ throw $e;
+ }
+ }
+
+ $this->db->transaction_commit();
+
+ return $components_added;
+
+ /*foreach ($entity_categories as $entity)
+ {
if ($entity['cat_id'])
{
$attributes =
$this->get_attributes($entity['entity_id'], $entity['cat_id']);
@@ -141,7 +209,7 @@
foreach ($entity['components'] as
$values)
{
$attributes_values =
$this->set_attributes_values($values, $attributes);
- $receipt =
$this->bo_entity->save(array('location' => $location), $attributes_values,
'add', $entity['entity_id'], $entity['cat_id']);
+ $receipt =
$this->bo_entity->save(array('location' => $location_code), $attributes_values,
'add', $entity['entity_id'], $entity['cat_id']);
if (!$receipt['id'])
{
$not_added[] = 1;
@@ -154,7 +222,164 @@
}
}
- return $components_not_added;
+ return $components_not_added;*/
}
+ private function _save_eav( $data, $entity_id, $cat_id )
+ {
+ $location_id = (int)
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
".{$this->type}.{$entity_id}.{$cat_id}");
+ $location_name =
"_{$this->type}_{$entity_id}_{$cat_id}";
+
+ $this->db->query("SELECT id as type FROM fm_bim_type
WHERE location_id = {$location_id}", __LINE__, __FILE__);
+ $this->db->next_record();
+ $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(), '{}');
+ }
+ 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,
+ 'location_id' => $location_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
+ );
+
+ $this->db->query("INSERT INTO fm_bim_item (" .
implode(',', array_keys($values_insert)) . ') VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) . ')', __LINE__,
__FILE__);
+
+ return $id;
+ }
+
+ private function _populate( $values, $values_attribute )
+ {
+
+ if (is_array($values_attribute))
+ {
+ $values_attribute =
$this->custom->convert_attribute_save($values_attribute);
+ }
+
+ $values_insert = array();
+
+ if (isset($values['street_name']) &&
$values['street_name'])
+ {
+ $address[] = $values['street_name'];
+ $address[] = $values['street_number'];
+ $address = $this->db->db_addslashes(implode("
", $address));
+ }
+
+ if (!isset($address) || !$address)
+ {
+ $address = isset($values['location_name']) ?
$this->db->db_addslashes($values['location_name']) : '';
+ }
+
+ if (isset($address) && $address)
+ {
+ $values_insert['address'] = $address;
+ }
+
+ if (isset($values['location_code']) &&
$values['location_code'])
+ {
+ $values_insert['location_code'] =
$values['location_code'];
+ }
+
+ if (isset($values['location']) &&
is_array($values['location']))
+ {
+ foreach ($values['location'] as $input_name =>
$value)
+ {
+ if (isset($value) && $value)
+ {
+ $values_insert[$input_name] =
$value;
+ }
+ }
+ }
+
+ if (isset($values['extra']) &&
is_array($values['extra']))
+ {
+ foreach ($values['extra'] as $input_name =>
$value)
+ {
+ if (isset($value) && $value)
+ {
+ $values_insert[$input_name] =
$value;
+ }
+ }
+ }
+
+ if (isset($values_attribute) &&
is_array($values_attribute))
+ {
+ foreach ($values_attribute as $entry)
+ {
+ if ($entry['value'])
+ {
+ if ($entry['datatype'] == 'C'
|| $entry['datatype'] == 'T' || $entry['datatype'] == 'V' || $entry['datatype']
== 'link')
+ {
+ $entry['value'] =
$this->db->db_addslashes($entry['value']);
+ }
+ $values_insert[$entry['name']]
= $entry['value'];
+
+ if ($entry['history'] == 1)
+ {
+
$history_set[$entry['attrib_id']] = array
+ (
+ 'value' =>
$entry['value'],
+ 'date' =>
$this->bocommon->date_to_timestamp($entry['date'])
+ );
+ }
+ }
+ }
+ }
+
+ if (isset($values_insert['p_num']) &&
$values_insert['p_num'])
+ {
+ // $p_category =
$admin_entity->read_single_category($values_insert['p_entity_id'],
$values_insert['p_cat_id']);
+ // $p_id = (int)
ltrim($values_insert['p_num'], $p_category['prefix']);
+ $p_id = $values_insert['p_num'];
+ $p_location_id =
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type],
".{$this->type}.{$values_insert['p_entity_id']}.{$values_insert['p_cat_id']}");
+ }
+
+ if (isset($values_insert['p_num']) &&
$values_insert['p_num'])
+ {
+ $values_insert['p_id'] = $p_id;
+ $values_insert['p_location_id'] =
$p_location_id;
+ }
+
+ return $values_insert;
+ }
+
}
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15435],
nelson . guerra <=