Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/utility/formatters/unit_formatter.php
Show All 23 Lines | |||||
* @param string $field_name | * @param string $field_name | ||||
* @param array $field_options | * @param array $field_options | ||||
* @param kDBBase $object | * @param kDBBase $object | ||||
*/ | */ | ||||
function PrepareOptions($field_name, &$field_options, &$object) | function PrepareOptions($field_name, &$field_options, &$object) | ||||
{ | { | ||||
if( !isset($field_options['master_field']) ) | if( !isset($field_options['master_field']) ) | ||||
{ | { | ||||
/** @var LanguagesItem $regional */ | |||||
$regional = $this->Application->recallObject('lang.current'); | $regional = $this->Application->recallObject('lang.current'); | ||||
/* @var $regional LanguagesItem */ | |||||
$add_fields = Array(); | $add_fields = Array(); | ||||
$options_a = Array('type' => 'int','error_field' => $field_name,'master_field' => $field_name,'format' => '%d' ); | $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' ); | $options_b = Array('type' => 'double','error_field' => $field_name,'master_field' => $field_name,'format' => '%0.2f' ); | ||||
switch( $regional->GetDBField('UnitSystem') ) | switch( $regional->GetDBField('UnitSystem') ) | ||||
{ | { | ||||
case 2: // US/UK | case 2: // US/UK | ||||
Show All 21 Lines | |||||
*/ | */ | ||||
function UpdateMasterFields($field, $value, &$options, &$object) | function UpdateMasterFields($field, $value, &$options, &$object) | ||||
{ | { | ||||
if ( isset($options['master_field']) || ($value == -1) ) { | if ( isset($options['master_field']) || ($value == -1) ) { | ||||
// for infinity setting, otherwise infinity is incorrectly converted back to Kg | // for infinity setting, otherwise infinity is incorrectly converted back to Kg | ||||
return ; | return ; | ||||
} | } | ||||
/** @var LanguagesItem $regional */ | |||||
$regional = $this->Application->recallObject('lang.current'); | $regional = $this->Application->recallObject('lang.current'); | ||||
/* @var $regional LanguagesItem */ | |||||
if ( $regional->GetDBField('UnitSystem') == 2 ) { | if ( $regional->GetDBField('UnitSystem') == 2 ) { | ||||
// US/UK | // US/UK | ||||
$major = $this->TypeCast($object->GetDBField($field . '_a'), $options); | $major = $this->TypeCast($object->GetDBField($field . '_a'), $options); | ||||
$minor = $this->TypeCast($object->GetDBField($field . '_b'), $options); | $minor = $this->TypeCast($object->GetDBField($field . '_b'), $options); | ||||
if ( $major === '' && $minor === '' ) { | if ( $major === '' && $minor === '' ) { | ||||
$value = null; | $value = null; | ||||
Show All 22 Lines | |||||
* @param Array $options | * @param Array $options | ||||
* @param kDBItem $object | * @param kDBItem $object | ||||
* @return void | * @return void | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function UpdateSubFields($field, $value, &$options, &$object) | public function UpdateSubFields($field, $value, &$options, &$object) | ||||
{ | { | ||||
if ( !isset($options['master_field']) ) { | if ( !isset($options['master_field']) ) { | ||||
/** @var LanguagesItem $regional */ | |||||
$regional = $this->Application->recallObject('lang.current'); | $regional = $this->Application->recallObject('lang.current'); | ||||
/* @var $regional LanguagesItem */ | |||||
if ( $regional->GetDBField('UnitSystem') == 2 ) { | if ( $regional->GetDBField('UnitSystem') == 2 ) { | ||||
// US/UK | // US/UK | ||||
if ( $value === null ) { | if ( $value === null ) { | ||||
$major = null; | $major = null; | ||||
$minor = null; | $minor = null; | ||||
} | } | ||||
else { | else { | ||||
list($major, $minor) = kUtil::Kg2Pounds($value); | list($major, $minor) = kUtil::Kg2Pounds($value); | ||||
// $major = floor( $value / 0.5 ); | // $major = floor( $value / 0.5 ); | ||||
// $minor = ($value - $major * 0.5) * 32; | // $minor = ($value - $major * 0.5) * 32; | ||||
} | } | ||||
$object->SetDBField($field . '_a', $major); | $object->SetDBField($field . '_a', $major); | ||||
$object->SetDBField($field . '_b', $minor); | $object->SetDBField($field . '_b', $minor); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |