Skip to content

Commit 6e1717a

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() Conflicts: core/profile_api.php
1 parent eb803ed commit 6e1717a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
 

Diff for: ‎core/profile_api.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,25 @@ function profile_get_row_direct( $p_profile_id ) {
210210
/**
211211
* Return an array containing all rows for a given user
212212
* @param int $p_user_id
213+
* @param bool $p_all_users Include profiles for all users
213214
* @return array
214215
*/
215-
function profile_get_all_rows( $p_user_id ) {
216-
$c_user_id = db_prepare_int( $p_user_id );
217-
216+
function profile_get_all_rows( $p_user_id, $p_all_users = false ) {
218217
$t_user_profile_table = db_get_table( 'user_profile' );
219218

219+
$query_where = 'user_id = ' . db_param();
220+
$param[] = db_prepare_int( $p_user_id );
221+
222+
if( $p_all_users && ALL_USERS != $p_user_id ) {
223+
$query_where .= ' OR user_id = ' . db_param();
224+
$param[] = ALL_USERS;
225+
}
226+
220227
$query = "SELECT *
221228
FROM $t_user_profile_table
222-
WHERE user_id=" . db_param() . "
229+
WHERE $query_where
223230
ORDER BY platform, os, os_build";
224-
$result = db_query_bound( $query, Array( $c_user_id ) );
231+
$result = db_query_bound( $query, $param );
225232

226233
$t_rows = array();
227234
$t_row_count = db_num_rows( $result );
@@ -240,13 +247,7 @@ function profile_get_all_rows( $p_user_id ) {
240247
* @return array
241248
*/
242249
function profile_get_all_for_user( $p_user_id ) {
243-
if( ALL_USERS == $p_user_id ) {
244-
return profile_get_all_rows( ALL_USERS );
245-
} else {
246-
$t_profiles_array = array_merge( profile_get_all_rows( ALL_USERS ), profile_get_all_rows( $p_user_id ) );
247-
asort( $t_profiles_array );
248-
return $t_profiles_array;
249-
}
250+
return profile_get_all_rows( $p_user_id, $p_user_id != ALL_USERS );
250251
}
251252

252253
/**

0 commit comments

Comments
 (0)
Please sign in to comment.