[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [8134] Property: more on EAV
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [8134] Property: more on EAV |
Date: |
Sun, 20 Nov 2011 21:02:53 +0000 |
Revision: 8134
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8134
Author: sigurdne
Date: 2011-11-20 21:02:53 +0000 (Sun, 20 Nov 2011)
Log Message:
-----------
Property: more on EAV
Modified Paths:
--------------
trunk/property/inc/class.boadmin_entity.inc.php
trunk/property/inc/class.menu.inc.php
trunk/property/inc/class.soadmin_entity.inc.php
trunk/property/inc/class.soentity.inc.php
trunk/property/inc/class.uiadmin_entity.inc.php
Modified: trunk/property/inc/class.boadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.boadmin_entity.inc.php 2011-11-20 11:01:52 UTC
(rev 8133)
+++ trunk/property/inc/class.boadmin_entity.inc.php 2011-11-20 21:02:53 UTC
(rev 8134)
@@ -571,4 +571,9 @@
{
return $this->so->get_children2($entity_id, $parent,
$level,$reset);
}
+
+ function convert_to_eav()
+ {
+ return $this->so->convert_to_eav();
+ }
}
Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php 2011-11-20 11:01:52 UTC (rev
8133)
+++ trunk/property/inc/class.menu.inc.php 2011-11-20 21:02:53 UTC (rev
8134)
@@ -101,6 +101,11 @@
*/
}
}
+ $admin_children_entity['convert_to_eav'] = array
+ (
+ 'text' => lang('convert to
eav'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'property.uiadmin_entity.convert_to_eav') )
+ );
$admin_children_tenant = array
(
Modified: trunk/property/inc/class.soadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_entity.inc.php 2011-11-20 11:01:52 UTC
(rev 8133)
+++ trunk/property/inc/class.soadmin_entity.inc.php 2011-11-20 21:02:53 UTC
(rev 8134)
@@ -1044,4 +1044,121 @@
$this->oProc->m_odb = & $this->db;
$this->oProc->m_odb->Halt_On_Error = 'yes';
}
+
+
+ /**
+ * Reduserer fra 684 til 265 tabeller for Nordlandssykehuset
+ *
+ * @return bool true on success
+ */
+ function convert_to_eav()
+ {
+ die('vent litt med denne');
+
+ phpgw::import_class('phpgwapi.xmlhelper');
+ $this->type = 'entity';
+ $entity_list = $this->read(array('allrows' => true));
+
+ $this->db->transaction_begin();
+
+ foreach($entity_list as $entry)
+ {
+ $cat_list =
$this->read_category(array('allrows'=>true,'entity_id'=>$entry['id']));
+
+ foreach($cat_list as $category)
+ {
+ if(!$category['is_eav'])
+ {
+
+ $location_id =
$GLOBALS['phpgw']->locations->get_id('property',
".{$this->type}.{$category['entity_id']}.{$category['id']}");
+ $values_insert = array
+ (
+ 'location_id' =>
$location_id,
+ 'name'
=>
".{$this->type}.{$category['entity_id']}.{$category['id']}::{$category['name']}",
+ 'description' =>
$category['descr'],
+ 'is_ifc'
=> 0
+ );
+
+ $this->db->query('INSERT INTO
fm_bim_type (' . implode(',',array_keys($values_insert)) . ') VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) .
')',__LINE__,__FILE__);
+
+ $sql = "UPDATE
fm_{$this->type}_category SET is_eav = 1 WHERE entity_id =" .
(int)$category['entity_id'] . ' AND id = ' . (int)$category['id'];
+
$this->db->query($sql,__LINE__,__FILE__);
+
+ $sql = "UPDATE phpgw_locations
SET c_attrib_table = NULL WHERE location_id = {$location_id}";
+
$this->db->query($sql,__LINE__,__FILE__);
+
+ $type =
$this->db->get_last_insert_id('fm_bim_type', 'id');
+
+ $sql = "SELECT * FROM
fm_{$this->type}_{$category['entity_id']}_{$category['id']}";
+
$this->db->query($sql,__LINE__,__FILE__);
+ while ($this->db->next_record())
+ {
+ $data =
$this->db->Record;
+
+ $xmldata =
phpgwapi_xmlhelper::toXML($data,
"_{$this->type}_{$category['entity_id']}_{$category['id']}");
+ $doc = new DOMDocument;
+ $domElement =
$doc->getElementsByTagName("_{$this->type}_{$category['entity_id']}_{$category['id']}")->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->preserveWhiteSpace = true;
+ $doc->loadXML( $xmldata
);
+ $doc->formatOutput =
true;
+ $xml = $doc->saveXML();
+
+ $p_location_id = '';
+ if($data['p_cat_id'])
+ {
+ $p_location_id
= $GLOBALS['phpgw']->locations->get_id('property',
".{$this->type}.{$data['p_entity_id']}.{$data['p_cat_id']}");
+ }
+
+ $p_id ='';
+ if($data['p_num'])
+ {
+ $p_id
= (int) ltrim($data['p_num'], $category['prefix']);
+ }
+ 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'
=> $data['id'],
+ 'type'
=> $type,
+ 'guid'
=> $guid,
+
'xml_representation' => $this->db->db_addslashes($xml),
+ 'model'
=> 0,
+ 'p_location_id'
=> $p_location_id,
+ 'p_id'
=> isset($data['p_num']) && $data['p_num'] ?
(int)$data['p_num'] : '',
+ 'location_code'
=> $data['location_code'],
+ 'loc1'
=> $data['loc1'],
+ 'address'
=> $data['address'],
+ 'entry_date'
=> $data['entry_date'],
+ 'user_id'
=> $data['user_id']
+ );
+
+
$this->db->query("INSERT INTO fm_bim_item (" .
implode(',',array_keys($values_insert)) . ') VALUES ('
+ .
$this->db->validate_insert(array_values($values_insert)) .
')',__LINE__,__FILE__);
+ }
+
+ $sql = "DROP TABLE
fm_{$this->type}_{$category['entity_id']}_{$category['id']}";
+ _debug_array($sql);
+
$this->db->query($sql,__LINE__,__FILE__);
+ }
+ }
+ }
+ return $this->db->transaction_commit();
+ }
}
Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php 2011-11-20 11:01:52 UTC (rev
8133)
+++ trunk/property/inc/class.soentity.inc.php 2011-11-20 21:02:53 UTC (rev
8134)
@@ -649,7 +649,7 @@
$sql .= $_joinmethod;
}
-_debug_array($sql);
+//_debug_array($sql);
$querymethod = '';
$_querymethod = array_merge($__querymethod,
$_querymethod);
@@ -1549,7 +1549,7 @@
}
$location_id =
$GLOBALS['phpgw']->locations->get_id('property',
".{$this->type}.{$entity_id}.{$cat_id}");
- $values['id'] =
$this->_save_eav($values_insert, $location_id);
+ $values['id'] =
$this->_save_eav($values_insert, $location_id,
".{$this->type}.{$entity_id}.{$cat_id}");
}
else
{
@@ -1601,20 +1601,32 @@
return $receipt;
}
- protected function _save_eav($data = array(),$location_id)
+ protected function _save_eav($data = array(),$location_id,
$location_name)
{
$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();
$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, 'PHPGW');
+ $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);
@@ -1650,20 +1662,32 @@
return $id;
}
- protected function _edit_eav($data = array(),$location_id, $id)
+ protected function _edit_eav($data = array(),$location_id,
$location_name, $id)
{
$location_id = (int) $location_id;
- $id = (int) $id;
+ $id = (int) $id;
+ $location_name = str_replace('.', '_', $location_name);
phpgw::import_class('phpgwapi.xmlhelper');
- $xmldata = phpgwapi_xmlhelper::toXML($data, 'PHPGW');
+
+ $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);
+// _debug_array($xml);
$value_set = array
(
@@ -1805,7 +1829,7 @@
}
$location_id =
$GLOBALS['phpgw']->locations->get_id('property',
".{$this->type}.{$entity_id}.{$cat_id}");
- $this->_edit_eav($value_set, $location_id,
$values['id']);
+ $this->_edit_eav($value_set, $location_id,
".{$this->type}.{$entity_id}.{$cat_id}", $values['id']);
}
else
{
Modified: trunk/property/inc/class.uiadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.uiadmin_entity.inc.php 2011-11-20 11:01:52 UTC
(rev 8133)
+++ trunk/property/inc/class.uiadmin_entity.inc.php 2011-11-20 21:02:53 UTC
(rev 8134)
@@ -57,7 +57,8 @@
'edit_attrib' => true,
'list_custom_function' => true,
'edit_custom_function' => true,
- 'get_template_attributes'=> true
+ 'get_template_attributes'=> true,
+ 'convert_to_eav' => true
);
function property_uiadmin_entity()
@@ -2923,4 +2924,50 @@
$GLOBALS['phpgw_info']['flags']['app_header'] =
lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit_custom_function' =>
$data));
}
+
+ function convert_to_eav()
+ {
+ $GLOBALS['phpgw_info']['flags']['menu_selection'] =
"admin::{$this->type_app[$this->type]}::entity::convert_to_eav";
+ $function = 'list_attribute';
+ if ( $custom_function_id )
+ {
+ $function = 'list_custom_function';
+ }
+
+ $redirect_args = array
+ (
+ 'menuaction' =>
'admin.uimainscreen.mainscreen'
+ );
+
+ if ( phpgw::get_var('delete', 'bool', 'POST') )
+ {
+ $this->bo->convert_to_eav();
+ $GLOBALS['phpgw']->redirect_link('/index.php',
$redirect_args);
+ }
+
+ if ( phpgw::get_var('cancel', 'bool', 'POST') )
+ {
+ $GLOBALS['phpgw']->redirect_link('/index.php',
$redirect_args);
+ }
+
+ $GLOBALS['phpgw']->xslttpl->add_file(array('delete'));
+
+ $link_data = array
+ (
+ 'menuaction' =>
'property.uiadmin_entity.convert_to_eav',
+ );
+
+ $data = array
+ (
+ 'delete_url' =>
$GLOBALS['phpgw']->link('/index.php', $link_data),
+ 'lang_confirm_msg' =>
lang('do you really want to convert to eav'),
+ 'lang_delete' =>
lang('yes'),
+ 'lang_cancel' =>
lang('no')
+ );
+
+ $function_msg = lang('convert to eav');
+
+ $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('property'). '::' . $function_msg;
+
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('delete' => $data));
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [8134] Property: more on EAV,
Sigurd Nes <=