diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 19:33:29 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 21:13:59 +0100 |
commit | aa2f0a652ff19490def8137bc73255dff282f305 (patch) | |
tree | 7045a9f873073076d1a9d419a0a6823838f376d5 | |
parent | 0ec6af38a97239003be76a85eb86e2f0aef5e99c (diff) | |
download | forums-aa2f0a652ff19490def8137bc73255dff282f305.tar forums-aa2f0a652ff19490def8137bc73255dff282f305.tar.gz forums-aa2f0a652ff19490def8137bc73255dff282f305.tar.bz2 forums-aa2f0a652ff19490def8137bc73255dff282f305.tar.xz forums-aa2f0a652ff19490def8137bc73255dff282f305.zip |
[ticket/11201] Change type from integer to service name
PHPBB3-11201
-rw-r--r-- | phpBB/includes/acp/acp_profile.php | 37 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/profilefield_types.php | 106 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/lang_helper.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/profilefields.php | 15 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_base.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 12 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_dropdown.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_int.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 14 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_string.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 8 |
12 files changed, 210 insertions, 34 deletions
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 5387f23049..feb8265cf5 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -24,6 +24,7 @@ class acp_profile var $edit_lang_id; var $lang_defs; + protected $type_collection; function main($id, $mode) { @@ -50,6 +51,7 @@ class acp_profile } $cp = $phpbb_container->get('profilefields'); + $this->type_collection = $phpbb_container->get('profilefields.type_collection'); // Build Language array // Based on this, we decide which elements need to be edited later and which language items are missing @@ -341,7 +343,7 @@ class acp_profile $this->edit_lang_id = $field_row['lang_id']; } $field_type = $field_row['field_type']; - $profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]); + $profile_field = $this->type_collection[$field_type]; // Get language entries $sql = 'SELECT * @@ -365,14 +367,14 @@ class acp_profile // We are adding a new field, define basic params $lang_options = $field_row = array(); - $field_type = request_var('field_type', 0); + $field_type = request_var('field_type', ''); - if (!$field_type) + if (!isset($this->type_collection[$field_type])) { trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } - $profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]); + $profile_field = $this->type_collection[$field_type]; $field_row = array_merge($profile_field->get_default_option_values(), array( 'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))), 'field_required' => 0, @@ -623,7 +625,7 @@ class acp_profile 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false, 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']), - 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])], + 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($profile_field->get_name())], 'FIELD_IDENT' => $cp->vars['field_ident'], 'LANG_NAME' => $cp->vars['lang_name'], 'LANG_EXPLAIN' => $cp->vars['lang_explain'], @@ -707,9 +709,10 @@ class acp_profile $s_one_need_edit = true; } + $profile_field = $this->type_collection[$row['field_type']]; $template->assign_block_vars('fields', array( 'FIELD_IDENT' => $row['field_ident'], - 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])], + 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($profile_field->get_name())], 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang], 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id", @@ -731,15 +734,15 @@ class acp_profile } $s_select_type = ''; - foreach ($cp->profile_types as $key => $value) + foreach ($this->type_collection as $key => $profile_field) { - $s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($value)] . '</option>'; + $s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($profile_field->get_name())] . '</option>'; } $template->assign_vars(array( 'U_ACTION' => $this->u_action, - 'S_TYPE_OPTIONS' => $s_select_type) - ); + 'S_TYPE_OPTIONS' => $s_select_type, + )); } /** @@ -764,9 +767,8 @@ class acp_profile } $db->sql_freeresult($result); - $type_collection = $phpbb_container->get('profilefields.type_collection'); - $profile_type = $type_collection['profilefields.type.' . $cp->profile_types[$field_type]]; - $options = $profile_type->get_language_options($cp->vars); + $profile_field = $this->type_collection[$field_type]; + $options = $profile_field->get_language_options($cp->vars); $lang_options = array(); @@ -906,8 +908,7 @@ class acp_profile $db->sql_query($sql); } - $type_collection = $phpbb_container->get('profilefields.type_collection'); - $profile_type = $type_collection['profilefields.type.' . $cp->profile_types[$field_type]]; + $profile_field = $this->type_collection[$field_type]; if ($action == 'create') { @@ -915,7 +916,7 @@ class acp_profile $db_tools = $phpbb_container->get('dbal.tools'); - list($sql_type, $null) = $db_tools->get_column_type($profile_type->get_database_column_type()); + list($sql_type, $null) = $db_tools->get_column_type($profile_field->get_database_column_type()); $profile_sql[] = $this->add_field_ident($field_ident, $sql_type); } @@ -990,7 +991,7 @@ class acp_profile foreach ($cp->vars['lang_options'] as $option_id => $value) { $sql_ary = array( - 'field_type' => (int) $field_type, + 'field_type' => $field_type, 'lang_value' => $value ); @@ -1045,7 +1046,7 @@ class acp_profile 'field_id' => (int) $field_id, 'lang_id' => (int) $lang_id, 'option_id' => (int) $option_id, - 'field_type' => (int) $field_type, + 'field_type' => $field_type, 'lang_value' => $value ); } diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_types.php b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php new file mode 100644 index 0000000000..553ff592a4 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php @@ -0,0 +1,106 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class profilefield_types extends \phpbb\db\migration\migration +{ + + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v310\alpha2', + ); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_type' => array('VCHAR:100', ''), + ), + $this->table_prefix . 'profile_fields_lang' => array( + 'field_type' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_profile_fields_type'))), + array('custom', array(array($this, 'update_profile_fields_lang_type'))), + ); + } + + public function update_profile_fields_type() + { + // Update profile field types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_profile_fields_lang_type() + { + // Update profile field language types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields_lang + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields_lang + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + /** + * Determine the new field type for a given phpBB 3.0 field type + * + * @param $field_type int Field type in 3.0 + * @return string Field new type which is used since 3.1 + */ + public function convert_phpbb30_field_type($field_type) + { + switch ($field_type) + { + case FIELD_INT: + return 'profilefields.type.int'; + case FIELD_STRING: + return 'profilefields.type.string'; + case FIELD_TEXT: + return 'profilefields.type.text'; + case FIELD_BOOL: + return 'profilefields.type.bool'; + case FIELD_DROPDOWN: + return 'profilefields.type.dropdown'; + case FIELD_DATE: + return 'profilefields.type.date'; + default: + return $field_type; + } + } +} diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 569eaaca40..432c0aa40b 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -65,7 +65,7 @@ class lang_helper FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id AND lang_id = $lang_id - AND field_type = $field_type + AND field_type = '" . $this->db->sql_escape($field_type) . "' ORDER BY option_id"; $result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index a580ca2937..bd9765d04c 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -82,10 +82,9 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - // Return templated field $tpl_snippet = $this->process_field_row('change', $row); - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $row['lang_name'], @@ -160,7 +159,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; @@ -300,7 +299,7 @@ class profilefields foreach ($profile_row as $ident => $ident_ary) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); if ($value === NULL) @@ -349,13 +348,13 @@ class profilefields )); // empty previously filled blockvars - foreach ($this->profile_types as $field_case => $field_type) + foreach ($this->type_collection as $field_key => $field_type) { - $this->template->destroy_block_vars($field_type); + $this->template->destroy_block_vars($field_type->get_name()); } // Assign template variables - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$profile_row['field_type']]]; + $profile_field = $this->type_collection[$profile_row['field_type']]; $profile_field->generate_field($profile_row, $preview_options); // Return templated data @@ -382,7 +381,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$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_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 2fd4c50f6b..7aee74d9ff 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -24,6 +24,14 @@ abstract class type_base implements type_interface /** * {@inheritDoc} */ + public function get_service_name() + { + return 'profilefields.type.' . $this->get_name(); + } + + /** + * {@inheritDoc} + */ public function get_field_ident($field_data) { return 'pf_' . $field_data['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 016ceb6000..f466b60099 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -26,6 +26,14 @@ class type_bool extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'bool'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row = array( @@ -36,7 +44,7 @@ class type_bool extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_BOOL, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], 'lang_options' => $field_data['lang_options'] ); @@ -163,7 +171,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 301e05c9ae..e59c959f5d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -25,6 +25,14 @@ class type_date extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'date'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row = array( @@ -34,7 +42,7 @@ class type_date extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DATE, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], ); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 95f250f444..c9d0936816 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -26,6 +26,14 @@ class type_dropdown extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'dropdown'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row[0] = array( @@ -36,7 +44,7 @@ class type_dropdown extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DROPDOWN, + 'field_type' => $this->get_service_name(), 'lang_options' => $field_data['lang_options'], ); @@ -95,7 +103,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], $this->get_service_name(), false); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -120,7 +128,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, $this->get_service_name(), false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -159,7 +167,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $profile_row['field_value'] = (int) $value; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index e22b45e7a4..5b5f84d41b 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -24,6 +24,14 @@ class type_int extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'int'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index e0c2ba824d..5a88200bad 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -12,6 +12,20 @@ namespace phpbb\profilefields\type; interface type_interface { /** + * Get the name of the type, used for error messages and template loops + * + * @return string lowercase version of the fields type + */ + public function get_name(); + + /** + * Get the name of service representing the type + * + * @return string lowercase version of the fields type + */ + public function get_service_name(); + + /** * Get dropdown options for second step in ACP * * @param string $default_lang_id ID of the default language diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9542a6256a..73563bc579 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -24,6 +24,14 @@ class type_string extends type_string_common /** * {@inheritDoc} */ + public function get_name() + { + return 'string'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 0ead505262..1638bffcff 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -24,6 +24,14 @@ class type_text extends type_string_common /** * {@inheritDoc} */ + public function get_name() + { + return 'text'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( |