[ticket/12187] Split generate_profile_fields_template() into 2 methods

Removing the mode switch that wraps the content of the method

PHPBB3-12187
This commit is contained in:
Joas Schilling 2014-03-04 08:47:47 +01:00
parent a3627a9ff7
commit c650078904
4 changed files with 110 additions and 110 deletions

View file

@ -63,7 +63,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
{
$cp = $phpbb_container->get('profilefields.manager');
$profile_fields = $cp->generate_profile_fields_template('grab', $author_id);
$profile_fields = $cp->grab_profile_fields_data($author_id);
}
// Assign TO/BCC Addresses to template
@ -173,7 +173,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
if (isset($profile_fields[$author_id]))
{
$cp_row = $cp->generate_profile_fields_template('show', false, $profile_fields[$author_id]);
$cp_row = $cp->generate_profile_fields_template_data($profile_fields[$author_id]);
}
}

View file

@ -618,8 +618,8 @@ switch ($mode)
if ($config['load_cpf_viewprofile'])
{
$cp = $phpbb_container->get('profilefields.manager');
$profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
$profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
$profile_fields = $cp->grab_profile_fields_data($user_id);
$profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields[$user_id]) : array();
}
// If the user has m_approve permission or a_user permission, then list then display unapproved posts
@ -1560,7 +1560,7 @@ switch ($mode)
if ($config['load_cpf_memberlist'])
{
// Grab all profile fields from users in id cache for later use - similar to the poster cache
$profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
$profile_fields_cache = $cp->grab_profile_fields_data($user_list);
// Filter the fields we don't want to show
foreach ($profile_fields_cache as $user_id => $user_profile_fields)
@ -1592,7 +1592,7 @@ switch ($mode)
$cp_row = array();
if ($config['load_cpf_memberlist'])
{
$cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
$cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields_cache[$user_id]) : array();
}
$memberrow = array_merge(show_profile($row), array(

View file

@ -278,16 +278,16 @@ class manager
}
/**
* Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
* This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
* Grab the user specific profile fields data
*
* @param int|array $user_ids Single user id or an array of ids
* @return array Users profile fields data
*/
public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
public function grab_profile_fields_data($user_ids = 0)
{
if ($mode == 'grab')
if (!is_array($user_ids))
{
if (!is_array($user_id))
{
$user_id = array($user_id);
$user_ids = array($user_ids);
}
if (!sizeof($this->profile_cache))
@ -295,14 +295,14 @@ class manager
$this->build_cache();
}
if (!sizeof($user_id))
if (!sizeof($user_ids))
{
return array();
}
$sql = 'SELECT *
FROM ' . $this->fields_data_table . '
WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id));
WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_ids));
$result = $this->db->sql_query($sql);
$field_data = array();
@ -314,8 +314,6 @@ class manager
$user_fields = array();
$user_ids = $user_id;
// Go through the fields in correct order
foreach (array_keys($this->profile_cache) as $used_ident)
{
@ -337,7 +335,14 @@ class manager
return $user_fields;
}
else if ($mode == 'show')
/**
* Assign the user's profile fields data to the template
*
* @param array $profile_row Array with users profile field data
* @return array
*/
public function generate_profile_fields_template_data($profile_row)
{
// $profile_row == $user_fields[$row['user_id']];
$tpl_fields = array();
@ -393,11 +398,6 @@ class manager
return $tpl_fields;
}
else
{
trigger_error('Wrong mode for custom profile', E_USER_ERROR);
}
}
/**
* Build Array for user insertion into custom profile fields table

View file

@ -1248,7 +1248,7 @@ if ($config['load_cpf_viewtopic'])
$cp = $phpbb_container->get('profilefields.manager');
// Grab all profile fields from users in id cache for later use - similar to the poster cache
$profile_fields_tmp = $cp->generate_profile_fields_template('grab', $id_cache);
$profile_fields_tmp = $cp->grab_profile_fields_data($id_cache);
// filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs.
$profile_fields_cache = array();
@ -1558,7 +1558,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
//
if ($config['load_cpf_viewtopic'])
{
$cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
$cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template_data($profile_fields_cache[$poster_id]) : array();
}
$post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;