Skip to content

Commit

Permalink
Fix #11916: List of user profiles not sorted alphabetically
Browse files Browse the repository at this point in the history
A new, optional boolean parameter $p_all_users has been added to the
profile_get_all_rows() function, to indicate whether it should return
the list of profiles for the specified user only, or include also the
profiles for all users.

This allows simplification of profile_get_all_for_user()

Conflicts:

	core/profile_api.php
  • Loading branch information
dregad committed Feb 28, 2012
1 parent eb803ed commit 6e1717a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions core/profile_api.php
Expand Up @@ -210,18 +210,25 @@ function profile_get_row_direct( $p_profile_id ) {
/**
* Return an array containing all rows for a given user
* @param int $p_user_id
* @param bool $p_all_users Include profiles for all users
* @return array
*/
function profile_get_all_rows( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );

function profile_get_all_rows( $p_user_id, $p_all_users = false ) {
$t_user_profile_table = db_get_table( 'user_profile' );

$query_where = 'user_id = ' . db_param();
$param[] = db_prepare_int( $p_user_id );

if( $p_all_users && ALL_USERS != $p_user_id ) {
$query_where .= ' OR user_id = ' . db_param();
$param[] = ALL_USERS;
}

$query = "SELECT *
FROM $t_user_profile_table
WHERE user_id=" . db_param() . "
WHERE $query_where
ORDER BY platform, os, os_build";
$result = db_query_bound( $query, Array( $c_user_id ) );
$result = db_query_bound( $query, $param );

$t_rows = array();
$t_row_count = db_num_rows( $result );
Expand All @@ -240,13 +247,7 @@ function profile_get_all_rows( $p_user_id ) {
* @return array
*/
function profile_get_all_for_user( $p_user_id ) {
if( ALL_USERS == $p_user_id ) {
return profile_get_all_rows( ALL_USERS );
} else {
$t_profiles_array = array_merge( profile_get_all_rows( ALL_USERS ), profile_get_all_rows( $p_user_id ) );
asort( $t_profiles_array );
return $t_profiles_array;
}
return profile_get_all_rows( $p_user_id, $p_user_id != ALL_USERS );
}

/**
Expand Down

0 comments on commit 6e1717a

Please sign in to comment.