Howto sort topics?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
WHK102
Registered User
Posts: 15
Joined: Tue Nov 14, 2017 7:45 pm

Howto sort topics?

Post by WHK102 » Sat Nov 18, 2017 1:49 am

Howto make a special sort the list of topics into forum?

By example, need sort all topics by created time should be last response time.

I try using core.viewforum_get_topic_data:
core.viewforum_get_topic_data viewforum.php forum_data, forum_id, sort_days, sort_dir, sort_key, sql_array, topics_count 3.1.0-a1 Event to modify the SQL query before the topic data is retrieved
But howto use the parameters to make a specific sort, example only by created time of the main post and not the las response?

WHK102
Registered User
Posts: 15
Joined: Tue Nov 14, 2017 7:45 pm

Re: Howto sort topics?

Post by WHK102 » Sat Nov 18, 2017 2:02 am

Does not work my function:

Code: Select all

    public function order_posts()
    {
        global $forum_data;
        global $sql_approved;
        global $sql_ary;
        global $sql_limit;
        global $sql_limit_time;
        global $sql_sort_order;
        global $sql_start;
        global $sql_where;
        global $store_reverse;

        $sql_ary['ORDER_BY'] = 't.topic_type DESC, t.topic_time DESC, t.topic_last_post_time DESC, t.topic_last_post_id DESC';
        // [ORDER_BY] => t.topic_type DESC, t.topic_last_post_time DESC, t.topic_last_post_id DESC
    }
The event is:

Code: Select all

'core.viewforum_get_topic_ids_data' => 'order_posts'
What did I do wrong?

WHK102
Registered User
Posts: 15
Joined: Tue Nov 14, 2017 7:45 pm

Re: Howto sort topics?

Post by WHK102 » Sat Nov 18, 2017 3:17 am

I have changed my code to:

Code: Select all

public function order_posts($event)
{
    $event['sql_ary']['ORDER_BY'] = 't.topic_type DESC, t.topic_time DESC, t.topic_last_post_time DESC, t.topic_last_post_id DESC';
    // [ORDER_BY] => t.topic_type DESC, t.topic_last_post_time DESC, t.topic_last_post_id DESC
}
But does not work :(

User avatar
3Di
Registered User
Posts: 11864
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Howto sort topics?

Post by 3Di » Sat Nov 18, 2017 3:38 am

Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

WHK102
Registered User
Posts: 15
Joined: Tue Nov 14, 2017 7:45 pm

Re: Howto sort topics?

Post by WHK102 » Sat Nov 18, 2017 3:41 am

Thanks, i try clone variable using: https://github.com/kasimi/phpbb-ext-sor ... stener.php :

Code: Select all

$sql_ary = $event['sql_ary'];
		$sql_ary['ORDER_BY'] = 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
		$event['sql_sort_order'] = $sql_sort_order;
		$event['sql_ary'] = $sql_ary;
Realy need clone the array?, ORDER_BY is static and read only mode, works when clone $event and set all content again. Its a harcored solution, is a bug of phpbb3?

My code now works cloning the $evnt:

Code: Select all

$sql_ary = $event['sql_ary']; // phpbb3 bug?
        $mode = $event['store_reverse'] ? 'ASC' : 'DESC';
        $sql_ary['ORDER_BY'] = implode(', ', array(
            't.topic_type           '.$mode,
            't.topic_time           '.$mode,
            't.topic_last_post_time '.$mode,
            't.topic_last_post_id   '.$mode,
        ));
        $event['sql_ary'] = $sql_ary;

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: aleba89, eunaumtenhoid and 10 guests

cron