[ticket/11201] Remove type related code from build_insert_sql_array()

PHPBB3-11201
This commit is contained in:
Joas Schilling 2014-01-14 13:38:24 +01:00
parent daf21fcb30
commit d601aaad26
10 changed files with 71 additions and 21 deletions

View file

@ -372,7 +372,7 @@ class acp_profile
}
$profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]);
$field_row = array_merge($profile_field->get_default_values(), array(
$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,
'field_show_novalue'=> 0,

View file

@ -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);

View file

@ -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,
@ -63,6 +63,14 @@ class type_bool implements type_interface
);
}
/**
* {@inheritDoc}
*/
public function get_default_field_value($field_data)
{
return $field_data['field_default_value'];
}
/**
* {@inheritDoc}
*/

View file

@ -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,
@ -71,6 +71,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}
*/

View file

@ -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,
@ -67,6 +67,14 @@ class type_dropdown implements type_interface
);
}
/**
* {@inheritDoc}
*/
public function get_default_field_value($field_data)
{
return $field_data['field_default_value'];
}
/**
* {@inheritDoc}
*/

View file

@ -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,
@ -51,6 +51,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}
*/

View file

@ -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

View file

@ -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,

View file

@ -28,6 +28,14 @@ abstract class type_string_common
return $validate_options;
}
/**
* {@inheritDoc}
*/
public function get_default_field_value($field_data)
{
return $field_data['lang_default_value'];
}
/**
* Validate entered profile field data
*

View file

@ -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',