Skip to content

Commit

Permalink
Paginate special users page
Browse files Browse the repository at this point in the history
  • Loading branch information
pupi1985 committed Aug 1, 2022
1 parent 2cf739b commit ff9fc6d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
25 changes: 22 additions & 3 deletions qa-include/db/selects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,18 +1565,37 @@ function qa_db_newest_users_selectspec($start, $count = null)
/**
* Return the selectspec to get information about users at a certain privilege level or higher
* @param $level
* @param $start
* @param $count
* @return array
*/
function qa_db_users_from_level_selectspec($level)
function qa_db_users_from_level_selectspec($level, $start = 0, $count = null)
{
$count = isset($count) ? min($count, QA_DB_RETRIEVE_USERS) : QA_DB_RETRIEVE_USERS;

return array(
'columns' => array('^users.userid', 'handle', 'level'),
'source' => '^users WHERE level>=# ORDER BY level DESC',
'arguments' => array($level),
'source' => '^users WHERE level >= # ORDER BY level, handle DESC LIMIT #, #',
'arguments' => array($level, $start, $count),
'sortdesc' => 'level',
);
}

/**
* Return the selectspec to count the amount of users at a certain privilege level or higher
* @param $level
* @return array
*/
function qa_db_users_from_level_count_selectspec($level)
{
$selectSpec = array(
'source' => '^users WHERE level >= #',
'arguments' => array($level),
);

return qa_db_selectspec_count($selectSpec);
}


/**
* Return the selectspec to get information about users with the $flag bit set (unindexed query)
Expand Down
22 changes: 13 additions & 9 deletions qa-include/pages/users-special.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/format.php';


// Check we're not using single-sign on integration

if (QA_FINAL_EXTERNAL_USERS) {
Expand All @@ -38,11 +37,6 @@
}


// Get list of special users

$users = qa_db_select_with_pending(qa_db_users_from_level_selectspec(QA_USER_LEVEL_EXPERT));


// Check we have permission to view this page (moderator or above)

if (qa_user_permit_error('permit_view_special_users_page')) {
Expand All @@ -52,9 +46,17 @@
}


// Get userids and handles of retrieved users
// Get list of special users

$start = qa_get_start();
$specialUsersSpec = qa_db_users_from_level_selectspec(QA_USER_LEVEL_EXPERT, $start, qa_opt_if_loaded('page_size_users'));
$specialUsersSpecCount = qa_db_users_from_level_count_selectspec(QA_USER_LEVEL_EXPERT);

$usershtml = qa_userids_handles_html($users);
list($specialUsers, $specialUsersCount) = qa_db_select_with_pending($specialUsersSpec, $specialUsersSpecCount);

$count = $specialUsersCount['count'];
$pageSize = qa_opt('page_size_users');
$usershtml = qa_userids_handles_html($specialUsers);


// Prepare content for theme
Expand All @@ -70,14 +72,16 @@
'sort' => 'level',
);

foreach ($users as $user) {
foreach ($specialUsers as $user) {
$qa_content['ranking']['items'][] = array(
'label' => $usershtml[$user['userid']],
'score' => qa_html(qa_user_level_string($user['level'])),
'raw' => $user,
);
}

$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pageSize, $count, qa_opt('pages_prev_next'));

$qa_content['navigation']['sub'] = qa_users_sub_navigation();


Expand Down

0 comments on commit ff9fc6d

Please sign in to comment.