mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 05:48:51 +00:00
[ticket/11201] Remove dependency from types on the manager
PHPBB3-11201
This commit is contained in:
parent
7bcbdfc1b1
commit
cacd43bfbd
6 changed files with 48 additions and 86 deletions
|
@ -1,20 +1,20 @@
|
|||
services:
|
||||
profilefields.manager:
|
||||
class: \phpbb\profilefields\manager
|
||||
class: phpbb\profilefields\manager
|
||||
arguments:
|
||||
- @auth
|
||||
- @dbal.conn
|
||||
- @request
|
||||
- @template
|
||||
- @profilefields.type_collection
|
||||
- @user
|
||||
- %tables.profile_fields%
|
||||
- %tables.profile_fields_language%
|
||||
- %tables.profile_fields_data%
|
||||
calls:
|
||||
- [set_type_collection, [@profilefields.type_collection]]
|
||||
|
||||
profilefields.lang_helper:
|
||||
class: \phpbb\profilefields\lang_helper
|
||||
class: phpbb\profilefields\lang_helper
|
||||
arguments:
|
||||
- @dbal.conn
|
||||
- %tables.profile_fields_options_language%
|
||||
|
@ -27,10 +27,9 @@ services:
|
|||
- { name: service_collection, tag: profilefield.type }
|
||||
|
||||
profilefields.type.bool:
|
||||
class: \phpbb\profilefields\type\type_bool
|
||||
class: phpbb\profilefields\type\type_bool
|
||||
arguments:
|
||||
- @profilefields.lang_helper
|
||||
- @profilefields.manager
|
||||
- @request
|
||||
- @template
|
||||
- @user
|
||||
|
@ -38,9 +37,8 @@ services:
|
|||
- { name: profilefield.type }
|
||||
|
||||
profilefields.type.date:
|
||||
class: \phpbb\profilefields\type\type_date
|
||||
class: phpbb\profilefields\type\type_date
|
||||
arguments:
|
||||
- @profilefields.manager
|
||||
- @request
|
||||
- @template
|
||||
- @user
|
||||
|
@ -48,10 +46,9 @@ services:
|
|||
- { name: profilefield.type }
|
||||
|
||||
profilefields.type.dropdown:
|
||||
class: \phpbb\profilefields\type\type_dropdown
|
||||
class: phpbb\profilefields\type\type_dropdown
|
||||
arguments:
|
||||
- @profilefields.lang_helper
|
||||
- @profilefields.manager
|
||||
- @request
|
||||
- @template
|
||||
- @user
|
||||
|
@ -59,7 +56,7 @@ services:
|
|||
- { name: profilefield.type }
|
||||
|
||||
profilefields.type.int:
|
||||
class: \phpbb\profilefields\type\type_int
|
||||
class: phpbb\profilefields\type\type_int
|
||||
arguments:
|
||||
- @request
|
||||
- @template
|
||||
|
@ -68,7 +65,7 @@ services:
|
|||
- { name: profilefield.type }
|
||||
|
||||
profilefields.type.string:
|
||||
class: \phpbb\profilefields\type\type_string
|
||||
class: phpbb\profilefields\type\type_string
|
||||
arguments:
|
||||
- @request
|
||||
- @template
|
||||
|
@ -77,7 +74,7 @@ services:
|
|||
- { name: profilefield.type }
|
||||
|
||||
profilefields.type.text:
|
||||
class: \phpbb\profilefields\type\type_text
|
||||
class: phpbb\profilefields\type\type_text
|
||||
arguments:
|
||||
- @request
|
||||
- @template
|
||||
|
|
|
@ -39,6 +39,12 @@ class manager
|
|||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Service Collection object
|
||||
* @var \phpbb\di\service_collection
|
||||
*/
|
||||
protected $type_collection;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var \phpbb\user
|
||||
|
@ -60,17 +66,19 @@ class manager
|
|||
* @param \phpbb\db\driver\driver $db Database object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\di\service_collection $type_collection
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $fields_table
|
||||
* @param string $fields_language_table
|
||||
* @param string $fields_data_table
|
||||
*/
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->db = $db;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->type_collection = $type_collection;
|
||||
$this->user = $user;
|
||||
|
||||
$this->fields_table = $fields_table;
|
||||
|
@ -78,20 +86,6 @@ class manager
|
|||
$this->fields_data_table = $fields_data_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the type collection
|
||||
*
|
||||
* We need to set the type collection later,
|
||||
* in order to avoid a circular dependency
|
||||
*
|
||||
* @param \phpbb\di\service_collection $type_collection
|
||||
* @return null
|
||||
*/
|
||||
public function set_type_collection(\phpbb\di\service_collection $type_collection)
|
||||
{
|
||||
$this->type_collection = $type_collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
|
||||
* Called by ucp_profile and ucp_register
|
||||
|
@ -131,8 +125,8 @@ class manager
|
|||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
// Return templated field
|
||||
$tpl_snippet = $this->process_field_row('change', $row);
|
||||
$profile_field = $this->type_collection[$row['field_type']];
|
||||
$tpl_snippet = $profile_field->process_field_row('change', $row);
|
||||
|
||||
$this->template->assign_block_vars('profile_fields', array(
|
||||
'LANG_NAME' => $this->user->lang($row['lang_name']),
|
||||
|
@ -351,33 +345,6 @@ class manager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Templated value/field. Possible values for $mode are:
|
||||
* change == user is able to set/enter profile values; preview == just show the value
|
||||
*/
|
||||
public function process_field_row($mode, $profile_row)
|
||||
{
|
||||
$preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false;
|
||||
|
||||
// set template filename
|
||||
$this->template->set_filenames(array(
|
||||
'cp_body' => 'custom_profile_fields.html',
|
||||
));
|
||||
|
||||
// empty previously filled blockvars
|
||||
foreach ($this->type_collection as $field_key => $field_type)
|
||||
{
|
||||
$this->template->destroy_block_vars($field_type->get_name_short());
|
||||
}
|
||||
|
||||
// Assign template variables
|
||||
$profile_field = $this->type_collection[$profile_row['field_type']];
|
||||
$profile_field->generate_field($profile_row, $preview_options);
|
||||
|
||||
// Return templated data
|
||||
return $this->template->assign_display('cp_body');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Array for user insertion into custom profile fields table
|
||||
*/
|
||||
|
|
|
@ -142,4 +142,26 @@ abstract class type_base implements type_interface
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return templated value/field. Possible values for $mode are:
|
||||
* change == user is able to set/enter profile values; preview == just show the value
|
||||
*/
|
||||
public function process_field_row($mode, $profile_row)
|
||||
{
|
||||
$preview_options = ($mode == 'preview') ? $profile_row['lang_options'] : false;
|
||||
|
||||
// set template filename
|
||||
$this->template->set_filenames(array(
|
||||
'cp_' . $this->get_name_short() . '_body' => 'custom_profile_fields.html',
|
||||
));
|
||||
|
||||
// empty previously filled blockvars
|
||||
$this->template->destroy_block_vars($this->get_name_short());
|
||||
|
||||
// Assign template variables
|
||||
$this->generate_field($profile_row, $preview_options);
|
||||
|
||||
return $this->template->assign_display('cp_' . $this->get_name_short() . '_body');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,6 @@ class type_bool extends type_base
|
|||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* Profile fields object
|
||||
* @var \phpbb\profilefields\manager
|
||||
*/
|
||||
protected $profilefields;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
|
@ -45,16 +39,14 @@ class type_bool extends type_base
|
|||
* Construct
|
||||
*
|
||||
* @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper
|
||||
* @param \phpbb\profilefields\manager $manager Profile fields object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $language_table Table where the language strings are stored
|
||||
*/
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->manager = $manager;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
|
@ -88,7 +80,7 @@ class type_bool extends type_base
|
|||
|
||||
$options = array(
|
||||
0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($field_data['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($field_data['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['CHECKBOX'] . '</label>'),
|
||||
1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row)),
|
||||
1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
|
||||
);
|
||||
|
||||
return $options;
|
||||
|
|
|
@ -11,12 +11,6 @@ namespace phpbb\profilefields\type;
|
|||
|
||||
class type_date extends type_base
|
||||
{
|
||||
/**
|
||||
* Profile fields object
|
||||
* @var \phpbb\profilefields\manager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
|
@ -38,15 +32,13 @@ class type_date extends type_base
|
|||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param \phpbb\profilefields\manager $manager Profile fields object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $language_table Table where the language strings are stored
|
||||
*/
|
||||
public function __construct(\phpbb\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
|
@ -87,7 +79,7 @@ class type_date extends type_base
|
|||
}
|
||||
|
||||
$options = array(
|
||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row)),
|
||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
|
||||
1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['NO'] . '</label>'),
|
||||
);
|
||||
|
||||
|
|
|
@ -17,12 +17,6 @@ class type_dropdown extends type_base
|
|||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* Profile fields object
|
||||
* @var \phpbb\profilefields\manager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var \phpbb\request\request
|
||||
|
@ -45,16 +39,14 @@ class type_dropdown extends type_base
|
|||
* Construct
|
||||
*
|
||||
* @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper
|
||||
* @param \phpbb\profilefields\manager $manager Profile fields object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $language_table Table where the language strings are stored
|
||||
*/
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
|
||||
{
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->manager = $manager;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
|
@ -91,8 +83,8 @@ class type_dropdown extends type_base
|
|||
$profile_row[1]['field_default_value'] = $field_data['field_novalue'];
|
||||
|
||||
$options = array(
|
||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row[0])),
|
||||
1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row[1])),
|
||||
0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
|
||||
1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])),
|
||||
);
|
||||
|
||||
return $options;
|
||||
|
|
Loading…
Add table
Reference in a new issue