Search code examples
elgg

Discussion pagination in elgg 1.8 is not working properly


We have a website created using elgg, and we have discussion part of elgg where pagination is not working properly.

When listing all discussion list, pagination is working correctly, from latest to oldest

But pagination inside topic (one of the discussion) where replies are too many, and they separated by pagination (Previous, next), it is showing replies incorrectly:

In the first page we have: The first page

As you can see it is ordered from latest to oldest: 17 days ago and then comes 21 days ago.

But when you go next page: Page 2

It is ordered inside the page from latest to oldest, but the the pages should be swapped.

How can I fix it?

Thanks forward


Solution

  • I have found finally going through all pagination libraries, and annotation views.

    The problem is when listing replies for discussion on replies.php file which in /views/default/discussion there are two jquery functions on the bottom of the page that reverse the order.

    function reverse(arr){
        var newArr = [];
        for(var iter = arr.length -1; iter >= 0; iter--){
            newArr.push(arr[iter])
        }
    
        return newArr;
    }
    

    I have change the iter to start from 0 and go to arr.lenthg.

    But it is not all yet, in order to get the latest replies first, I have added to

    $options = array(
    'guid' => $vars['entity']->getGUID(),
    'annotation_name' => 'group_topic_post',
    

    );

    this line:

    'order_by'=> 'time_created desc'
    

    And then I got my replies ordered correctly: from latest to oldest.