Commit 96acea7a by Scott

Add pagination to blocked users page

Also create generic qa_db_selectspec_count function for modifying a
selectspec with COUNT(*).
parent d13ddf71
...@@ -114,6 +114,20 @@ ...@@ -114,6 +114,20 @@
} }
function qa_db_selectspec_count($selectSpec)
/*
Modify a selectspec to count the number of items. This assumes the original selectspec does not have a LIMIT clause.
Currently works with message inbox/outbox functions and user-flags function.
*/
{
$selectSpec['columns'] = array('count' => 'COUNT(*)');
$selectSpec['single'] = true;
unset($selectSpec['arraykey']);
return $selectSpec;
}
function qa_db_posts_basic_selectspec($voteuserid=null, $full=false, $user=true) function qa_db_posts_basic_selectspec($voteuserid=null, $full=false, $user=true)
/* /*
Return the common selectspec used to build any selectspecs which retrieve posts from the database. Return the common selectspec used to build any selectspecs which retrieve posts from the database.
...@@ -1288,15 +1302,24 @@ ...@@ -1288,15 +1302,24 @@
} }
function qa_db_users_with_flag_selectspec($flag) function qa_db_users_with_flag_selectspec($flag, $start=0, $limit=null)
/* /*
Return the selectspec to get information about users with the $flag bit set (unindexed query) Return the selectspec to get information about users with the $flag bit set (unindexed query)
*/ */
{ {
$source = '^users WHERE (flags & #)';
$arguments = array($flag);
if (isset($limit)) {
$limit = min($limit, QA_DB_RETRIEVE_USERS);
$source .= ' LIMIT #,#';
array_push($arguments, $start, $limit);
}
return array( return array(
'columns' => array('^users.userid', 'handle', 'flags', 'level'), 'columns' => array('^users.userid', 'handle', 'flags', 'level'),
'source' => '^users WHERE (flags & #)', 'source' => $source,
'arguments' => array($flag), 'arguments' => $arguments,
); );
} }
...@@ -1355,12 +1378,11 @@ ...@@ -1355,12 +1378,11 @@
} }
function qa_db_messages_inbox_selectspec($type, $toidentifier, $toisuserid, $limit=null, $start=0) function qa_db_messages_inbox_selectspec($type, $toidentifier, $toisuserid, $start=0, $limit=null)
/* /*
Get selectspec for messages *to* specified user. Get selectspec for messages *to* specified user. $type is either 'public' or 'private'.
$type is either 'public' or 'private'.
$toidentifier is a handle or userid depending on the value of $toisuserid. $toidentifier is a handle or userid depending on the value of $toisuserid.
Return $limit messages, or all of them if $limit is null (used for COUNT(*) query below). Returns $limit messages, or all of them if $limit is null (used in qa_db_selectspec_count).
*/ */
{ {
$type = strtoupper($type); $type = strtoupper($type);
...@@ -1386,12 +1408,11 @@ ...@@ -1386,12 +1408,11 @@
} }
function qa_db_messages_outbox_selectspec($type, $fromidentifier, $fromisuserid, $limit=null, $start=0) function qa_db_messages_outbox_selectspec($type, $fromidentifier, $fromisuserid, $start=0, $limit=null)
/* /*
Get selectspec for messages *from* specified user. Get selectspec for messages *from* specified user. $type is either 'public' or 'private'.
$type is either 'public' or 'private'.
$fromidentifier is a handle or userid depending on the value of $fromisuserid. $fromidentifier is a handle or userid depending on the value of $fromisuserid.
Return $limit messages, or all of them if $limit is null (used for COUNT(*) query below). Returns $limit messages, or all of them if $limit is null (used in qa_db_selectspec_count).
*/ */
{ {
$type = strtoupper($type); $type = strtoupper($type);
...@@ -1417,19 +1438,6 @@ ...@@ -1417,19 +1438,6 @@
} }
function qa_db_messages_count_selectspec($selectSpec)
/*
Modify a messages selectspec to count messages.
*/
{
$selectSpec['columns'] = array('count' => 'COUNT(*)');
$selectSpec['single'] = true;
unset($selectSpec['arraykey']);
return $selectSpec;
}
function qa_db_is_favorite_selectspec($userid, $entitytype, $identifier) function qa_db_is_favorite_selectspec($userid, $entitytype, $identifier)
/* /*
Return the selectspec to retrieve whether or not $userid has favorited entity $entitytype identifier by $identifier. Return the selectspec to retrieve whether or not $userid has favorited entity $entitytype identifier by $identifier.
......
...@@ -68,8 +68,8 @@ ...@@ -68,8 +68,8 @@
// get number of messages then actual messages for this page // get number of messages then actual messages for this page
$func = 'qa_db_messages_'.$showBox.'_selectspec'; $func = 'qa_db_messages_'.$showBox.'_selectspec';
$pmSpecCount = qa_db_messages_count_selectspec( $func('private', $loginUserId, true) ); $pmSpecCount = qa_db_selectspec_count( $func('private', $loginUserId, true) );
$pmSpec = $func('private', $loginUserId, true, $pagesize, $start); $pmSpec = $func('private', $loginUserId, true, $start, $pagesize);
list($numMessages, $userMessages) = qa_db_select_with_pending($pmSpecCount, $pmSpec); list($numMessages, $userMessages) = qa_db_select_with_pending($pmSpecCount, $pmSpec);
$count = $numMessages['count']; $count = $numMessages['count'];
......
...@@ -42,7 +42,14 @@ ...@@ -42,7 +42,14 @@
// Get list of blocked users // Get list of blocked users
$users = qa_db_select_with_pending(qa_db_users_with_flag_selectspec(QA_USER_FLAGS_USER_BLOCKED)); $start = qa_get_start();
$pagesize = qa_opt('page_size_users');
$userSpecCount = qa_db_selectspec_count( qa_db_users_with_flag_selectspec(QA_USER_FLAGS_USER_BLOCKED) );
$userSpec = qa_db_users_with_flag_selectspec(QA_USER_FLAGS_USER_BLOCKED, $start, $pagesize);
list($numUsers, $users) = qa_db_select_with_pending($userSpecCount, $userSpec);
$count = $numUsers['count'];
// Check we have permission to view this page (moderator or above) // Check we have permission to view this page (moderator or above)
...@@ -63,7 +70,7 @@ ...@@ -63,7 +70,7 @@
$qa_content = qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['title'] = count($users) ? qa_lang_html('users/blocked_users') : qa_lang_html('users/no_blocked_users'); $qa_content['title'] = $count > 0 ? qa_lang_html('users/blocked_users') : qa_lang_html('users/no_blocked_users');
$qa_content['ranking'] = array( $qa_content['ranking'] = array(
'items' => array(), 'items' => array(),
...@@ -79,6 +86,8 @@ ...@@ -79,6 +86,8 @@
); );
} }
$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(); $qa_content['navigation']['sub'] = qa_users_sub_navigation();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment