Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7caa180

Browse files
committedFeb 28, 2012
Fix #11916: List of user profiles not sorted alphabetically
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()
1 parent ae8be02 commit 7caa180

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
 

‎core/profile_api.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function profile_create( $p_user_id, $p_platform, $p_os, $p_os_build, $p_descrip
6868
return db_insert_id( $t_user_profile_table );
6969
}
7070

71-
/**
71+
/**
7272
* Delete a profile for the user
7373
*
7474
* Note that although profile IDs are currently globally unique, the existing
@@ -190,18 +190,25 @@ function profile_get_row_direct( $p_profile_id ) {
190190
/**
191191
* Return an array containing all rows for a given user
192192
* @param int $p_user_id
193+
* @param bool $p_all_users Include profiles for all users
193194
* @return array
194195
*/
195-
function profile_get_all_rows( $p_user_id ) {
196-
$c_user_id = db_prepare_int( $p_user_id );
197-
196+
function profile_get_all_rows( $p_user_id, $p_all_users = false ) {
198197
$t_user_profile_table = db_get_table( 'mantis_user_profile_table' );
199198

199+
$query_where = 'user_id = ' . db_param();
200+
$param[] = db_prepare_int( $p_user_id );
201+
202+
if( $p_all_users && ALL_USERS != $p_user_id ) {
203+
$query_where .= ' OR user_id = ' . db_param();
204+
$param[] = ALL_USERS;
205+
}
206+
200207
$query = "SELECT *
201208
FROM $t_user_profile_table
202-
WHERE user_id=" . db_param() . "
209+
WHERE $query_where
203210
ORDER BY platform, os, os_build";
204-
$result = db_query_bound( $query, Array( $c_user_id ) );
211+
$result = db_query_bound( $query, $param );
205212

206213
$t_rows = array();
207214
$t_row_count = db_num_rows( $result );
@@ -220,13 +227,7 @@ function profile_get_all_rows( $p_user_id ) {
220227
* @return array
221228
*/
222229
function profile_get_all_for_user( $p_user_id ) {
223-
if( ALL_USERS == $p_user_id ) {
224-
return profile_get_all_rows( ALL_USERS );
225-
} else {
226-
$t_profiles_array = array_merge( profile_get_all_rows( ALL_USERS ), profile_get_all_rows( $p_user_id ) );
227-
asort( $t_profiles_array );
228-
return $t_profiles_array;
229-
}
230+
return profile_get_all_rows( $p_user_id, $p_user_id != ALL_USERS );
230231
}
231232

232233
/**

0 commit comments

Comments
 (0)
Please sign in to comment.