mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/11201] Move generate_field() method to type class
PHPBB3-11201
This commit is contained in:
parent
d57c43d397
commit
daf21fcb30
9 changed files with 218 additions and 211 deletions
|
@ -14,6 +14,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -23,6 +24,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -32,6 +34,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -40,6 +43,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_int
|
class: \phpbb\profilefields\type\type_int
|
||||||
arguments:
|
arguments:
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -48,6 +52,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_string
|
class: \phpbb\profilefields\type\type_string
|
||||||
arguments:
|
arguments:
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -56,6 +61,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_text
|
class: \phpbb\profilefields\type\type_text
|
||||||
arguments:
|
arguments:
|
||||||
- @request
|
- @request
|
||||||
|
- @template
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
|
|
@ -360,209 +360,6 @@ class profilefields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get field value for registration/profile
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function get_var($field_validation, &$profile_row, $default_value, $preview)
|
|
||||||
{
|
|
||||||
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
|
||||||
$user_ident = $profile_row['field_ident'];
|
|
||||||
// checkbox - set the value to "true" if it has been set to 1
|
|
||||||
if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
|
|
||||||
{
|
|
||||||
$value = (isset($_REQUEST[$profile_row['field_ident']]) && request_var($profile_row['field_ident'], $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]);
|
|
||||||
}
|
|
||||||
else if ($profile_row['field_type'] == FIELD_INT)
|
|
||||||
{
|
|
||||||
if (isset($_REQUEST[$profile_row['field_ident']]))
|
|
||||||
{
|
|
||||||
$value = ($this->request->variable($profile_row['field_ident'], '') === '') ? NULL : $this->request->variable($profile_row['field_ident'], $default_value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!$preview && array_key_exists($user_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$user_ident]))
|
|
||||||
{
|
|
||||||
$value = NULL;
|
|
||||||
}
|
|
||||||
else if (!isset($this->user->profile_fields[$user_ident]) || $preview)
|
|
||||||
{
|
|
||||||
$value = $default_value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$value = $this->user->profile_fields[$user_ident];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (is_null($value) || $value === '') ? '' : (int) $value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$value = (isset($_REQUEST[$profile_row['field_ident']])) ? request_var($profile_row['field_ident'], $default_value, true) : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]);
|
|
||||||
|
|
||||||
if (gettype($value) == 'string')
|
|
||||||
{
|
|
||||||
$value = utf8_normalize_nfc($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($field_validation)
|
|
||||||
{
|
|
||||||
case 'int':
|
|
||||||
return (int) $value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process int-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_int($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process date-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_date($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
|
||||||
$user_ident = $profile_row['field_ident'];
|
|
||||||
|
|
||||||
$now = getdate();
|
|
||||||
|
|
||||||
if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
|
|
||||||
{
|
|
||||||
if ($profile_row['field_default_value'] == 'now')
|
|
||||||
{
|
|
||||||
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
||||||
}
|
|
||||||
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($preview && $profile_row['field_default_value'] == 'now')
|
|
||||||
{
|
|
||||||
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
||||||
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$day = request_var($profile_row['field_ident'] . '_day', 0);
|
|
||||||
$month = request_var($profile_row['field_ident'] . '_month', 0);
|
|
||||||
$year = request_var($profile_row['field_ident'] . '_year', 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
|
|
||||||
for ($i = 1; $i < 32; $i++)
|
|
||||||
{
|
|
||||||
$profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
|
|
||||||
for ($i = 1; $i < 13; $i++)
|
|
||||||
{
|
|
||||||
$profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
|
|
||||||
for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++)
|
|
||||||
{
|
|
||||||
$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
|
|
||||||
}
|
|
||||||
unset($now);
|
|
||||||
|
|
||||||
$profile_row['field_value'] = 0;
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process bool-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_bool($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
||||||
|
|
||||||
$profile_row['field_value'] = $value;
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
|
|
||||||
if ($profile_row['field_length'] == 1)
|
|
||||||
{
|
|
||||||
if (!isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
|
|
||||||
{
|
|
||||||
$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
|
||||||
{
|
|
||||||
$this->template->assign_block_vars('bool.options', array(
|
|
||||||
'OPTION_ID' => $option_id,
|
|
||||||
'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
|
|
||||||
'VALUE' => $option_value)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process string-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_string($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process text-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_text($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$field_length = explode('|', $profile_row['field_length']);
|
|
||||||
$profile_row['field_rows'] = $field_length[0];
|
|
||||||
$profile_row['field_cols'] = $field_length[1];
|
|
||||||
|
|
||||||
$profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process dropdown-type
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function generate_dropdown($profile_row, $preview = false)
|
|
||||||
{
|
|
||||||
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
|
||||||
|
|
||||||
if (!isset($this->options_lang[$profile_row['field_id']]) || !isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
|
|
||||||
{
|
|
||||||
$this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_row['field_value'] = $value;
|
|
||||||
$this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
|
|
||||||
|
|
||||||
foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
|
||||||
{
|
|
||||||
$this->template->assign_block_vars('dropdown.options', array(
|
|
||||||
'OPTION_ID' => $option_id,
|
|
||||||
'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
|
|
||||||
'VALUE' => $option_value)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Templated value/field. Possible values for $mode are:
|
* Return Templated value/field. Possible values for $mode are:
|
||||||
* change == user is able to set/enter profile values; preview == just show the value
|
* change == user is able to set/enter profile values; preview == just show the value
|
||||||
|
@ -584,8 +381,8 @@ class profilefields
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign template variables
|
// Assign template variables
|
||||||
$type_func = 'generate_' . $this->profile_types[$profile_row['field_type']];
|
$profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]);
|
||||||
$this->$type_func($profile_row, $preview);
|
$profile_field->generate_field($profile_row, $preview);
|
||||||
|
|
||||||
// Return templated data
|
// Return templated data
|
||||||
return $this->template->assign_display('cp_body');
|
return $this->template->assign_display('cp_body');
|
||||||
|
|
|
@ -14,10 +14,11 @@ class type_bool implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,4 +127,45 @@ class type_bool implements type_interface
|
||||||
return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1];
|
return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
$field_ident = $profile_row['field_ident'];
|
||||||
|
$default_value = $profile_row['lang_default_value'];
|
||||||
|
|
||||||
|
$value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
|
||||||
|
// checkbox - set the value to "true" if it has been set to 1
|
||||||
|
if ($profile_row['field_length'] == 2)
|
||||||
|
{
|
||||||
|
$value = ($this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['field_value'] = (int) $value;
|
||||||
|
$this->template->assign_block_vars('bool', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
|
||||||
|
if ($profile_row['field_length'] == 1)
|
||||||
|
{
|
||||||
|
if (!isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
|
||||||
|
{
|
||||||
|
$this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
||||||
|
{
|
||||||
|
$this->template->assign_block_vars('bool.options', array(
|
||||||
|
'OPTION_ID' => $option_id,
|
||||||
|
'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
|
||||||
|
'VALUE' => $option_value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,11 @@ class type_date implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,4 +156,58 @@ class type_date implements type_interface
|
||||||
|
|
||||||
return $field_value;
|
return $field_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
|
||||||
|
$now = getdate();
|
||||||
|
|
||||||
|
if (!$this->request->is_set($profile_row['field_ident'] . '_day'))
|
||||||
|
{
|
||||||
|
if ($profile_row['field_default_value'] == 'now')
|
||||||
|
{
|
||||||
|
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
||||||
|
}
|
||||||
|
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($preview && $profile_row['field_default_value'] == 'now')
|
||||||
|
{
|
||||||
|
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
||||||
|
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$day = $this->request->variable($profile_row['field_ident'] . '_day', 0);
|
||||||
|
$month = $this->request->variable($profile_row['field_ident'] . '_month', 0);
|
||||||
|
$year = $this->request->variable($profile_row['field_ident'] . '_year', 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
|
||||||
|
for ($i = 1; $i < 32; $i++)
|
||||||
|
{
|
||||||
|
$profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
|
||||||
|
for ($i = 1; $i < 13; $i++)
|
||||||
|
{
|
||||||
|
$profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
|
||||||
|
for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++)
|
||||||
|
{
|
||||||
|
$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['field_value'] = 0;
|
||||||
|
$this->template->assign_block_vars('date', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,11 @@ class type_dropdown implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,4 +136,33 @@ class type_dropdown implements type_interface
|
||||||
|
|
||||||
return $this->profilefields->options_lang[$field_id][$lang_id][$field_value];
|
return $this->profilefields->options_lang[$field_id][$lang_id][$field_value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
$field_ident = $profile_row['field_ident'];
|
||||||
|
$default_value = $profile_row['lang_default_value'];
|
||||||
|
|
||||||
|
$value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||||
|
|
||||||
|
if (!isset($this->profilefields->options_lang[$profile_row['field_id']]) || !isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
|
||||||
|
{
|
||||||
|
$this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['field_value'] = (int) $value;
|
||||||
|
$this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
|
||||||
|
foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
|
||||||
|
{
|
||||||
|
$this->template->assign_block_vars('dropdown.options', array(
|
||||||
|
'OPTION_ID' => $option_id,
|
||||||
|
'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
|
||||||
|
'VALUE' => $option_value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_int implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,4 +102,38 @@ class type_int implements type_interface
|
||||||
}
|
}
|
||||||
return (int) $field_value;
|
return (int) $field_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
$field_ident = $profile_row['field_ident'];
|
||||||
|
$default_value = $profile_row['lang_default_value'];
|
||||||
|
|
||||||
|
if ($this->request->is_set($field_ident))
|
||||||
|
{
|
||||||
|
$value = ($this->request->variable($field_ident, '') === '') ? null : $this->request->variable($field_ident, $default_value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!$preview && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident]))
|
||||||
|
{
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
|
else if (!isset($this->user->profile_fields[$field_ident]) || $preview)
|
||||||
|
{
|
||||||
|
$value = $default_value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$value = $this->user->profile_fields[$field_ident];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile_row['field_value'] = (is_null($value) || $value === '') ? '' : (int) $value;
|
||||||
|
|
||||||
|
$this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,4 +62,13 @@ interface type_interface
|
||||||
* @return mixed Field value to display
|
* @return mixed Field value to display
|
||||||
*/
|
*/
|
||||||
public function get_profile_value($field_value, $field_data);
|
public function get_profile_value($field_value, $field_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the input field for display
|
||||||
|
*
|
||||||
|
* @param array $profile_row Array with data for this field
|
||||||
|
* @param bool $preview Do we preview the form
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_string extends type_string_common implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,4 +67,18 @@ class type_string extends type_string_common implements type_interface
|
||||||
{
|
{
|
||||||
return $this->validate_string_profile_field('string', $field_value, $field_data);
|
return $this->validate_string_profile_field('string', $field_value, $field_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
$field_ident = $profile_row['field_ident'];
|
||||||
|
$default_value = $profile_row['lang_default_value'];
|
||||||
|
$profile_row['field_value'] = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value, true) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||||
|
|
||||||
|
|
||||||
|
$this->template->assign_block_vars('string', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_text extends type_string_common implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,4 +67,21 @@ class type_text extends type_string_common implements type_interface
|
||||||
{
|
{
|
||||||
return $this->validate_string_profile_field('text', $field_value, $field_data);
|
return $this->validate_string_profile_field('text', $field_value, $field_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function generate_field($profile_row, $preview = false)
|
||||||
|
{
|
||||||
|
$field_length = explode('|', $profile_row['field_length']);
|
||||||
|
$profile_row['field_rows'] = $field_length[0];
|
||||||
|
$profile_row['field_cols'] = $field_length[1];
|
||||||
|
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
|
||||||
|
$field_ident = $profile_row['field_ident'];
|
||||||
|
$default_value = $profile_row['lang_default_value'];
|
||||||
|
|
||||||
|
$profile_row['field_value'] = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value, true) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]);
|
||||||
|
|
||||||
|
$this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue