Index: branches/5.2.x/core/kernel/utility/formatters/unit_formatter.php =================================================================== diff -u -N -r14244 -r14596 --- branches/5.2.x/core/kernel/utility/formatters/unit_formatter.php (.../unit_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/unit_formatter.php (.../unit_formatter.php) (revision 14596) @@ -1,6 +1,6 @@ Application->recallObject('lang.current'); + /* @var $regional LanguagesItem */ + $add_fields = Array(); $options_a = Array('type' => 'int','error_field' => $field_name,'master_field' => $field_name,'format' => '%d' ); $options_b = Array('type' => 'double','error_field' => $field_name,'master_field' => $field_name,'format' => '%0.2f' ); + switch( $regional->GetDBField('UnitSystem') ) { case 2: // US/UK @@ -41,6 +44,7 @@ break; default: } + $add_fields = kUtil::array_merge_recursive($add_fields, $object->getVirtualFields()); $object->setVirtualFields($add_fields); } @@ -57,60 +61,68 @@ */ function UpdateMasterFields($field, $value, &$options, &$object) { - if( !isset($options['master_field']) ) - { - if ($value == -1) return; // for infinity setting, otherwise infinity is incorrectly converted back to Kg - $regional =& $this->Application->recallObject('lang.current'); - switch( $regional->GetDBField('UnitSystem') ) - { - case 2: // US/UK - $major = $this->TypeCast($object->GetDBField($field.'_a'), $options); - $minor = $this->TypeCast($object->GetDBField($field.'_b'), $options); - if($major === '' && $minor === '') - { - $value = null; - } - elseif($major === null && $minor === null) - { - $fields = $object->getFields(); - unset($fields[$field]); - $object->setFields($fields); - return; - } - else - { - $value = kUtil::Pounds2Kg($major, $minor); - } - break; - default: + if ( isset($options['master_field']) || ($value == -1) ) { + // for infinity setting, otherwise infinity is incorrectly converted back to Kg + return ; + } + + $regional =& $this->Application->recallObject('lang.current'); + /* @var $regional LanguagesItem */ + + if ( $regional->GetDBField('UnitSystem') == 2 ) { + // US/UK + $major = $this->TypeCast($object->GetDBField($field . '_a'), $options); + $minor = $this->TypeCast($object->GetDBField($field . '_b'), $options); + + if ( $major === '' && $minor === '' ) { + $value = null; } - $object->SetDBField($field, $value); + elseif ( $major === null && $minor === null ) { + $fields = $object->getFields(); + unset($fields[$field]); + + $object->setFields($fields); + return; + } + else { + $value = kUtil::Pounds2Kg($major, $minor); + } } + + $object->SetDBField($field, $value); } - function UpdateSubFields($field, $value, &$options, &$object) + /** + * Used for split fields like timestamp -> date, time + * Called from DBItem to update sub fields values after loading item + * + * @param string $field + * @param string $value + * @param Array $options + * @param kDBItem $object + * @return void + * @access public + */ + public function UpdateSubFields($field, $value, &$options, &$object) { - if( !isset($options['master_field']) ) - { + if ( !isset($options['master_field']) ) { $regional =& $this->Application->recallObject('lang.current'); - switch( $regional->GetDBField('UnitSystem') ) - { - case 2: // US/UK - if($value === null) - { - $major = null; - $minor = null; - } - else - { - list($major,$minor) = kUtil::Kg2Pounds($value); - /*$major = floor( $value / 0.5 ); - $minor = ($value - $major * 0.5) * 32;*/ - } - $object->SetDBField($field.'_a', $major); - $object->SetDBField($field.'_b', $minor); - break; - default: + /* @var $regional LanguagesItem */ + + if ( $regional->GetDBField('UnitSystem') == 2 ) { + // US/UK + if ( $value === null ) { + $major = null; + $minor = null; + } + else { + list($major, $minor) = kUtil::Kg2Pounds($value); +// $major = floor( $value / 0.5 ); +// $minor = ($value - $major * 0.5) * 32; + } + + $object->SetDBField($field . '_a', $major); + $object->SetDBField($field . '_b', $minor); } } }