@@ -25,7 +25,7 @@ |
||
25 | 25 | if($schema == 'no_currency_code'){ |
26 | 26 | // echo "schema no currency!"; |
27 | 27 | $display_code = false; |
28 | - }else{ |
|
28 | + } else{ |
|
29 | 29 | $display_code = true; |
30 | 30 | } |
31 | 31 | //we don't use the $pretty_float because format_currency will take care of it. |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * Text_Fields is a base class for any fields which are have float value. (Exception: foreign and private key fields. Wish PHP had multiple-inheritance for this...) |
4 | 4 | */ |
5 | -class EE_Money_Field extends EE_Float_Field{ |
|
5 | +class EE_Money_Field extends EE_Float_Field { |
|
6 | 6 | protected $_whole_pennies_only; |
7 | 7 | /** |
8 | 8 | * |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | * @param boolean $whole_pennies_only if TRUE (default) then the internal representation of this |
14 | 14 | * amount will be rounded to a whole penny. If FALSE, then it can be arbitrarily precise |
15 | 15 | */ |
16 | - public function __construct( $table_column, $nicename, $nullable, |
|
17 | - $default_value = null, $whole_pennies_only = true ) { |
|
16 | + public function __construct($table_column, $nicename, $nullable, |
|
17 | + $default_value = null, $whole_pennies_only = true) { |
|
18 | 18 | $this->_whole_pennies_only = $whole_pennies_only; |
19 | - parent::__construct( $table_column, |
|
19 | + parent::__construct($table_column, |
|
20 | 20 | $nicename, |
21 | 21 | $nullable, |
22 | - $default_value ); |
|
22 | + $default_value); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | return $this->_whole_pennies_only; |
31 | 31 | } |
32 | 32 | |
33 | - function get_wpdb_data_type(){ |
|
33 | + function get_wpdb_data_type() { |
|
34 | 34 | return '%f'; |
35 | 35 | } |
36 | 36 | /** |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | * @param type $schema |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted,$schema = null){ |
|
46 | - if( $schema === 'localized_float') { |
|
47 | - $local_float_with_whole_pennies = number_format( $value_on_field_to_be_outputted, EE_Config::instance()->currency->dec_plc, EE_Config::instance()->currency->dec_mrk, EE_Config::instance()->currency->thsnds) ; |
|
48 | - if( $this->whole_pennies_only() ) { |
|
45 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) { |
|
46 | + if ($schema === 'localized_float') { |
|
47 | + $local_float_with_whole_pennies = number_format($value_on_field_to_be_outputted, EE_Config::instance()->currency->dec_plc, EE_Config::instance()->currency->dec_mrk, EE_Config::instance()->currency->thsnds); |
|
48 | + if ($this->whole_pennies_only()) { |
|
49 | 49 | return $local_float_with_whole_pennies; |
50 | 50 | } |
51 | - $local_float_arbitrary_precision = parent::prepare_for_pretty_echoing( $value_on_field_to_be_outputted ); |
|
51 | + $local_float_arbitrary_precision = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
52 | 52 | $pos_of_decimal_place = strpos( |
53 | 53 | $local_float_arbitrary_precision, |
54 | 54 | EE_Config::instance()->currency->dec_mrk |
@@ -58,23 +58,22 @@ discard block |
||
58 | 58 | $local_float_arbitrary_precision, |
59 | 59 | $pos_of_decimal_place |
60 | 60 | ) |
61 | - ) : |
|
62 | - 0; |
|
63 | - if( $local_float_arbitrary_precision_length_after_decimal <= EE_Config::instance()->currency->dec_plc ){ |
|
61 | + ) : 0; |
|
62 | + if ($local_float_arbitrary_precision_length_after_decimal <= EE_Config::instance()->currency->dec_plc) { |
|
64 | 63 | return $local_float_with_whole_pennies; |
65 | 64 | } else { |
66 | 65 | return $local_float_arbitrary_precision; |
67 | 66 | } |
68 | 67 | } |
69 | 68 | |
70 | - if($schema == 'no_currency_code'){ |
|
69 | + if ($schema == 'no_currency_code') { |
|
71 | 70 | // echo "schema no currency!"; |
72 | 71 | $display_code = false; |
73 | - }else{ |
|
72 | + } else { |
|
74 | 73 | $display_code = true; |
75 | 74 | } |
76 | 75 | //we don't use the $pretty_float because format_currency will take care of it. |
77 | - return EEH_Template::format_currency( $value_on_field_to_be_outputted, false, $display_code ); |
|
76 | + return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
78 | 77 | } |
79 | 78 | |
80 | 79 | /** |
@@ -89,12 +88,12 @@ discard block |
||
89 | 88 | //now it's a float-style string or number |
90 | 89 | $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
91 | 90 | //round to the correctly number of decimal places for this currency |
92 | - return $this->_round_if_no_partial_pennies( $float_val ); |
|
91 | + return $this->_round_if_no_partial_pennies($float_val); |
|
93 | 92 | |
94 | 93 | } |
95 | 94 | |
96 | 95 | function prepare_for_get($value_of_field_on_model_object) { |
97 | - return $this->_round_if_no_partial_pennies( parent::prepare_for_get($value_of_field_on_model_object) ); |
|
96 | + return $this->_round_if_no_partial_pennies(parent::prepare_for_get($value_of_field_on_model_object)); |
|
98 | 97 | } |
99 | 98 | |
100 | 99 | /** |
@@ -103,9 +102,9 @@ discard block |
||
103 | 102 | * @param type $amount |
104 | 103 | * @return float |
105 | 104 | */ |
106 | - protected function _round_if_no_partial_pennies( $amount ) { |
|
107 | - if( $this->whole_pennies_only() ) { |
|
108 | - return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code ); |
|
105 | + protected function _round_if_no_partial_pennies($amount) { |
|
106 | + if ($this->whole_pennies_only()) { |
|
107 | + return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); |
|
109 | 108 | } else { |
110 | 109 | return $amount; |
111 | 110 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * Text_Fields is a base class for any fields which are have float value. (Exception: foreign and private key fields. Wish PHP had multiple-inheritance for this...) |
4 | 4 | */ |
5 | -class EE_Float_Field extends EE_Model_Field_Base{ |
|
6 | - function get_wpdb_data_type(){ |
|
5 | +class EE_Float_Field extends EE_Model_Field_Base { |
|
6 | + function get_wpdb_data_type() { |
|
7 | 7 | return '%f'; |
8 | 8 | } |
9 | 9 | /** |
@@ -17,26 +17,26 @@ discard block |
||
17 | 17 | function prepare_for_set($value_inputted_for_field_on_model_object) { |
18 | 18 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
19 | 19 | //remove whitespaces and thousands separators |
20 | - if(is_string($value_inputted_for_field_on_model_object)){ |
|
21 | - $value_inputted_for_field_on_model_object = str_replace(array(" ",EE_Config::instance()->currency->thsnds),"",$value_inputted_for_field_on_model_object); |
|
20 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
21 | + $value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds), "", $value_inputted_for_field_on_model_object); |
|
22 | 22 | //echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
23 | 23 | //normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
24 | - $value_inputted_for_field_on_model_object = str_replace( EE_Config::instance()->currency->dec_mrk, ".", $value_inputted_for_field_on_model_object) ; |
|
24 | + $value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".", $value_inputted_for_field_on_model_object); |
|
25 | 25 | //echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
26 | 26 | //double-check there's absolutely nothing left on this string besides numbers |
27 | - $value_inputted_for_field_on_model_object = preg_replace( "/[^0-9,.]/", "", $value_inputted_for_field_on_model_object); |
|
27 | + $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object); |
|
28 | 28 | } |
29 | 29 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
30 | - return floatval( $value_inputted_for_field_on_model_object ); |
|
30 | + return floatval($value_inputted_for_field_on_model_object); |
|
31 | 31 | } |
32 | 32 | /** |
33 | 33 | * Returns the number formatted according to local custom (set by the country of the blog). |
34 | 34 | * @param float $value_on_field_to_be_outputted |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted,$schema = null){ |
|
37 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) { |
|
38 | 38 | $EE = EE_Registry::instance(); |
39 | - $localized_float = number_format( $value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk, $EE->CFG->currency->thsnds) ; |
|
39 | + $localized_float = number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk, $EE->CFG->currency->thsnds); |
|
40 | 40 | //note however: this only includes the number of decimal places we'd want for currency, which might not be right |
41 | 41 | //we don't want to lose any extra precision, |
42 | 42 | //so: compare everything after the decimal place (of original and localized) |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $localized_float, |
46 | 46 | EE_Config::instance()->currency->dec_mrk |
47 | 47 | ); |
48 | - $float_as_string = (string)$value_on_field_to_be_outputted; |
|
48 | + $float_as_string = (string) $value_on_field_to_be_outputted; |
|
49 | 49 | $contents_after_decimal = substr( |
50 | 50 | $float_as_string, |
51 | 51 | strpos( |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | '.' |
54 | 54 | ) - 1 |
55 | 55 | ); |
56 | - $localized_float = substr( $localized_float, 0, $pos_of_decimal_in_localized_string - 1 ) . $contents_after_decimal; |
|
56 | + $localized_float = substr($localized_float, 0, $pos_of_decimal_in_localized_string - 1).$contents_after_decimal; |
|
57 | 57 | return $localized_float; |
58 | 58 | } |
59 | 59 |