mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 16:35:35 +02:00
[ticket/11201] Move get_profile_value() to type class
PHPBB3-11201
This commit is contained in:
phpBB/phpbb/profilefields
@ -365,7 +365,8 @@ class profilefields
|
||||
|
||||
foreach ($profile_row as $ident => $ident_ary)
|
||||
{
|
||||
$value = $this->get_profile_value($ident_ary);
|
||||
$profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]);
|
||||
$value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
|
||||
|
||||
if ($value === NULL)
|
||||
{
|
||||
@ -399,124 +400,6 @@ class profilefields
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Profile Value for display
|
||||
*/
|
||||
function get_profile_value($ident_ary)
|
||||
{
|
||||
$value = $ident_ary['value'];
|
||||
$field_type = $ident_ary['data']['field_type'];
|
||||
|
||||
switch ($this->profile_types[$field_type])
|
||||
{
|
||||
case 'int':
|
||||
if ($value === '' && !$ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return (int) $value;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
case 'text':
|
||||
if (!$value && !$ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$value = make_clickable($value);
|
||||
$value = censor_text($value);
|
||||
$value = bbcode_nl2br($value);
|
||||
return $value;
|
||||
break;
|
||||
|
||||
// case 'datetime':
|
||||
case 'date':
|
||||
$date = explode('-', $value);
|
||||
$day = (isset($date[0])) ? (int) $date[0] : 0;
|
||||
$month = (isset($date[1])) ? (int) $date[1] : 0;
|
||||
$year = (isset($date[2])) ? (int) $date[2] : 0;
|
||||
|
||||
if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else if ($day && $month && $year)
|
||||
{
|
||||
// Date should display as the same date for every user regardless of timezone
|
||||
return $this->user->create_datetime()
|
||||
->setDate($year, $month, $day)
|
||||
->setTime(0, 0, 0)
|
||||
->format($user->lang['DATE_FORMAT'], true);
|
||||
}
|
||||
|
||||
return $value;
|
||||
break;
|
||||
|
||||
case 'dropdown':
|
||||
$field_id = $ident_ary['data']['field_id'];
|
||||
$lang_id = $ident_ary['data']['lang_id'];
|
||||
if (!isset($this->options_lang[$field_id][$lang_id]))
|
||||
{
|
||||
$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
|
||||
}
|
||||
|
||||
if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$value = (int) $value;
|
||||
|
||||
// User not having a value assigned
|
||||
if (!isset($this->options_lang[$field_id][$lang_id][$value]))
|
||||
{
|
||||
if ($ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
$value = $ident_ary['data']['field_novalue'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->options_lang[$field_id][$lang_id][$value];
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
$field_id = $ident_ary['data']['field_id'];
|
||||
$lang_id = $ident_ary['data']['lang_id'];
|
||||
if (!isset($this->options_lang[$field_id][$lang_id]))
|
||||
{
|
||||
$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
|
||||
}
|
||||
|
||||
if (!$value && $ident_ary['data']['field_show_novalue'])
|
||||
{
|
||||
$value = $ident_ary['data']['field_default_value'];
|
||||
}
|
||||
|
||||
if ($ident_ary['data']['field_length'] == 1)
|
||||
{
|
||||
return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
|
||||
}
|
||||
else if (!$value)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('Unknown profile type', E_USER_ERROR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get field value for registration/profile
|
||||
* @access private
|
||||
|
@ -94,4 +94,36 @@ class type_bool implements type_interface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$field_id = $field_data['field_id'];
|
||||
$lang_id = $field_data['lang_id'];
|
||||
|
||||
if (!isset($this->profilefields->options_lang[$field_id][$lang_id]))
|
||||
{
|
||||
$this->profilefields->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
|
||||
}
|
||||
|
||||
if (!$field_value && $field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_default_value'];
|
||||
}
|
||||
|
||||
if ($field_data['field_length'] == 1)
|
||||
{
|
||||
return (isset($this->profilefields->options_lang[$field_id][$lang_id][(int) $field_value])) ? $this->options_lang[$field_id][$lang_id][(int) $field_value] : null;
|
||||
}
|
||||
else if (!$field_value)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,4 +129,30 @@ class type_date implements type_interface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$date = explode('-', $field_value);
|
||||
$day = (isset($date[0])) ? (int) $date[0] : 0;
|
||||
$month = (isset($date[1])) ? (int) $date[1] : 0;
|
||||
$year = (isset($date[2])) ? (int) $date[2] : 0;
|
||||
|
||||
if (!$day && !$month && !$year && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ($day && $month && $year)
|
||||
{
|
||||
// Date should display as the same date for every user regardless of timezone
|
||||
return $this->user->create_datetime()
|
||||
->setDate($year, $month, $day)
|
||||
->setTime(0, 0, 0)
|
||||
->format($user->lang['DATE_FORMAT'], true);
|
||||
}
|
||||
|
||||
return $field_value;
|
||||
}
|
||||
}
|
||||
|
@ -100,4 +100,39 @@ class type_dropdown implements type_interface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
$field_id = $field_data['field_id'];
|
||||
$lang_id = $field_data['lang_id'];
|
||||
if (!isset($this->profilefields->options_lang[$field_id][$lang_id]))
|
||||
{
|
||||
$this->profilefields->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
|
||||
}
|
||||
|
||||
if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$field_value = (int) $field_value;
|
||||
|
||||
// User not having a value assigned
|
||||
if (!isset($this->profilefields->options_lang[$field_id][$lang_id][$field_value]))
|
||||
{
|
||||
if ($field_data['field_show_novalue'])
|
||||
{
|
||||
$field_value = $field_data['field_novalue'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->profilefields->options_lang[$field_id][$lang_id][$field_value];
|
||||
}
|
||||
}
|
||||
|
@ -89,4 +89,16 @@ class type_int implements type_interface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
if ($field_value === '' && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (int) $field_value;
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,13 @@ interface type_interface
|
||||
* @return mixed String with key of the error language string, false otherwise
|
||||
*/
|
||||
public function validate_profile_field(&$field_value, $field_data);
|
||||
|
||||
/**
|
||||
* Get Profile Value for display
|
||||
*
|
||||
* @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 to display
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data);
|
||||
}
|
||||
|
@ -67,4 +67,20 @@ abstract class type_string_common
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_profile_value($field_value, $field_data)
|
||||
{
|
||||
if (!$field_value && !$field_data['field_show_novalue'])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$field_value = make_clickable($field_value);
|
||||
$field_value = censor_text($field_value);
|
||||
$field_value = bbcode_nl2br($field_value);
|
||||
return $field_value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user