mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11201] Change type from integer to service name
PHPBB3-11201
This commit is contained in:
parent
0ec6af38a9
commit
aa2f0a652f
12 changed files with 210 additions and 34 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
106
phpBB/phpbb/db/migration/data/v310/profilefield_types.php
Normal file
106
phpBB/phpbb/db/migration/data/v310/profilefield_types.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -21,6 +21,14 @@ abstract class type_base implements type_interface
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_service_name()
|
||||
{
|
||||
return 'profilefields.type.' . $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,14 @@ class type_bool extends type_base
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'bool';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -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']);
|
||||
|
|
|
@ -22,6 +22,14 @@ class type_date extends type_base
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -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'],
|
||||
);
|
||||
|
||||
|
|
|
@ -23,6 +23,14 @@ class type_dropdown extends type_base
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'dropdown';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -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;
|
||||
|
|
|
@ -21,6 +21,14 @@ class type_int extends type_base
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,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
|
||||
*
|
||||
|
|
|
@ -21,6 +21,14 @@ class type_string extends type_string_common
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,14 @@ class type_text extends type_string_common
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue