Commit 7dbd2c0a by Scott

Paginate private messages

Add selectspec for counting messages
parent 6da9a5d4
......@@ -1355,21 +1355,26 @@
}
function qa_db_messages_inbox_selectspec($type, $toidentifier, $toisuserid, $count=null, $start=0)
function qa_db_messages_inbox_selectspec($type, $toidentifier, $toisuserid, $limit=null, $start=0)
/*
Get selectspec for messages *to* specified user.
$type is either 'public' or 'private'.
$toidentifier is a handle or userid depending on the value of $toisuserid.
Return $count (or default) messages.
Return $limit messages, or all of them if $limit is null (used for COUNT(*) query below).
*/
{
$type = strtoupper($type);
$count = isset($count) ? min($count, QA_DB_RETRIEVE_MESSAGES) : QA_DB_RETRIEVE_MESSAGES;
$where = 'touserid=' . ($toisuserid ? '$' : '(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)') . ' AND type=$';
$source = '^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE ' . $where . ' ORDER BY ^messages.created DESC LIMIT #,#';
$arguments = array($toidentifier, $type, $start, $count);
$source = '^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE ' . $where . ' ORDER BY ^messages.created DESC';
$arguments = array($toidentifier, $type);
if (isset($limit)) {
$limit = min($limit, QA_DB_RETRIEVE_MESSAGES);
$source .= ' LIMIT #,#';
$arguments[] = $start;
$arguments[] = $limit;
}
return array(
'columns' => qa_db_messages_columns(),
......@@ -1381,21 +1386,26 @@
}
function qa_db_messages_outbox_selectspec($type, $fromidentifier, $fromisuserid, $count=null, $start=0)
function qa_db_messages_outbox_selectspec($type, $fromidentifier, $fromisuserid, $limit=null, $start=0)
/*
Get selectspec for messages *from* specified user.
$type is either 'public' or 'private'.
$fromidentifier is a handle or userid depending on the value of $fromisuserid.
Return $count (or default) messages.
Return $limit messages, or all of them if $limit is null (used for COUNT(*) query below).
*/
{
$type = strtoupper($type);
$count = isset($count) ? min($count, QA_DB_RETRIEVE_MESSAGES) : QA_DB_RETRIEVE_MESSAGES;
$where = 'fromuserid=' . ($fromisuserid ? '$' : '(SELECT userid FROM ^users WHERE handle=$ LIMIT 1)') . ' AND type=$';
$source = '^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE ' . $where . ' ORDER BY ^messages.created DESC LIMIT #,#';
$arguments = array($fromidentifier, $type, $start, $count);
$source = '^messages LEFT JOIN ^users ufrom ON fromuserid=ufrom.userid LEFT JOIN ^users uto ON touserid=uto.userid WHERE ' . $where . ' ORDER BY ^messages.created DESC';
$arguments = array($fromidentifier, $type);
if (isset($limit)) {
$limit = min($limit, QA_DB_RETRIEVE_MESSAGES);
$source .= ' LIMIT #,#';
$arguments[] = $start;
$arguments[] = $limit;
}
return array(
'columns' => qa_db_messages_columns(),
......@@ -1407,6 +1417,19 @@
}
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)
/*
Return the selectspec to retrieve whether or not $userid has favorited entity $entitytype identifier by $identifier.
......
......@@ -61,11 +61,18 @@
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
// Find the user profile and questions and answers for this handle
// Find the messages for this user
$start = qa_get_start();
$pagesize = qa_opt('page_size_wall');
// get number of messages then actual messages for this page
$func = 'qa_db_messages_'.$showBox.'_selectspec';
$pmSpec = $func('private', $loginUserId, true);
$userMessages = qa_db_select_with_pending($pmSpec);
$pmSpecCount = qa_db_messages_count_selectspec( $func('private', $loginUserId, true) );
$pmSpec = $func('private', $loginUserId, true, $pagesize, $start);
list($numMessages, $userMessages) = qa_db_select_with_pending($pmSpecCount, $pmSpec);
$count = $numMessages['count'];
// Prepare content for theme
......@@ -99,6 +106,8 @@
$qa_content['message_list']['messages'][] = $msgFormat;
}
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
$qa_content['navigation']['sub'] = qa_messages_sub_navigation($showBox);
return $qa_content;
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