News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

SMF 2.0.6 Function getBoardList not always returns boards with order

Started by davidhs, December 28, 2013, 06:49:54 PM

Previous topic - Next topic

davidhs

I programmed some MODs where I needed a select box with list of boards. I used getBoardList() function and works.
require_once ($sourcedir . '/Subs-MessageIndex.php');
$boardListOptions = array(
'not_redirection' => true,
);
$all_boards = getBoardList($boardListOptions);


Now I need a select box with not all boards, only a set of these, and I use this code
require_once ($sourcedir . '/Subs-MessageIndex.php');
$boardListOptions = array(
'not_redirection' => true,
'included_boards' => $boards; // Array of ID boards to add in select box.

);
$my_boards = getBoardList($boardListOptions);

This return my boards and I fill a select box but... boards are displayed without order!

Solution:

Version SMF: 2.0.6
File: Sources/Subs-MessageIndex.php
Function: getBoardList()
Line: 50
Code:
$request = $smcFunc['db_query']('messageindex_fetch_boards', '
SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
WHERE ' . implode('
AND ', $where)),
$where_parameters
);

Replace by
$request = $smcFunc['db_query']('messageindex_fetch_boards', '
SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
WHERE ' . implode('
AND ', $where)) . '
ORDER BY b.board_order ASC',
$where_parameters
);

Arantor

Yes, we know about this. Applies in a bunch of places, not just that one you've pointed out.

Unfortunately the solution you have provided makes all such queries *substantially slower* which is why we do not fix it that way. More details: https://github.com/SimpleMachines/SMF2.1/issues/887

davidhs

What if the ORDER BY is written only when it is needed?
$request = $smcFunc['db_query']('messageindex_fetch_boards', '
SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
WHERE ' . implode('
AND ', $where)) . (empty($boardListOptions['force_order']) ? '' : '
ORDER BY b.board_order ASC'),
$where_parameters
);

And we can use
require_once ($sourcedir . '/Subs-MessageIndex.php');
$boardListOptions = array(
'not_redirection' => true,
);
$all_boards = getBoardList($boardListOptions);

or
require_once ($sourcedir . '/Subs-MessageIndex.php');
$boardListOptions = array(
'not_redirection' => true,
'included_boards' => $boards; // Array of ID boards to add in select box.
'force_order' => true, // New parameter.
);
$my_boards = getBoardList($boardListOptions);

Arantor

It's needed everywhere the board list is pulled. Because if it's wrong, it's always wrong.

Advertisement: