diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..26c11d9e22 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,6 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); + $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']); if ($value === null) { @@ -412,26 +413,28 @@ class manager } $tpl_fields['row'] += array( - 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, - 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, - 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, - 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_VALUE_RAW' => $value_raw, + 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, + 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, ); $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_IDENT' => $ident, - 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_CONTACT' => $contact_url, - 'PROFILE_FIELD_DESC' => $field_desc, - 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_FIELD_IDENT' => $ident, + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_VALUE_RAW' => $value_raw, + 'PROFILE_FIELD_CONTACT' => $contact_url, + 'PROFILE_FIELD_DESC' => $field_desc, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f67e58ee3a..0582722833 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -177,6 +177,24 @@ class type_bool extends type_base } } + /** + * {@inheritDoc} + */ + public function get_profile_value_raw($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 158eec6a0c..90ac9a6703 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -205,6 +205,19 @@ class type_date extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_value_raw($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 118ddf1f37..17ae89e1b2 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -186,6 +186,24 @@ class type_dropdown extends type_base return $this->lang_helper->get($field_id, $lang_id, $field_value); } + /** + * {@inheritDoc} + */ + public function get_profile_value_raw($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 78f1c7d2c9..dd08df94c1 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -151,6 +151,18 @@ class type_int extends type_base return (int) $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_value_raw($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + return (int) $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 489e916fd5..2dd13fa480 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -93,6 +93,15 @@ interface type_interface */ public function get_profile_value($field_value, $field_data); + /** + * Get Profile Value ID for display (the raw, unprocessed user data) + * + * @param mixed $field_value Field value as stored in the database + * @param array $field_data Array with requirements of the field + * @return mixed Field value ID to display + */ + public function get_profile_value_raw($field_value, $field_data); + /** * Get Profile Value for display * diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index b48e3c5add..c2b951b6c9 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -109,6 +109,19 @@ abstract class type_string_common extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_value_raw($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index 29c118d57d..bdab179c8c 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -74,10 +74,10 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case { return array( array( - false, - array('field_required' => true), - 'FIELD_REQUIRED-field', - 'Field should not accept empty values for required fields', + false, + array('field_required' => true), + 'FIELD_REQUIRED-field', + 'Field should not accept empty values for required fields', ), ); } @@ -130,6 +130,54 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + '4', + array('field_show_novalue' => true), + '4', + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => true), + null, + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function is_set_callback($field_id, $lang_id, $field_value) { return isset($this->options[$field_value]); diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 39fe95b97f..0ad2cde9fe 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -179,6 +179,42 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + '', + 'Field should return correct raw value', + ), + array( + '12/06/2014', + array('field_show_novalue' => true), + '12/06/2014', + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index 0e92afd504..ebecbf97f0 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -170,6 +170,54 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + '4', + array('field_show_novalue' => true), + '4', + 'Field should return the correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should null for empty value without show_novalue', + ), + array( + '', + array('field_show_novalue' => true), + 0, + 'Field should return 0 for empty value with show_novalue', + ), + array( + null, + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + null, + array('field_show_novalue' => true), + 0, + 'Field should return 0 for empty value with show_novalue', + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function is_set_callback($field_id, $lang_id, $field_value) { return isset($this->dropdown_options[$field_value]); diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index 611edd32b9..ac48c10a84 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -169,6 +169,66 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + '10', + array('field_show_novalue' => true), + 10, + 'Field should return the correct raw value', + ), + array( + '0', + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => true), + 0, + 'Field should return correct raw value', + ), + array( + '10', + array('field_show_novalue' => false), + 10, + 'Field should return the correct raw value', + ), + array( + '0', + array('field_show_novalue' => false), + 0, + 'Field should return correct raw value', + ), + array( + '', + array('field_show_novalue' => false), + null, + 'Field should return correct raw value', + ), + array( + 'string', + array('field_show_novalue' => false), + 0, + 'Field should return int cast of passed string' + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index cee8a1d863..f6c14ee38b 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -225,6 +225,60 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + '[b]bbcode test[/b]', + array('field_show_novalue' => true), + '[b]bbcode test[/b]', + 'Field should return the correct raw value', + ), + array( + '[b]bbcode test[/b]', + array('field_show_novalue' => false), + '[b]bbcode test[/b]', + 'Field should return correct raw value', + ), + array( + 125, + array('field_show_novalue' => false), + 125, + 'Field should return value of integer as is', + ), + array( + 0, + array('field_show_novalue' => false), + null, + 'Field should return null for empty integer without show_novalue', + ), + array( + 0, + array('field_show_novalue' => true), + 0, + 'Field should return 0 for empty integer with show_novalue', + ), + array( + null, + array('field_show_novalue' => true), + null, + 'field should return null value as is', + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args()); diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index 9957510d90..a45a28e7c7 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -104,6 +104,36 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case $this->assertSame($expected, $result, $description); } + public function profile_value_raw_data() + { + return array( + array( + 'http://example.com', + array('field_show_novalue' => true), + 'http://example.com', + 'Field should return the correct raw value', + ), + array( + 'http://example.com', + array('field_show_novalue' => false), + 'http://example.com', + 'Field should return correct raw value', + ), + ); + } + + /** + * @dataProvider profile_value_raw_data + */ + public function test_get_profile_value_raw($value, $field_options, $expected, $description) + { + $field_options = array_merge($this->field_options, $field_options); + + $result = $this->cp->get_profile_value_raw($value, $field_options); + + $this->assertSame($expected, $result, $description); + } + public function return_callback_implode() { return implode('-', func_get_args());