@@ -12,30 +12,30 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class EE_DB_Only_Field_Base extends EE_Model_Field_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * @param string $table_column |
|
17 | - * @param string $nicename |
|
18 | - * @param bool $nullable |
|
19 | - * @param null $default_value |
|
20 | - */ |
|
21 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
22 | - { |
|
23 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
24 | - $this->setSchemaType(SchemaType::STRING); |
|
25 | - $this->setSchemaReadOnly(true); |
|
26 | - $this->setDataType(DataType::STRING); |
|
27 | - } |
|
15 | + /** |
|
16 | + * @param string $table_column |
|
17 | + * @param string $nicename |
|
18 | + * @param bool $nullable |
|
19 | + * @param null $default_value |
|
20 | + */ |
|
21 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
22 | + { |
|
23 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
24 | + $this->setSchemaType(SchemaType::STRING); |
|
25 | + $this->setSchemaReadOnly(true); |
|
26 | + $this->setDataType(DataType::STRING); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * All these children classes are for the db-only (meaning, we should select them |
|
32 | - * on get_all queries, update, delete, and will still want to set their default value |
|
33 | - * on inserts, but the model object won't have reference to these fields) |
|
34 | - * |
|
35 | - * @return boolean |
|
36 | - */ |
|
37 | - public function is_db_only_field(): bool |
|
38 | - { |
|
39 | - return true; |
|
40 | - } |
|
30 | + /** |
|
31 | + * All these children classes are for the db-only (meaning, we should select them |
|
32 | + * on get_all queries, update, delete, and will still want to set their default value |
|
33 | + * on inserts, but the model object won't have reference to these fields) |
|
34 | + * |
|
35 | + * @return boolean |
|
36 | + */ |
|
37 | + public function is_db_only_field(): bool |
|
38 | + { |
|
39 | + return true; |
|
40 | + } |
|
41 | 41 | } |
@@ -9,27 +9,27 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Integer_Field extends EE_Model_Field_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string $table_column |
|
14 | - * @param string $nicename |
|
15 | - * @param bool $nullable |
|
16 | - * @param null $default_value |
|
17 | - */ |
|
18 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
19 | - { |
|
20 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
21 | - $this->setSchemaType(SchemaType::INTEGER); |
|
22 | - $this->setDataType(DataType::INTEGER); |
|
23 | - } |
|
12 | + /** |
|
13 | + * @param string $table_column |
|
14 | + * @param string $nicename |
|
15 | + * @param bool $nullable |
|
16 | + * @param null $default_value |
|
17 | + */ |
|
18 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
19 | + { |
|
20 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
21 | + $this->setSchemaType(SchemaType::INTEGER); |
|
22 | + $this->setDataType(DataType::INTEGER); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - return intval($value_inputted_for_field_on_model_object); |
|
29 | - } |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + return intval($value_inputted_for_field_on_model_object); |
|
29 | + } |
|
30 | 30 | |
31 | - public function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
32 | - { |
|
33 | - return intval($value_inputted_for_field_on_model_object); |
|
34 | - } |
|
31 | + public function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
32 | + { |
|
33 | + return intval($value_inputted_for_field_on_model_object); |
|
34 | + } |
|
35 | 35 | } |
@@ -16,41 +16,41 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Email_Field extends EE_Text_Field_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @param string $table_column |
|
21 | - * @param string $nice_name |
|
22 | - * @param bool $nullable |
|
23 | - * @param null $default_value |
|
24 | - * @throws InvalidArgumentException |
|
25 | - */ |
|
26 | - public function __construct($table_column, $nice_name, $nullable, $default_value = null) |
|
27 | - { |
|
28 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
29 | - $this->setSchemaFormat(SchemaFormat::EMAIL); |
|
30 | - $this->setDataType(DataType::EMAIL); |
|
31 | - } |
|
19 | + /** |
|
20 | + * @param string $table_column |
|
21 | + * @param string $nice_name |
|
22 | + * @param bool $nullable |
|
23 | + * @param null $default_value |
|
24 | + * @throws InvalidArgumentException |
|
25 | + */ |
|
26 | + public function __construct($table_column, $nice_name, $nullable, $default_value = null) |
|
27 | + { |
|
28 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
29 | + $this->setSchemaFormat(SchemaFormat::EMAIL); |
|
30 | + $this->setDataType(DataType::EMAIL); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
36 | - * so we need to undo that on setting of these fields |
|
37 | - * |
|
38 | - * @param string $email_address |
|
39 | - * @return string |
|
40 | - * @throws InvalidArgumentException |
|
41 | - * @throws InvalidInterfaceException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - */ |
|
44 | - public function prepare_for_set($email_address) |
|
45 | - { |
|
46 | - if (empty($email_address)) { |
|
47 | - return ''; |
|
48 | - } |
|
49 | - try { |
|
50 | - $email_address_obj = EmailAddressFactory::create($email_address); |
|
51 | - return $email_address_obj instanceof EmailAddress ? $email_address_obj->get() : ''; |
|
52 | - } catch (EmailValidationException $e) { |
|
53 | - return ''; |
|
54 | - } |
|
55 | - } |
|
34 | + /** |
|
35 | + * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
36 | + * so we need to undo that on setting of these fields |
|
37 | + * |
|
38 | + * @param string $email_address |
|
39 | + * @return string |
|
40 | + * @throws InvalidArgumentException |
|
41 | + * @throws InvalidInterfaceException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + */ |
|
44 | + public function prepare_for_set($email_address) |
|
45 | + { |
|
46 | + if (empty($email_address)) { |
|
47 | + return ''; |
|
48 | + } |
|
49 | + try { |
|
50 | + $email_address_obj = EmailAddressFactory::create($email_address); |
|
51 | + return $email_address_obj instanceof EmailAddress ? $email_address_obj->get() : ''; |
|
52 | + } catch (EmailValidationException $e) { |
|
53 | + return ''; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | } |
@@ -4,26 +4,26 @@ |
||
4 | 4 | |
5 | 5 | class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base |
6 | 6 | { |
7 | - public function __construct($table_column, $nicename) |
|
8 | - { |
|
9 | - parent::__construct($table_column, $nicename, null); |
|
10 | - $this->setDataType(DataType::STRING); |
|
11 | - } |
|
7 | + public function __construct($table_column, $nicename) |
|
8 | + { |
|
9 | + parent::__construct($table_column, $nicename, null); |
|
10 | + $this->setDataType(DataType::STRING); |
|
11 | + } |
|
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * removes all tags when setting |
|
16 | - * |
|
17 | - * @param EE_Base_Class|string|null $value_inputted_for_field_on_model_object |
|
18 | - * @return string |
|
19 | - * @throws EE_Error |
|
20 | - * @throws ReflectionException |
|
21 | - */ |
|
22 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
23 | - { |
|
24 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
25 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
26 | - } |
|
27 | - return wp_strip_all_tags((string) $value_inputted_for_field_on_model_object); |
|
28 | - } |
|
14 | + /** |
|
15 | + * removes all tags when setting |
|
16 | + * |
|
17 | + * @param EE_Base_Class|string|null $value_inputted_for_field_on_model_object |
|
18 | + * @return string |
|
19 | + * @throws EE_Error |
|
20 | + * @throws ReflectionException |
|
21 | + */ |
|
22 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
23 | + { |
|
24 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
25 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
26 | + } |
|
27 | + return wp_strip_all_tags((string) $value_inputted_for_field_on_model_object); |
|
28 | + } |
|
29 | 29 | } |
@@ -9,69 +9,69 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class EE_Text_Field_Base extends EE_Model_Field_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string $table_column |
|
14 | - * @param string $nicename |
|
15 | - * @param bool $nullable |
|
16 | - * @param null $default_value |
|
17 | - */ |
|
18 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
19 | - { |
|
20 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
21 | - $this->setSchemaType(SchemaType::STRING); |
|
22 | - $this->setDataType(DataType::STRING); |
|
23 | - } |
|
12 | + /** |
|
13 | + * @param string $table_column |
|
14 | + * @param string $nicename |
|
15 | + * @param bool $nullable |
|
16 | + * @param null $default_value |
|
17 | + */ |
|
18 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
19 | + { |
|
20 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
21 | + $this->setSchemaType(SchemaType::STRING); |
|
22 | + $this->setDataType(DataType::STRING); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Gets the value in the format expected when being set. |
|
28 | - * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead. |
|
29 | - * |
|
30 | - * @param mixed $value_of_field_on_model_object |
|
31 | - * @return mixed|string |
|
32 | - */ |
|
33 | - public function prepare_for_get($value_of_field_on_model_object) |
|
34 | - { |
|
35 | - if ($value_of_field_on_model_object === null) { |
|
36 | - return $this->is_nullable() ? null : ''; |
|
37 | - } |
|
38 | - return $value_of_field_on_model_object; |
|
39 | - } |
|
26 | + /** |
|
27 | + * Gets the value in the format expected when being set. |
|
28 | + * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead. |
|
29 | + * |
|
30 | + * @param mixed $value_of_field_on_model_object |
|
31 | + * @return mixed|string |
|
32 | + */ |
|
33 | + public function prepare_for_get($value_of_field_on_model_object) |
|
34 | + { |
|
35 | + if ($value_of_field_on_model_object === null) { |
|
36 | + return $this->is_nullable() ? null : ''; |
|
37 | + } |
|
38 | + return $value_of_field_on_model_object; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
44 | - * |
|
45 | - * @param mixed $value_on_field_to_be_outputted |
|
46 | - * @param string|null $schema |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, ?string $schema = null) |
|
50 | - { |
|
51 | - if ($schema === 'form_input') { |
|
52 | - $value_on_field_to_be_outputted = htmlentities( |
|
53 | - (string) $value_on_field_to_be_outputted, |
|
54 | - ENT_QUOTES, |
|
55 | - 'UTF-8' |
|
56 | - ); |
|
57 | - } |
|
58 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
59 | - } |
|
42 | + /** |
|
43 | + * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
44 | + * |
|
45 | + * @param mixed $value_on_field_to_be_outputted |
|
46 | + * @param string|null $schema |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, ?string $schema = null) |
|
50 | + { |
|
51 | + if ($schema === 'form_input') { |
|
52 | + $value_on_field_to_be_outputted = htmlentities( |
|
53 | + (string) $value_on_field_to_be_outputted, |
|
54 | + ENT_QUOTES, |
|
55 | + 'UTF-8' |
|
56 | + ); |
|
57 | + } |
|
58 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Data received from the user should be exactly as they hope to save it in the DB, with the exception that |
|
64 | - * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP |
|
65 | - * in magic-quotes fashion. We used to call html_entity_decode on the value here, |
|
66 | - * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary |
|
67 | - * because web browsers always decode HTML entities in element attributes, like a form element's value attribute. |
|
68 | - * So if we do it again here, we'll be removing HTML entities the user intended to have.) |
|
69 | - * |
|
70 | - * @param string|null $value_inputted_for_field_on_model_object |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
74 | - { |
|
75 | - return stripslashes((string) parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
76 | - } |
|
62 | + /** |
|
63 | + * Data received from the user should be exactly as they hope to save it in the DB, with the exception that |
|
64 | + * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP |
|
65 | + * in magic-quotes fashion. We used to call html_entity_decode on the value here, |
|
66 | + * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary |
|
67 | + * because web browsers always decode HTML entities in element attributes, like a form element's value attribute. |
|
68 | + * So if we do it again here, we'll be removing HTML entities the user intended to have.) |
|
69 | + * |
|
70 | + * @param string|null $value_inputted_for_field_on_model_object |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
74 | + { |
|
75 | + return stripslashes((string) parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
76 | + } |
|
77 | 77 | } |
@@ -11,96 +11,96 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Usually the name of a single model. However, as in the case for custom post types, |
|
16 | - * it can actually be an array of models |
|
17 | - * |
|
18 | - * @var string[] |
|
19 | - */ |
|
20 | - protected $_model_name_pointed_to; |
|
14 | + /** |
|
15 | + * Usually the name of a single model. However, as in the case for custom post types, |
|
16 | + * it can actually be an array of models |
|
17 | + * |
|
18 | + * @var string[] |
|
19 | + */ |
|
20 | + protected $_model_name_pointed_to; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $table_column name of column for field |
|
25 | - * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
26 | - * @param boolean $nullable |
|
27 | - * @param int|string $default_value data type should match field type |
|
28 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
29 | - * Basically it's the model class's name without the "EEM_" |
|
30 | - */ |
|
31 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
32 | - { |
|
33 | - $this->_model_name_pointed_to = (array) $model_name; |
|
34 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
35 | - $this->setSchemaType(SchemaType::STRING); |
|
36 | - $this->setDataType(DataType::STRING); |
|
37 | - } |
|
23 | + /** |
|
24 | + * @param string $table_column name of column for field |
|
25 | + * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
26 | + * @param boolean $nullable |
|
27 | + * @param int|string $default_value data type should match field type |
|
28 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
29 | + * Basically it's the model class's name without the "EEM_" |
|
30 | + */ |
|
31 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
32 | + { |
|
33 | + $this->_model_name_pointed_to = (array) $model_name; |
|
34 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
35 | + $this->setSchemaType(SchemaType::STRING); |
|
36 | + $this->setDataType(DataType::STRING); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Returns the name of the model(s) pointed to |
|
42 | - * |
|
43 | - * @return string[] string or array of strings |
|
44 | - * @deprecated since version 4.6.7 |
|
45 | - */ |
|
46 | - public function get_model_name_pointed_to(): array |
|
47 | - { |
|
48 | - EE_Error::doing_it_wrong( |
|
49 | - 'get_model_name_pointed_to', |
|
50 | - esc_html__( |
|
51 | - 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - '4.6.7' |
|
55 | - ); |
|
56 | - return $this->_model_name_pointed_to; |
|
57 | - } |
|
40 | + /** |
|
41 | + * Returns the name of the model(s) pointed to |
|
42 | + * |
|
43 | + * @return string[] string or array of strings |
|
44 | + * @deprecated since version 4.6.7 |
|
45 | + */ |
|
46 | + public function get_model_name_pointed_to(): array |
|
47 | + { |
|
48 | + EE_Error::doing_it_wrong( |
|
49 | + 'get_model_name_pointed_to', |
|
50 | + esc_html__( |
|
51 | + 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + '4.6.7' |
|
55 | + ); |
|
56 | + return $this->_model_name_pointed_to; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Gets the model names pointed to by this field, always as an array |
|
62 | - * (even if there's only one) |
|
63 | - * |
|
64 | - * @return string[] of model names pointed to by this field |
|
65 | - */ |
|
66 | - public function get_model_names_pointed_to(): array |
|
67 | - { |
|
68 | - return is_array($this->_model_name_pointed_to) |
|
69 | - ? $this->_model_name_pointed_to |
|
70 | - : [$this->_model_name_pointed_to]; |
|
71 | - } |
|
60 | + /** |
|
61 | + * Gets the model names pointed to by this field, always as an array |
|
62 | + * (even if there's only one) |
|
63 | + * |
|
64 | + * @return string[] of model names pointed to by this field |
|
65 | + */ |
|
66 | + public function get_model_names_pointed_to(): array |
|
67 | + { |
|
68 | + return is_array($this->_model_name_pointed_to) |
|
69 | + ? $this->_model_name_pointed_to |
|
70 | + : [$this->_model_name_pointed_to]; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Returns the model's classname (eg EE_Event instead of just Event) |
|
76 | - * |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function get_model_class_names_pointed_to(): array |
|
80 | - { |
|
81 | - $model_names = []; |
|
82 | - if (is_array($this->_model_name_pointed_to)) { |
|
83 | - foreach ($this->_model_name_pointed_to as $model_name) { |
|
84 | - $model_names[] = "EE_" . $model_name; |
|
85 | - } |
|
86 | - } else { |
|
87 | - $model_names = ["EE_" . $this->_model_name_pointed_to]; |
|
88 | - } |
|
89 | - return $model_names; |
|
90 | - } |
|
74 | + /** |
|
75 | + * Returns the model's classname (eg EE_Event instead of just Event) |
|
76 | + * |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function get_model_class_names_pointed_to(): array |
|
80 | + { |
|
81 | + $model_names = []; |
|
82 | + if (is_array($this->_model_name_pointed_to)) { |
|
83 | + foreach ($this->_model_name_pointed_to as $model_name) { |
|
84 | + $model_names[] = "EE_" . $model_name; |
|
85 | + } |
|
86 | + } else { |
|
87 | + $model_names = ["EE_" . $this->_model_name_pointed_to]; |
|
88 | + } |
|
89 | + return $model_names; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @param int|EE_Base_Class $model_obj |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function is_model_obj_of_type_pointed_to($model_obj): bool |
|
98 | - { |
|
99 | - foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
100 | - if ($model_obj instanceof $model_obj_classname) { |
|
101 | - return true; |
|
102 | - } |
|
103 | - } |
|
104 | - return false; |
|
105 | - } |
|
93 | + /** |
|
94 | + * @param int|EE_Base_Class $model_obj |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function is_model_obj_of_type_pointed_to($model_obj): bool |
|
98 | + { |
|
99 | + foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
100 | + if ($model_obj instanceof $model_obj_classname) { |
|
101 | + return true; |
|
102 | + } |
|
103 | + } |
|
104 | + return false; |
|
105 | + } |
|
106 | 106 | } |
@@ -9,85 +9,85 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Float_Field extends EE_Model_Field_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var EE_Currency_Config |
|
14 | - */ |
|
15 | - protected $currency; |
|
12 | + /** |
|
13 | + * @var EE_Currency_Config |
|
14 | + */ |
|
15 | + protected $currency; |
|
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $table_column |
|
20 | - * @param string $nicename |
|
21 | - * @param bool $nullable |
|
22 | - * @param null $default_value |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
25 | - { |
|
26 | - $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
27 | - ? EE_Config::instance()->currency |
|
28 | - : new EE_Currency_Config(); |
|
29 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
30 | - $this->setSchemaType(SchemaType::NUMBER); |
|
31 | - $this->setDataType(DataType::FLOAT); |
|
32 | - } |
|
18 | + /** |
|
19 | + * @param string $table_column |
|
20 | + * @param string $nicename |
|
21 | + * @param bool $nullable |
|
22 | + * @param null $default_value |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
25 | + { |
|
26 | + $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
27 | + ? EE_Config::instance()->currency |
|
28 | + : new EE_Currency_Config(); |
|
29 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
30 | + $this->setSchemaType(SchemaType::NUMBER); |
|
31 | + $this->setDataType(DataType::FLOAT); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
37 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
38 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, typecast as float first. |
|
39 | - * Returns a float |
|
40 | - * |
|
41 | - * @param float|string $number |
|
42 | - * @return float |
|
43 | - */ |
|
44 | - public function prepare_for_set($number) |
|
45 | - { |
|
46 | - // remove whitespaces and thousands separators |
|
47 | - if (is_string($number)) { |
|
48 | - // scientific notation can just be cast as a float |
|
49 | - if (strpos($number, 'e') || strpos($number, 'E')) { |
|
50 | - return (float) $number; |
|
51 | - } |
|
52 | - $number = str_replace( |
|
53 | - array(" ", $this->currency->thsnds), |
|
54 | - "", |
|
55 | - $number |
|
56 | - ); |
|
57 | - // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
58 | - $number = str_replace( |
|
59 | - $this->currency->dec_mrk, |
|
60 | - ".", |
|
61 | - $number |
|
62 | - ); |
|
63 | - // double-check there's absolutely nothing left on this string besides numbers |
|
64 | - $number = preg_replace( |
|
65 | - "/[^0-9,.]/", |
|
66 | - "", |
|
67 | - $number |
|
68 | - ); |
|
69 | - } |
|
70 | - return (float) $number; |
|
71 | - } |
|
35 | + /** |
|
36 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
37 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
38 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, typecast as float first. |
|
39 | + * Returns a float |
|
40 | + * |
|
41 | + * @param float|string $number |
|
42 | + * @return float |
|
43 | + */ |
|
44 | + public function prepare_for_set($number) |
|
45 | + { |
|
46 | + // remove whitespaces and thousands separators |
|
47 | + if (is_string($number)) { |
|
48 | + // scientific notation can just be cast as a float |
|
49 | + if (strpos($number, 'e') || strpos($number, 'E')) { |
|
50 | + return (float) $number; |
|
51 | + } |
|
52 | + $number = str_replace( |
|
53 | + array(" ", $this->currency->thsnds), |
|
54 | + "", |
|
55 | + $number |
|
56 | + ); |
|
57 | + // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
58 | + $number = str_replace( |
|
59 | + $this->currency->dec_mrk, |
|
60 | + ".", |
|
61 | + $number |
|
62 | + ); |
|
63 | + // double-check there's absolutely nothing left on this string besides numbers |
|
64 | + $number = preg_replace( |
|
65 | + "/[^0-9,.]/", |
|
66 | + "", |
|
67 | + $number |
|
68 | + ); |
|
69 | + } |
|
70 | + return (float) $number; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
75 | - * |
|
76 | - * @param float $number |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function prepare_for_pretty_echoing($number, ?string $schema = null) |
|
80 | - { |
|
81 | - return number_format( |
|
82 | - $number, |
|
83 | - $this->currency->dec_plc, |
|
84 | - $this->currency->dec_mrk, |
|
85 | - $this->currency->thsnds |
|
86 | - ); |
|
87 | - } |
|
73 | + /** |
|
74 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
75 | + * |
|
76 | + * @param float $number |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function prepare_for_pretty_echoing($number, ?string $schema = null) |
|
80 | + { |
|
81 | + return number_format( |
|
82 | + $number, |
|
83 | + $this->currency->dec_plc, |
|
84 | + $this->currency->dec_mrk, |
|
85 | + $this->currency->thsnds |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | - public function prepare_for_set_from_db($number) |
|
90 | - { |
|
91 | - return (float) $number; |
|
92 | - } |
|
89 | + public function prepare_for_set_from_db($number) |
|
90 | + { |
|
91 | + return (float) $number; |
|
92 | + } |
|
93 | 93 | } |
@@ -4,42 +4,42 @@ |
||
4 | 4 | |
5 | 5 | class EE_Foreign_Key_String_Field extends EE_Foreign_Key_Field_Base |
6 | 6 | { |
7 | - /** |
|
8 | - * Whether the value should be converted to uppercase on insertion. |
|
9 | - * |
|
10 | - * @var bool |
|
11 | - */ |
|
12 | - protected bool $is_uppercase; |
|
7 | + /** |
|
8 | + * Whether the value should be converted to uppercase on insertion. |
|
9 | + * |
|
10 | + * @var bool |
|
11 | + */ |
|
12 | + protected bool $is_uppercase; |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @param string $table_column name of column for field |
|
17 | - * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
18 | - * @param boolean $nullable |
|
19 | - * @param int|string $default_value data type should match field type |
|
20 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
21 | - * Basically its the model class's name without the "EEM_" |
|
22 | - * @param boolean $is_uppercase Whether the value should be converted to uppercase on insertion. |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name, bool $is_uppercase = true) |
|
25 | - { |
|
26 | - $this->is_uppercase = $is_uppercase; |
|
27 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
28 | - $this->setDataType(DataType::STRING); |
|
29 | - } |
|
15 | + /** |
|
16 | + * @param string $table_column name of column for field |
|
17 | + * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
18 | + * @param boolean $nullable |
|
19 | + * @param int|string $default_value data type should match field type |
|
20 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
21 | + * Basically its the model class's name without the "EEM_" |
|
22 | + * @param boolean $is_uppercase Whether the value should be converted to uppercase on insertion. |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name, bool $is_uppercase = true) |
|
25 | + { |
|
26 | + $this->is_uppercase = $is_uppercase; |
|
27 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
28 | + $this->setDataType(DataType::STRING); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * removes all tags when setting |
|
33 | - * |
|
34 | - * @param string|null $value_inputted_for_field_on_model_object |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
38 | - { |
|
39 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
40 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
41 | - } |
|
42 | - $clean_value = wp_strip_all_tags((string) $value_inputted_for_field_on_model_object); |
|
43 | - return $this->is_uppercase ? strtoupper($clean_value) : $clean_value; |
|
44 | - } |
|
31 | + /** |
|
32 | + * removes all tags when setting |
|
33 | + * |
|
34 | + * @param string|null $value_inputted_for_field_on_model_object |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
38 | + { |
|
39 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
40 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
41 | + } |
|
42 | + $clean_value = wp_strip_all_tags((string) $value_inputted_for_field_on_model_object); |
|
43 | + return $this->is_uppercase ? strtoupper($clean_value) : $clean_value; |
|
44 | + } |
|
45 | 45 | } |
@@ -5,16 +5,16 @@ |
||
5 | 5 | |
6 | 6 | class EE_DB_Only_Float_Field extends EE_DB_Only_Field_Base |
7 | 7 | { |
8 | - /** |
|
9 | - * @param string $table_column |
|
10 | - * @param string $nicename |
|
11 | - * @param bool $nullable |
|
12 | - * @param null $default_value |
|
13 | - */ |
|
14 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
15 | - { |
|
16 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
17 | - $this->setSchemaType(SchemaType::FLOAT); |
|
18 | - $this->setDataType(DataType::FLOAT); |
|
19 | - } |
|
8 | + /** |
|
9 | + * @param string $table_column |
|
10 | + * @param string $nicename |
|
11 | + * @param bool $nullable |
|
12 | + * @param null $default_value |
|
13 | + */ |
|
14 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
15 | + { |
|
16 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
17 | + $this->setSchemaType(SchemaType::FLOAT); |
|
18 | + $this->setDataType(DataType::FLOAT); |
|
19 | + } |
|
20 | 20 | } |