mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/11201] Move get_profile_field() to type classes
PHPBB3-11201
This commit is contained in:
parent
a7e3538e5b
commit
b3803d563a
9 changed files with 119 additions and 80 deletions
|
@ -4,6 +4,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @auth
|
- @auth
|
||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
|
- @service_container
|
||||||
- @request
|
- @request
|
||||||
- @template
|
- @template
|
||||||
- @user
|
- @user
|
||||||
|
@ -12,6 +13,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_bool
|
class: \phpbb\profilefields\type\type_bool
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -20,6 +22,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_date
|
class: \phpbb\profilefields\type\type_date
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -28,6 +31,7 @@ services:
|
||||||
class: \phpbb\profilefields\type\type_dropdown
|
class: \phpbb\profilefields\type\type_dropdown
|
||||||
arguments:
|
arguments:
|
||||||
- @profilefields
|
- @profilefields
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -35,6 +39,7 @@ services:
|
||||||
profilefields.type.int:
|
profilefields.type.int:
|
||||||
class: \phpbb\profilefields\type\type_int
|
class: \phpbb\profilefields\type\type_int
|
||||||
arguments:
|
arguments:
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -42,6 +47,7 @@ services:
|
||||||
profilefields.type.string:
|
profilefields.type.string:
|
||||||
class: \phpbb\profilefields\type\type_string
|
class: \phpbb\profilefields\type\type_string
|
||||||
arguments:
|
arguments:
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
@ -49,6 +55,7 @@ services:
|
||||||
profilefields.type.text:
|
profilefields.type.text:
|
||||||
class: \phpbb\profilefields\type\type_text
|
class: \phpbb\profilefields\type\type_text
|
||||||
arguments:
|
arguments:
|
||||||
|
- @request
|
||||||
- @user
|
- @user
|
||||||
tags:
|
tags:
|
||||||
- { name: profilefield.type }
|
- { name: profilefield.type }
|
||||||
|
|
|
@ -22,10 +22,11 @@ class profilefields
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($auth, $db, $request, $template, $user)
|
public function __construct($auth, $db, /** @todo: */ $phpbb_container, $request, $template, $user)
|
||||||
{
|
{
|
||||||
$this->auth = $auth;
|
$this->auth = $auth;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
$this->container = $phpbb_container;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -300,7 +301,8 @@ class profilefields
|
||||||
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
|
$profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]);
|
||||||
|
$cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row);
|
||||||
$check_value = $cp_data['pf_' . $row['field_ident']];
|
$check_value = $cp_data['pf_' . $row['field_ident']];
|
||||||
|
|
||||||
if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
|
if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
|
||||||
|
@ -362,7 +364,7 @@ class profilefields
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($db->sql_layer)
|
switch ($this->db->sql_layer)
|
||||||
{
|
{
|
||||||
case 'oracle':
|
case 'oracle':
|
||||||
case 'firebird':
|
case 'firebird':
|
||||||
|
@ -900,75 +902,4 @@ class profilefields
|
||||||
|
|
||||||
return $cp_data;
|
return $cp_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get profile field value on submit
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function get_profile_field($profile_row)
|
|
||||||
{
|
|
||||||
$var_name = 'pf_' . $profile_row['field_ident'];
|
|
||||||
|
|
||||||
switch ($profile_row['field_type'])
|
|
||||||
{
|
|
||||||
case FIELD_DATE:
|
|
||||||
|
|
||||||
if (!isset($_REQUEST[$var_name . '_day']))
|
|
||||||
{
|
|
||||||
if ($profile_row['field_default_value'] == 'now')
|
|
||||||
{
|
|
||||||
$now = getdate();
|
|
||||||
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
|
||||||
}
|
|
||||||
list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$day = request_var($var_name . '_day', 0);
|
|
||||||
$month = request_var($var_name . '_month', 0);
|
|
||||||
$year = request_var($var_name . '_year', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$var = sprintf('%2d-%2d-%4d', $day, $month, $year);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_BOOL:
|
|
||||||
// Checkbox
|
|
||||||
if ($profile_row['field_length'] == 2)
|
|
||||||
{
|
|
||||||
$var = (isset($_REQUEST[$var_name])) ? 1 : 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_STRING:
|
|
||||||
case FIELD_TEXT:
|
|
||||||
$var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_INT:
|
|
||||||
if (isset($_REQUEST[$var_name]) && $this->request->variable($var_name, '') === '')
|
|
||||||
{
|
|
||||||
$var = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_DROPDOWN:
|
|
||||||
$var = request_var($var_name, (int) $profile_row['field_default_value']);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$var = request_var($var_name, $profile_row['field_default_value']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $var;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_bool implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,4 +61,22 @@ class type_bool implements type_interface
|
||||||
'field_default_value' => 0,
|
'field_default_value' => 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
|
||||||
|
// Checkbox
|
||||||
|
if ($profile_row['field_length'] == 2)
|
||||||
|
{
|
||||||
|
return ($this->request->is_set($var_name)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_date implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,4 +69,30 @@ class type_date implements type_interface
|
||||||
'field_default_value' => ' 0- 0- 0',
|
'field_default_value' => ' 0- 0- 0',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
|
||||||
|
if (!$this->request->is_set($var_name . '_day'))
|
||||||
|
{
|
||||||
|
if ($profile_row['field_default_value'] == 'now')
|
||||||
|
{
|
||||||
|
$now = getdate();
|
||||||
|
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
|
||||||
|
}
|
||||||
|
list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$day = $this->request->variable($var_name . '_day', 0);
|
||||||
|
$month = $this->request->variable($var_name . '_month', 0);
|
||||||
|
$year = $this->request->variable($var_name . '_year', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf('%2d-%2d-%4d', $day, $month, $year);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ class type_dropdown implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
|
public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
$this->profilefields = $profilefields;
|
$this->profilefields = $profilefields;
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,4 +65,13 @@ class type_dropdown implements type_interface
|
||||||
'field_default_value' => 0,
|
'field_default_value' => 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,9 @@ class type_int implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($user)
|
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,4 +49,20 @@ class type_int implements type_interface
|
||||||
'field_default_value' => 0,
|
'field_default_value' => 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
if ($this->request->is_set($var_name) && $this->request->variable($var_name, '') === '')
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,12 @@ interface type_interface
|
||||||
* @return array with values like default field size and more
|
* @return array with values like default field size and more
|
||||||
*/
|
*/
|
||||||
public function get_default_values();
|
public function get_default_values();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get profile field value on submit
|
||||||
|
*
|
||||||
|
* @param array $profile_row Array with data for this field
|
||||||
|
* @return mixed Submitted value of the profile field
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,9 @@ class type_string extends type_string_common implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($user)
|
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,4 +49,13 @@ class type_string extends type_string_common implements type_interface
|
||||||
'field_default_value' => '',
|
'field_default_value' => '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,9 @@ class type_text extends type_string_common implements type_interface
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($user)
|
public function __construct(\phpbb\request\request $request, \phpbb\user $user)
|
||||||
{
|
{
|
||||||
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,4 +49,13 @@ class type_text extends type_string_common implements type_interface
|
||||||
'field_default_value' => '',
|
'field_default_value' => '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_profile_field($profile_row)
|
||||||
|
{
|
||||||
|
$var_name = 'pf_' . $profile_row['field_ident'];
|
||||||
|
return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue