Forum post order preference

Added a user preference for the sort order of comments

(DBOINCP-28)
This commit is contained in:
Tristan Olive 2013-10-28 23:13:34 -04:00
parent 3b20262a16
commit 12202da894
2 changed files with 19 additions and 5 deletions

View File

@ -340,11 +340,17 @@ function boinccore_url_pagination_handler($type, $object_id) {
$object = _comment_load($object_id);
if ($object) {
$path = "node/{$object->nid}";
// See how many comments there are before this comment...
// Get the sort order
$gt_lt = '<';
$comment_order = (isset($user->sort)) ? $user->sort : variable_get('comment_default_order_forum', 2);
if ($comment_order == COMMENT_ORDER_NEWEST_FIRST) {
$gt_lt = '>';
}
// See how many comments there are before (or after) this comment...
$comment_offset = db_result(db_query('
SELECT COUNT(*) FROM {comments}
WHERE nid = %d AND status = 0 AND timestamp < %d',
$object->nid, $object->timestamp));
WHERE nid = %d AND status = 0 AND timestamp %s %d',
$object->nid, $gt_lt, $object->timestamp));
if ($comment_offset) {
// Get the number of comments per page
if ($user->comments_per_page) {

View File

@ -1055,7 +1055,8 @@ function communityprefs_form(&$form_state) {
$default = array(
'pm_send_notification' => '', // This is set already in pm_email_notify_user
'friend_notification' => isset($account->friend_notification) ? $account->friend_notification : 0,
'comments_per_page' => (isset($account->comments_per_page) AND $account->comments_per_page) ? $account->comments_per_page : variable_get('comment_default_per_page_forum', 50)
'comments_per_page' => (isset($account->comments_per_page) AND $account->comments_per_page) ? $account->comments_per_page : variable_get('comment_default_per_page_forum', 50),
'comments_order' => (isset($account->sort) AND $account->sort) ? $account->sort : variable_get('comment_default_order_forum', COMMENT_ORDER_OLDEST_FIRST),
);
// General options
@ -1134,6 +1135,12 @@ function communityprefs_form(&$form_state) {
// Can't have a typical Drupal form suffix on a select box?
$form['forums']['comments_per_page_suffix'] = array(
'#value' => '<span>' . t('comments per page') . '</span>'
);
$form['forums']['comments_order'] = array(
'#type' => 'select',
'#title' => t('Sort comments in discussions'),
'#options' => array(1 => t('Newest post first'), 2 => t('Oldest post first')),
'#default_value' => $default['comments_order']
);
// Signature (pulled from user_edit_form):
if (variable_get('user_signatures', 0) && module_exists('comment')) {
@ -1205,7 +1212,8 @@ function communityprefs_form_submit($form, &$form_state) {
'signature_format' => $edit['signature_format'],
'timezone' => $edit['timezone'],
'friend_notification' => $edit['friend_notification'],
'comments_per_page' => $edit['comments_per_page']
'comments_per_page' => $edit['comments_per_page'],
'sort' => $edit['comments_order'],
));
}