Index: trunk/kernel/units/users/users_item.php =================================================================== diff -u -N -r3907 -r4065 --- trunk/kernel/units/users/users_item.php (.../users_item.php) (revision 3907) +++ trunk/kernel/units/users/users_item.php (.../users_item.php) (revision 4065) @@ -1,62 +1,8 @@ Application->getUnitOption($this->Prefix, 'ItemType'); - $sql = 'SELECT CustomFieldId, FieldName FROM '.TABLE_PREFIX.'CustomField WHERE Type = %s'; - $this->CustomFields = $this->Conn->GetCol( sprintf($sql, $item_type), 'FieldName' ); - } - - - function defineFields() - { - parent::defineFields(); - - // add custom fields definitions (as virtual fields) - $add_fields = Array(); - $custom_field_options = Array('default' => '', 'not_null' => 1); - foreach ($this->CustomFields as $custom_field => $custom_id) - { - $add_fields[$custom_field] = $custom_field_options; - } - - if($add_fields) - { - $add_fields = array_merge_recursive2($add_fields, $this->VirtualFields); - $this->setVirtualFields($add_fields); - } - } - - /** - * Load custom fields values as virtual fields for dbitem - * - * @return bool - */ - function LoadCustomFields() - { - if (!$this->CustomFields) return false; - - $custom_ids = implode(',', $this->CustomFields); - $sql = 'SELECT Value, CustomFieldId - FROM '.TABLE_PREFIX.'CustomMetaData - WHERE ResourceId = '.$this->GetDBField('ResourceId').' AND CustomFieldId IN ('.$custom_ids.')'; - $custom_values = $this->Conn->GetCol($sql, 'CustomFieldId'); - if (!$custom_values) return false; - - $custom_fields = array_flip($this->CustomFields); - foreach ($custom_values as $custom_id => $custom_value) - { - $this->SetDBField($custom_fields[$custom_id], $custom_value); - } - return true; - } - function LoadPersistantVars() { $sql = 'SELECT VariableValue, VariableName @@ -81,41 +27,10 @@ return getArrayValue($this->persistantVars, $var_name); } - function UpdateCustomFields() - { - $data_table = TABLE_PREFIX.'CustomMetaData'; - - // get values already written, to find their ids - $sql = 'SELECT CustomDataId, CustomFieldId - FROM '.$data_table.' - WHERE ResourceId = '.$this->GetDBField('ResourceId'); - $custom_value_ids = $this->Conn->GetCol($sql, 'CustomFieldId'); - $sql = 'REPLACE INTO '.$data_table.'(CustomDataId,ResourceId,CustomFieldId,Value) VALUES (%1$s,%2$s,%3$s,%4$s)'; - - foreach ($this->CustomFields as $custom_field => $custom_id) - { - $data_id = isset($custom_value_ids[$custom_id]) ? $custom_value_ids[$custom_id] : 0; - $custom_value = $this->GetDBField($custom_field); - - if (!$custom_value && $data_id) - { - $temp_sql = 'DELETE FROM '.$data_table.' WHERE CustomDataId = '.$data_id; - $this->Conn->Query($temp_sql); - } - elseif($custom_value) - { - $temp_sql = sprintf($sql, $data_id, $this->GetDBField('ResourceId'), $custom_id, $this->Conn->qstr( $this->GetDBField($custom_field) ) ); - $this->Conn->Query($temp_sql); - } - } - } - function Load($id, $id_field_name = null) { $ret = parent::Load($id, $id_field_name); - if($ret) - { - $this->LoadCustomFields(); + if ($ret) { $this->LoadPersistantVars(); } return $ret; @@ -184,10 +99,7 @@ function Create($force_id=false, $system_create=false) { $ret = parent::Create($force_id, $system_create); - if ($ret) - { - $this->UpdateCustomFields(); - + if ($ret) { // find out how to syncronize user only when it's copied to live table $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('createUser', $this->FieldValues); @@ -199,10 +111,7 @@ function Update($id=null, $system_update=false) { $ret = parent::Update($id, $system_update); - if ($ret) - { - $this->UpdateCustomFields(); - + if ($ret) { // find out how to syncronize user only when it's copied to live table $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('updateUser', $this->FieldValues); @@ -219,9 +128,7 @@ function Delete($id = null) { $ret = parent::Delete($id); - - if ($ret) - { + if ($ret) { $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('deleteUser', $this->FieldValues); }