diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-14 13:38:24 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-14 13:38:24 +0100 |
commit | d601aaad263e19b47865bca56da527f4fdf504e1 (patch) | |
tree | 6c942af03a1536ebd99a942c7f04f72b36cd28e3 /phpBB/phpbb | |
parent | daf21fcb30c5c76c1d3f0b2a2bce8d8c1d8aed14 (diff) | |
download | forums-d601aaad263e19b47865bca56da527f4fdf504e1.tar forums-d601aaad263e19b47865bca56da527f4fdf504e1.tar.gz forums-d601aaad263e19b47865bca56da527f4fdf504e1.tar.bz2 forums-d601aaad263e19b47865bca56da527f4fdf504e1.tar.xz forums-d601aaad263e19b47865bca56da527f4fdf504e1.zip |
[ticket/11201] Remove type related code from build_insert_sql_array()
PHPBB3-11201
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/profilefields/profilefields.php | 14 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_dropdown.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_int.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 12 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_string.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_string_common.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 2 |
9 files changed, 70 insertions, 20 deletions
diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index ba0baa53f0..e3201712df 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -408,18 +408,8 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE) - { - $now = getdate(); - $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); - } - else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT) - { - // We cannot insert an empty string into an integer column. - $row['field_default_value'] = NULL; - } - - $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value']; + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index ee75578a16..e60806becd 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -51,7 +51,7 @@ class type_bool implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 1, @@ -66,6 +66,14 @@ class type_bool implements type_interface /** * {@inheritDoc} */ + public function get_default_field_value($field_data) + { + return $field_data['field_default_value']; + } + + /** + * {@inheritDoc} + */ public function get_profile_field($profile_row) { $var_name = 'pf_' . $profile_row['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 36e82dabce..7aabafcb14 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -59,7 +59,7 @@ class type_date implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 10, @@ -74,6 +74,20 @@ class type_date implements type_interface /** * {@inheritDoc} */ + public function get_default_field_value($field_data) + { + if ($field_data['field_default_value'] == 'now') + { + $now = getdate(); + $field_data['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); + } + + return $field_data['field_default_value']; + } + + /** + * {@inheritDoc} + */ public function get_profile_field($profile_row) { $var_name = 'pf_' . $profile_row['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 61fa8d7585..c461815426 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -55,7 +55,7 @@ class type_dropdown implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 0, @@ -70,6 +70,14 @@ class type_dropdown implements type_interface /** * {@inheritDoc} */ + public function get_default_field_value($field_data) + { + return $field_data['field_default_value']; + } + + /** + * {@inheritDoc} + */ public function get_profile_field($profile_row) { $var_name = 'pf_' . $profile_row['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 7285b0f4ba..f650436d21 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -39,7 +39,7 @@ class type_int implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 5, @@ -54,6 +54,20 @@ class type_int implements type_interface /** * {@inheritDoc} */ + public function get_default_field_value($field_data) + { + if ($field_data['field_default_value'] === '') + { + // We cannot insert an empty string into an integer column. + return null; + } + + return $field_data['field_default_value']; + } + + /** + * {@inheritDoc} + */ public function get_profile_field($profile_row) { $var_name = 'pf_' . $profile_row['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 92925c3023..d53c038d2d 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -31,11 +31,19 @@ interface type_interface public function get_options($default_lang_id, $field_data); /** - * Get default values for this type + * Get default values for the options of this type * * @return array with values like default field size and more */ - public function get_default_values(); + public function get_default_option_values(); + + /** + * Get default value for this type + * + * @param array $field_data Array with data for this field + * @return mixed default value for new users when no value is given + */ + public function get_default_field_value($field_data); /** * Get profile field value on submit diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index c9929b1110..090b5a2a54 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -39,7 +39,7 @@ class type_string extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 10, diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 46e44fa85a..02b640bb44 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -29,6 +29,14 @@ abstract class type_string_common } /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + return $field_data['lang_default_value']; + } + + /** * Validate entered profile field data * * @param string $field_type Field type (string or text) diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 476e1d204f..e73ffc5375 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -39,7 +39,7 @@ class type_text extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => '5|80', |